• 嵌入式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 ^^^^^^^^^^^
  • 相关阅读:
    AS3.0纯代码编写的两款loading效果
    AS3.0 Vector的运用
    java 垃圾回收总结(1)
    as3垃圾回收机制
    AS3.0 效率优化
    数组去重的方法
    javascript 的垃圾回收机制讲一下
    浅拷贝和深拷贝
    判断 js 类型的方式
    前端安全问题?
  • 原文地址:https://www.cnblogs.com/qinwanlin/p/5091701.html
Copyright © 2020-2023  润新知