python - 如何升级openssl版本并将其链接到python 3.6.5

标签 python ssl openssl tls1.2 pyopenssl

我的 Ubuntu 机器上有多个版本的 python。默认值为 2.7。但是,我可以通过转到特定路径来运行 python 3.6:

/usr/local/bin/code/tls-client

我需要在我的Python代码中使用openSSL库。我想运行特定版本:1.1.0。我尝试使用 pip install openssl 然后检查版本是否已更新,但事实并非如此。

python3
Python 3.6.5 (default, May  3 2018, 10:08:28) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2g  1 Mar 2016'

如何将 python 3.6.5 链接到特定版本的 openSSL(例如 OpenSSL 1.1.0)?甚至 1.1.1(如果可能的话)?

编辑: 按照答案的建议从源代码编译后,我检查了版本,这就是我得到的:

/usr/local/bin/openssl-1.1.0h$ openssl version -a
OpenSSL 1.0.2g  1 Mar 2016
built on: reproducible build, date unspecified
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: cc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/lib/ssl"

最佳答案

假设您尚未更新到最新稳定版本的 OpenSSL(从 bash 控制台):

$ sudo apt update && sudo apt upgrade openssl

如果没有安装您期望的版本(通过执行 openssl version -a 进行检查),则尝试编译并手动安装:

wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz
tar xzvf openssl-1.1.0h.tar.gz
cd openssl-1.1.0h
./config -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)'
make
make install

openssl version -a

应将 OpenSSL 更新至版本 1.1.0h — 应自动处理链接。

关于python - 如何升级openssl版本并将其链接到python 3.6.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50663229/

相关文章:

python - 如何使用 python 和 openssl 验证 webhook 签名

Qt即使安装了也找不到libssl

ubuntu - OpenSSL 未签名的证书静默

python - JupyterHub 内核连接返回 HTTP504 GATEWAY_TIMEOUT

python - DRF 关联模型中的单个字段

ssl - 如何在 Go 中缓存/重用 TLS 连接

python - 由于环境错误,pip3 安装失败

使用超时时 Python OpenSSL 连接握手失败

python - 如果满足条件,则从列表列表中删除列表

python - 如何在基类内部声明子类对象而不导致递归错误?