上一步的存档被复制并解压
...
在同一台(测试)机器上构建 openssl 和 curl 是可行的。
听起来构建机器上的 OpenSSL 启用了 Next Protocol Negotiation,但目标机器的 OpenSSL 是在构建时没有 Next Protocol Negotiation。对于 OpenSSL 1.1.0,我相信这意味着构建机器配置了no-nextprotoneg。对于 OpenSSL 1.0.2 及以下版本,我相信这意味着它配置了no-npn。
SSL_CTX_set_alpn_protos 是 OpenSSL 1.1.0 的一部分。 .pod 很重要,因为它意味着它已记录在案,因此它是一个旨在由用户程序调用的公共函数(这是 1.1.0 的策略更改):
$ cd openssl-master
$ grep -IR SSL_CTX_set_alpn_protos * | egrep '(ssl.h|.pod)'
doc/ssl/SSL_CTX_set_alpn_select_cb.pod:SSL_CTX_set_alpn_protos, SSL_set_alpn_protos, SSL_CTX_set_alpn_select_cb,
doc/ssl/SSL_CTX_set_alpn_select_cb.pod: int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
doc/ssl/SSL_CTX_set_alpn_select_cb.pod:SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() are used by the client to
doc/ssl/SSL_CTX_set_alpn_select_cb.pod:SSL_CTX_set_alpn_protos() and SSL_set_alpn_protos() return 0 on success, and
include/openssl/ssl.h:__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
它在 1.0.2 中也可用:
$ cd openssl-1.0.2g
$ grep -IR SSL_CTX_set_alpn_protos *
apps/s_client.c: SSL_CTX_set_alpn_protos(ctx, alpn, alpn_len);
ssl/ssl.h:int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
ssl/ssl_lib.c: * SSL_CTX_set_alpn_protos sets the ALPN protocol list on |ctx| to |protos|.
ssl/ssl_lib.c:int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
ssl/ssltest.c: SSL_CTX_set_alpn_protos(c_ctx, alpn, alpn_len);
util/ssleay.num:SSL_CTX_set_alpn_protos 387 EXIST::FUNCTION:
我的猜测是 cURL 使用的是底层发行版提供的缺乏协议协商的 OpenSSL(如 OpenSSL 0.9.8):
export LIBS='-ldl'
./configure --prefix="$(pwd)/<install_dir>" --with-ssl="<unpacked-tar>"
make && make install
检查 config.log 以查看 cURL 在配置期间发现了什么。
您可以通过以下方式禁用 OpenSSL 中的协议协商:
- OpenSSL 1.0.2 -
no-npn
- OpenSSL 1.1.0 -
no-nextprotoneg
它将显示在<openssl/opensslconf.h:
$ cd openssl-master
$ ./config no-nextprotoneg
...
$ find $PWD -name 'opensslconf.h'
.../include/openssl/opensslconf.h
$ cat .../include/openssl/opensslconf.h | grep PROT
#ifndef OPENSSL_NO_NEXTPROTONEG
# define OPENSSL_NO_NEXTPROTONEG
还有:
$ cd openssl-1.0.2g
$ ./config no-npn
...
$ cat include/openssl/opensslconf.h | grep NPN
#ifndef OPENSSL_NO_NPN
# define OPENSSL_NO_NPN
# if defined(OPENSSL_NO_NPN) && !defined(NO_NPN)
# define NO_NPN
因此,您还应该验证它在构建时没有被禁用。
看起来 cURL 对 no-npn 和 no-nextprotoneg 并不完全同情:
$ git clone https://github.com/curl/curl.git
$ cd curl/
$ egrep -IR '(OPENSSL_NO_NPN|OPENSSL_NO_NEXTPROTONEG)' *
lib/vtls/openssl.c: && !defined(OPENSSL_NO_NEXTPROTONEG)
这也是 SSL_CTX_set_alpn_protos 的唯一命中:
$ grep -IR SSL_CTX_set_alpn_protos *
lib/vtls/openssl.c: SSL_CTX_set_alpn_protos(connssl->ctx, protocols, cur)