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

时间:2018-06-03 04:12:20

标签: python ssl openssl tls1.2 pyopenssl

我有几个版本的python我的Ubuntu机器。默认值为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(如果可能的话)?

修改 根据答案的建议从源头编译后,我检查了verison,这就是我得到的:

/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"

1 个答案:

答案 0 :(得分:0)

假设您还没有更新到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 - 应自动处理链接。