【问题标题】:Building curl from sources - undefined reference to SSL_CTX_set_alpn_protos从源构建 curl - 对 SSL_CTX_set_alpn_protos 的未定义引用
【发布时间】:2016-04-04 13:43:59
【问题描述】:

我对这些工具不是很有经验,所以请多多包涵。我想从源代码中使用 SSL 构建curl。为此,我还从源代码编译OpenSSL

在构建和安装OpenSSL 之后,会创建一个归档文件。这个 tar 然后被解压,在构建 curl 时应该使用。

我的做法是:

OpenSSL

./config shared -fPIC --prefix="/some/path/install_dir"
make depend
make && make install

rm -rf /some/path/install_dir/lib/pkgconfig
# create tar from $prefix/bin $prefix/include $prefix/lib

pkgconfig 被删除了,因为当我把它放在那里时,它包含了 openssl 构建机器上库的绝对路径,这可能与 curl 构建机器不同,我只想使用存档中的那些. 我不知道这是否正确。

卷曲

上一步的存档被复制并解压。那么

export LIBS='-ldl'
./configure --prefix="$(pwd)/<install_dir>" --with-ssl="<unpacked-tar>"
make && make install

但是,make 会导致:

../lib/.libs/libcurl.so: undefined reference to `SSL_CTX_set_alpn_protos'
../lib/.libs/libcurl.so: undefined reference to `SSL_get0_alpn_selected'

在同一台(测试)机器上构建 openssl 和 curl 是可行的。

使用openssl-1.0.2gcurl-7.47.1。知道有什么问题吗?


curl 的 config.log 包含如下编译命令:

gcc -o conftest -O2 -Wno-system-headers  -I/home/teamcity/buildAgent/work/10199cb4c61825f3/openssl-1.0.2g/include -I/home/teamcity/buildAgent/work/10199cb4c61825f3/openssl-1.0.2g/include/openssl  -L/home/teamcity/buildAgent/work/10199cb4c61825f3/openssl-1.0.2g/lib conftest.c -lcrypto  -lz -lrt -ldl >&5

-I 文件夹是我想要包含的文件夹,所以我认为不应该使用系统范围的库。

搜索NPNPROT 没有结果,所以协商没有被禁用。

【问题讨论】:

    标签: curl build openssl


    【解决方案1】:

    上一步的存档被复制并解压 ... 在同一台(测试)机器上构建 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

    它将显示在&lt;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-npnno-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)
    

    【讨论】:

    • 编辑了问题。从 config.log 来看,一切都符合预期。协议协商似乎没有被禁用
    猜你喜欢
    • 1970-01-01
    • 2021-04-28
    • 2018-09-02
    • 2017-05-09
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    相关资源
    最近更新 更多