【问题标题】:Building Python and OpenSSL from source, but ssl module fails从源代码构建 Python 和 OpenSSL,但 ssl 模块失败
【发布时间】:2020-03-05 00:09:40
【问题描述】:

我正在尝试从容器中的源代码构建 Python 和 OpenSSL。两者似乎都正确构建,但 Python 没有成功创建 _ssl 模块。

我在网上找到了一个 few guides 表示取消注释和来自 Python-3.X.X/Modules/Setup 的行,并将 --openssldir=/usr/local/ssl 标志添加到 OpenSSL 的 ./configure 步骤。我在我的 dockerfile 中执行这些操作。这导致在 Python 的 ./configure 输出期间,我看到以下行。

checking for X509_VERIFY_PARAM_set1_host in libssl... yes

但我收到以下错误:

[91m*** WARNING: renaming "_ssl" since importing it failed: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by build/lib.linux-x86_64-3.8/_ssl.cpython-38-x86_64-linux-gnu.so)
[0m[91m*** WARNING: renaming "_hashlib" since importing it failed: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by build/lib.linux-x86_64-3.8/_hashlib.cpython-38-x86_64-linux-gnu.so)
[0m
Python build finished successfully!

...

Following modules built successfully but were removed because they could not be imported:
_hashlib              _ssl                                     


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

如果 ./configure 找到 X509...,为什么我仍然收到 hashlib 和 ssl 错误?

完整的 Dockerfile,FWIW:

FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y apt-utils gcc make zlib1g-dev \
    build-essential libffi-dev checkinstall libsqlite3-dev 
RUN wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz && \
    tar xzf openssl-1.1.1d.tar.gz && \
    cd openssl-1.1.1d && \
    ./config -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)' --prefix=/usr/local/ssl --openssldir=/usr/local/ssl && \
    make && \
    make test && \
    make install
RUN wget -q https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz && \
    tar -xzf Python-3.8.2.tgz && \
    cd Python-3.8.2 && \
    ./configure && \
    make && \
    make install
USER jenkins

【问题讨论】:

  • 嗨,Jake,你为什么不能在Python/Modules/Setup 中添加那行?你可以做一个sed 对文件进行适当的更改。
  • 正在尝试...sed -i 's|# -DUSE_SSL| -DUSE_SSL| w /dev/stdout' Python-3.8.2/Modules/Setup。在我的机器上它可以工作,在 dockerfile 上它没有。
  • 甚至让它在 Dockerfile 上运行也会给出:[91m./python: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by ./python) [0mgenerate-posix-vars failed Makefile:592: recipe for target 'pybuilddir.txt' failed [91mmake: *** [pybuilddir.txt] Error 1 [0m

标签: python linux docker ssl openssl


【解决方案1】:

我认为 Jenkins Image 安装了一些不是 1.1.1 的 openssl 版本,因此您在 libssl 中找到 X509... 但无法构建。

关于配置选项,您可以使用 bash 作为 CMD 启动容器,将配置从容器内复制到映像所在的机器,编辑 ist 并将您的配置版本烘焙到映像中。

【讨论】:

  • 是的,但是 Dockerfile 的重点是不需要这些步骤,因此可以分发和重用...
  • 将配置烘焙到镜像后,您就有了镜像的工作版本,可以重新分发和重用
  • 也许我不清楚,我并不是说将配置复制到正在运行的容器中。我的意思是,将配置复制出正在运行的容器,在本地计算机上进行编辑,然后创建一个基于相关图像的新图像(来自图像 xyz),并在该图像中使用您的配置(复制 myconfig /路径/to/config/in/image)
  • 好的,有道理。我可以直接在容器中编辑安装文件,但显然这并不能解决问题。 make 仍然给我一个错误:./python: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by ./python)。有什么想法吗?
  • 我无法重现您的问题,您的 Dockerfile 对我有用
【解决方案2】:
Following modules built successfully but were removed because they could not be imported:
_hashlib              _ssl                                     

Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

从源代码构建 openssl 时似乎出现安装问题。对于 _ssl 模块上的构建失败,请在使用脚本 ./configure 配置 Python 时尝试额外的选项,例如 --with-opensslCFLAGSLDFLAGS,例如

./configure  --with-openssl=/PATH/TO/YOUR/OPENSSL_INSTALL_FOLDER/ \
    --enable-optimizations \
    --with-ssl-default-suites=openssl \
    CFLAGS="-I/PATH/TO/YOUR/OPENSSL_INSTALL_FODLER/include" \
    LDFLAGS="-L/PATH/TO/YOUR/OPENSSL_INSTALL_FODLER/"

也试试这个命令openssl version,如果它报告这样的错误:

/usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found

这意味着您的 openssl 库存在链接问题,我不确定您是在 Linux 还是其他系统上,但对于 Linux 系统,您可以手动修改指向 openssl 库的链接以解决问题,如所述@ 987654321@.

参考

Building Python 3.7.1 - SSL module failed

Python 3.7.0 wont compile with SSL Support 1.1.0

【讨论】:

    猜你喜欢
    • 2019-04-14
    • 2019-05-01
    • 2017-05-23
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多