嵌入式web server——Goahead啟用SSL


前言

之前已經介紹過如何把goahead移植到linux平台,現在再介紹goahead應用SSL的一些關鍵要點。因為此博文是繼承於上一篇關於移植的博文,有不明白的請先回看。移植篇點這里

 

移植環境

goahead-3.4.9

arm + linux 2.6,交叉編譯器arm-uclibc-gcc

 

移植要點

1、把me.h中和SSL相關的兩個宏置為1。

#define ME_COM_OPENSSL 1
#define ME_COM_SSL 1

 

2、把原來刪除掉的goahead-openssl/openssl.c再恢復回來。

 

3、修改makefile,把依賴的源文件加上,如下。

SOURCE_FILE = *.c goahead-openssl/openssl.c

 

4、此時編譯可能會有問題,應該都是與openssl相關的,未聲明或未定義之類的。是因為openssl版本低的問題。在我的編譯環境中查看openssl版本,如下:

[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的移植請點這里

 

5、再修改makefile文件,使用我們自己編譯的openssl。

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

 

6、重新編譯goahead,應該能編譯得過,可能會有一些warning。

 

7、使用編譯出來的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

 

8、使用編譯出來的openssl生成證書。

#讀書名要符合me.h中的定義 #define ME_GOAHEAD_SSL_CERTIFICATE "self.crt"
openssl req -new -x509 -key self.key -out self.crt -days 1095

 

9、布署。把goahead、self.key、self.crt布署到板上,他們三個是在同一個目錄下。

 

10、執行,此時執行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;
    }
*/

 

11、注釋后編譯再執行,服務器的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 ^^^^^^^^^^^

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM