以前已經介紹過如何把goahead移植到linux平臺,如今再介紹goahead應用SSL的一些關鍵要點。由於此博文是繼承於上一篇關於移植的博文,有不明白的請先回看。移植篇點這裏。html
goahead-3.4.9linux
arm + linux 2.6,交叉編譯器arm-uclibc-gccc++
一、把me.h中和SSL相關的兩個宏置爲1。web
#define ME_COM_OPENSSL 1 #define ME_COM_SSL 1
二、把原來刪除掉的goahead-openssl/openssl.c再恢復回來。瀏覽器
三、修改makefile,把依賴的源文件加上,以下。服務器
SOURCE_FILE = *.c goahead-openssl/openssl.c
四、此時編譯可能會有問題,應該都是與openssl相關的,未聲明或未定義之類的。是由於openssl版本低的問題。在個人編譯環境中查看openssl版本,以下:post
[root]$ openssl version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
所以我決定本身下載openssl,本身編譯成靜態庫,讓goahead直接使用我編譯的openssl庫。我下載的openssl版本是openssl-1.0.0q,已經移植成功,編譯以後的有用的內容包括lib/libssl.a、include、bin/openssl、ssl/openssl.cnf。關於openssl的移植請點這裏。ui
五、再修改makefile文件,使用咱們本身編譯的openssl。this
CC=arm-uclibc-gcc #CC=gcc #-Werror FLAGS = -Wall -fPIC -g -O2 -s -ldl -lm -o LIB = -lstdc++ \ -lssl SSL_ARM_INCLUDE = ./openssl/arm/ssl/include SSL_ARM_LIB = ./openssl/arm/ssl/lib OBJ_ARM = libhttpspost_arm.so SSL_X86_INCLUDE = ./openssl/x86/ssl/include SSL_X86_LIB = ./openssl/x86/ssl/lib OBJ_X86 = libhttpspost_x86.so ifeq ($(CC),gcc) SSL_INCLUDE = $(SSL_X86_INCLUDE) SSL_LIB = $(SSL_X86_LIB) OBJ = $(OBJ_X86) else SSL_INCLUDE = $(SSL_ARM_INCLUDE) SSL_LIB = $(SSL_ARM_LIB) OBJ = $(OBJ_ARM) endif SOURCE_FILE = *.c goahead-openssl/openssl.c goahead: $(SOURCE_FILE) $(CC) $(FLAGS) $@ $(SOURCE_FILE) -I$(SSL_INCLUDE) $(SSL_LIB)/libssl.a $(SSL_LIB)/libcrypto.a clean: rm -rf goahead .PHONY: clean
六、從新編譯goahead,應該能編譯得過,可能會有一些warning。spa
七、使用編譯出來的openssl生成私鑰。
#生成私鑰前先設置環境變量,不然會提示【WARNING: can't open config file: /usr/local/ssl/openssl.cnf】
export OPENSSL_CONF=../ssl/openssl.cnf
#key名要符合me.h中的定義 #define ME_GOAHEAD_SSL_KEY "self.key"
openssl genrsa -out self.key 1024
八、使用編譯出來的openssl生成證書。
#讀書名要符合me.h中的定義 #define ME_GOAHEAD_SSL_CERTIFICATE "self.crt"
openssl req -new -x509 -key self.key -out self.crt -days 1095
九、佈署。把goahead、self.key、self.crt佈署到板上,他們三個是在同一個目錄下。
十、執行,此時執行goahead會有一些問題,提示
goahead: 0: Unable to set cipher list ......
此時最直接了當的解決辦法是把openss.h中的相關一段代碼註釋掉便可。
/* Configure cipher suite */ /* if (ME_GOAHEAD_SSL_CIPHERS && *ME_GOAHEAD_SSL_CIPHERS) { ciphers = ME_GOAHEAD_SSL_CIPHERS; } else { ciphers = OPENSSL_DEFAULT_CIPHERS; } ciphers = mapCipherNames(ciphers); trace(5, "Using OpenSSL ciphers: %s", ciphers); if (SSL_CTX_set_cipher_list(sslctx, ciphers) != 1) { error("Unable to set cipher list \"%s\"", ciphers); sslClose(); wfree(ciphers); return -1; } */
十一、註釋後編譯再執行,服務器的log會提示已經監聽ssl服務的端口443,在瀏覽器中輸入https://ip便可訪問。
[/mnt/goahead]./goahead goahead: 1: This system does not have IPv6 support goahead: 4: Upload directory is /tmp goahead: 2: Configuration for Embedthis GoAhead goahead: 2: --------------------------------------------- goahead: 2: Version: 3.4.9 goahead: 2: BuildType: Debug goahead: 2: CPU: arm goahead: 2: OS: linux goahead: 2: Host: 0.0.0.0 goahead: 2: Directory: /mnt/goahead goahead: 2: Documents: web goahead: 2: Configure: me -d -q -platform linux-x86-default -configure . -with openssl -gen make goahead: 2: --------------------------------------------- goahead: 2: Started http://*:80 goahead: 2: Started https://*:443 goahead: 2: ^^^^^^^^^^^ web start successful ^^^^^^^^^^^