tl;dr: 用上 LibreSSL 已经第二个夜晚了 ... 依然运行良好 7月11日,LibreSSL团队发布 LibreSSL 的可移植版本,这是第一个可在 OpenBSD, Linux, OSX, Solaris 和 FreeBSD 上运行的版本。 [1,2,5,8] 本文会介绍一些 Nginx 与 Libressl 一起使用实践经验。 
 
 本文所用软件的版本nginx 1.6.0 libressl 2.0.0 
 在reddit-discussion [11]中有描述一些使用最新开发版本(1.7 分支)会出现的问题。 安装直接从源码编译LibreSSL,构建过程的输出非常简洁,源码还附带测试用例及提供并行构建支持(见附录)。 1 2 3  |   $ ./configure --prefix=/usr LDFLAGS=-lrt && make check && sudo make install
  |  
 新安装的 LibreSSL 可替代openssl以相同的方式运行,但要注意:正如 sabotage-linux 的 spencerjohn 和 Gentoo 的 Hanno Böck 所说的那样,用libressl完全替代操作系统中的openssl会很麻烦。[3,4] 
 LibreSSL 会报告其版本为 LibreSSL 2.0, openssl命令的使用方法与openssl一样: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  | $ which openssl
 /usr/bin/openssl
   $ openssl version
 LibreSSL 2.0
   $ openssl s_client -host www.openssl.org -port 443
 CONNECTED(00000003)
 depth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
 verify error:num=19:self signed certificate in certificate chain
 verify return:0
 ---
 Certificate chain
  0 s:/C=GB/OU=Domain Control Validated/CN=*.openssl.org
    i:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2
  1 s:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA
    i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA
  2 s:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2
    i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA
 ---
 Server certificate
 -----BEGIN CERTIFICATE-----
 ... skip
 -----END CERTIFICATE-----
 subject=/C=GB/OU=Domain Control Validated/CN=*.openssl.org
 issuer=/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA - G2
 ---
 No client certificate CA names sent
 ---
 SSL handshake has read 4136 bytes and written 707 bytes
 ---
 New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
 Server public key is 2048 bit
 Secure Renegotiation IS supported
 Compression: NONE
 Expansion: NONE
 SSL-Session:
     Protocol  : TLSv1.2
     Cipher    : DHE-RSA-AES256-GCM-SHA384
     TLS session ticket lifetime hint: 300 (seconds)
     TLS session ticket:
  |  
 确认了 libressl 能够使用后,我便动手让 nginx 来使用 libressl 。尽管在仍然使用 openssl 0.9.x 的旧系统中,通常我都会静态构建 nginx+openssl 以使最新和最好的 tls 版本可用。第一次尝试,只使用 ./configure --with-openssl=/path/to/libressl 就大错特错了,因为 nginx 已经完全与 openssl 的构建过程融合了:  尝试通过手工建立目录层次(.openssl/lib)及根据 libressl 成功构建后出现的错误提示(见下面的错误信息)来复制文件以解决这些问题;在编译 libressl 时,我看到一个类似可以通过使用 LDFLAGS=-lrt 选项来解决问题的错误提示,但在尝试编译nginx并链接到已静态编译过的libressl库时仍然无法修复这个问题(但我依然继续): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  |   ...
     objs/addon/nginx-upstream-fair/ngx_http_upstream_fair_module.o \
   objs/addon/src/ngx_http_headers_more_filter_module.o \
   objs/addon/src/ngx_http_headers_more_headers_out.o \
   objs/addon/src/ngx_http_headers_more_headers_in.o \
   objs/addon/src/ngx_http_headers_more_util.o \
   objs/addon/src/ngx_http_encrypted_session_module.o \
   objs/addon/src/ngx_http_encrypted_session_cipher.o \
   objs/ngx_modules.o \
   -Wl,-E -lpthread -lcrypt -L/usr/lib -lm -llua5.1 -lpcre /data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libssl.a /data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libcrypto.a -ldl -lz
 /data/builds/froggstack/nginx_modules/openssl/.openssl/lib/libcrypto.a(libcompat_la-getentropy_linux.o): In function `getentropy_fallback':
 /data/builds/froggstack/nginx_modules/openssl/crypto/compat/getentropy_linux.c:324: undefined reference to `clock_gettime'
 /data/builds/froggstack/nginx_modules/openssl/crypto/compat/getentropy_linux.c:395: undefined reference to `clock_gettime'
 collect2: error: ld returned 1 exit status
 make[1]: *** [objs/nginx] Error 1
 make[1]: Leaving directory `/data/builds/froggstack/src_nginx/nginx-1.6.0'
 make: *** [build] Error 2
  |  
 下一个尝试是在安装了 libressl 的前提下通过链接到 libressl 的动态库来构建 nginx,最终成功了(完整的nginx ./configure 选项参数见附录)。 运行 nginx-libressl -t 测试成功,并将 /usr/bin/nginx 替换成新的二进制可执行文件和运行 /etc/init.d/nginx restart,更新后的 nginx + libressl 上线了。任何配置文件和 nginx 的 ssl 配置都不需要修改,非常好! 
 
 测试感兴趣并想测试的朋友可以访问: www.mare-system.de,网站从2014-07-12开始运行在 libressl 上。如你发现任何不兼容的问题,请通过 atsecurity@mare-system.de 给我留言。 在各种 Linux 和 Android 的浏览器上测试都没有发现问题;甚至在一台已被遗忘的装有2007年10月发布并已过时的附带 OpenSSL 0.9.8g 19 的 debian 5 上使用像 w3m 这样的控制台浏览器上浏览也没有问题。 在 ssllabs.com 上测试的得分为 A+,成绩与之前的配置一样;在使用了 libressl 后,唯一给出的提示是加密算法 ChaCha20-Poly1305 还处于实验阶段。  
  
 
  |