首页 > 解决方案 > 使用自定义 openssl 在 python 3.8.0 中安装密码学的问题

问题描述

我参与了一个编译 python 3.8 和一组库的项目,这些库要部署在 RHEL6 和 RHEL7 机器的混合中。此外,由于 RHEL6 和 7(主要是在 /lib64 中找到的某些库)的差异,如果我要在 RHEL7 机器中编译它,我的 python 安装在 RHEL6 机器中不起作用,但反之亦然。所以我现在试图在 RHEL6 机器上编译这些东西,打包它并全面部署它。

请注意我正在编译 Python 3.8 的框,并且库是气隙机器,所以我只是将源代码从不同的机器转移到构建机器。

我遇到的第一个问题是,Python3.8 抱怨旧版本的 ssl 库,我使用下面链接中概述的步骤解决了这个问题

https://jameskiefer.com/posts/installing-python-3.7-on-debian-8

这是我遇到问题的地方。我使用我之前编译的 openssl 来构建 Python 3.8 并使用它来编译密码学,注意下面的链接。

https://cryptography.io/en/latest/installation/#static-wheels

Cryptography 安装得很好,但它仍然指向本机 libssl,而不是我编译的新更新的 libssl。

在生成轮子的部分,我打开了调试模式,我注意到了这些命令。

  running build_ext
  generating cffi module 'build/temp.linux-x86_64-3.8/_padding.c'
  creating build/temp.linux-x86_64-3.8
  generating cffi module 'build/temp.linux-x86_64-3.8/_constant_time.c'
  generating cffi module 'build/temp.linux-x86_64-3.8/_openssl.c'
  building '_openssl' extension
  creating build/temp.linux-x86_64-3.8/build
  creating build/temp.linux-x86_64-3.8/build/temp.linux-x86_64-3.8
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/apps/ops/python3/include/python3.8 -c build/temp.linux-x86_64-3.8/_openssl.c -o build/temp.linux-x86_64-3.8/build/temp.li
nux-x86_64-3.8/_openssl.o -Wconversion -Wno-error=sign-conversion

看起来正在生成的 _openssl.o 只使用了操作系统本机库,尽管我看到我的开关很快就正确显示了。

  gcc -pthread -shared -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib build/temp.linux-x86_64-3.8/build/temp.linux
-x86_64-3.8/_openssl.o -lssl -lcrypto -o build/lib.linux-x86_64-3.8/cryptography/hazmat/bindings/_openssl.abi3.so
  building '_constant_time' extension
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/apps/ops/python3/include/python3.8 -c build/temp.linux-x86_64-3.8/_constant_time.c -o build/temp.linux-x86_64-3.8/build/t
emp.linux-x86_64-3.8/_constant_time.o
  gcc -pthread -shared -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib build/temp.linux-x86_64-3.8/build/temp.linux
-x86_64-3.8/_constant_time.o -o build/lib.linux-x86_64-3.8/cryptography/hazmat/bindings/_constant_time.abi3.so
  building '_padding' extension
  gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/apps/ops/python3/include/python3.8 -c build/temp.linux-x86_64-3.8/_padding.c -o build/temp.linux-x86_64-3.8/build/temp.li
nux-x86_64-3.8/_padding.o
  gcc -pthread -shared -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib -Wl,-rpath,/apps/ops/python3/openssl/lib build/temp.linux-x86_64-3.8/build/temp.linux
-x86_64-3.8/_padding.o -o build/lib.linux-x86_64-3.8/cryptography/hazmat/bindings/_padding.abi3.so

请看下面的输出。我完全无法解决这个问题,或者这只是不可行,我必须寻找不同的解决方案。

(env) [user1@devhost wheelhouse]$ python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: '
 + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
/home/user1/tmp/env/lib/python3.8/site-packages/cryptography/hazmat/bindings/openssl/binding.py:159: CryptographyDeprecationWarning: OpenSSL version 1.0.1 is no longer supported by the Open
SSL project, please upgrade. The next version of cryptography will drop support for it.
  warnings.warn(
Loaded: OpenSSL 1.0.1e-fips 11 Feb 2013
Linked Against: OpenSSL 1.0.1e 11 Feb 2013

(env) [user1@devhost wheels]$ python -c 'import ssl; print (ssl.OPENSSL_VERSION)'
OpenSSL 1.0.2t  10 Sep 2019

标签: python-3.xlinuxpipcryptographyparamiko

解决方案


推荐阅读