简体   繁体   English

手动更新 windows x64 上 python 使用的 openssl 版本

[英]Manually update the openssl version used by python on windows x64

I am running python 3.9.1 for windows 10 (x64).我正在为 windows 10 (x64) 运行 python 3.9.1。 I have noticed the openssl dll files shipped with python (libcrypto-1_1.dll & libssl-1_1.dll) are only version 1.1.1.7. I have noticed the openssl dll files shipped with python (libcrypto-1_1.dll & libssl-1_1.dll) are only version 1.1.1.7. I would therefore like to replace these with the latest versions.因此,我想用最新版本替换这些。

I have been able to successfully build openssl 1.1.1.9 in windows 10 following the instructions in the release.按照发布中的说明,我已经能够在 windows 10 中成功构建 openssl 1.1.1.9。 I am using Microsoft visual studio 2019 + strawberry perl + nasm.我正在使用 Microsoft Visual Studio 2019 + 草莓 perl + nasm。 I ran the following config command using the x64 native tools command prompt for vs 2019:我使用 vs 2019 的 x64 本机工具命令提示符运行以下配置命令:

perl Configure VC-WIN64A

I then run the nmake command.然后我运行 nmake 命令。 This produces the two dlls I need: libcrypto-1_1-x64.dll and libssl-1_1-x64.dll这会产生我需要的两个 dll:libcrypto-1_1-x64.dll 和 libssl-1_1-x64.dll

I renamed both files to remove the "-x64" at the end of the name and then used them to replace the existing dlls in the python installation.我重命名了这两个文件以删除名称末尾的“-x64”,然后用它们替换 python 安装中的现有 dll。

When I try to import the ssl library in python, I get the error:当我尝试在 python 中导入 ssl 库时,出现错误:

ImportError: DLL load failed while importing _ssl: The specified module could not be found.

I then built openssl for x86, using the x86 native tools command prompt for vs 2019 and the command:然后,我使用 vs 2019 的 x86 本机工具命令提示符和命令为 x86 构建 openssl 和命令:

perl Configure VC-WIN32

I then ran nmake which produced: libcrypto-1_1.dll and libssl-1_1.dll然后我运行了 nmake,它产生了: libcrypto-1_1.dll 和 libssl-1_1.dll

I replaced the dlls in the python installation with those.我用这些替换了 python 安装中的 dll。 When I try and import the ssl library in python I get:当我尝试在 python 中导入 ssl 库时,我得到:

ImportError: DLL load failed while importing _ssl: %1 is not a valid Win32 application.

I am reasonably certain I need the x64 version of the dlls because (1) my python installation is x64 (2) when I used the visual studio dumpbin.exe tool on the python shipped dlls to inspect the headers they say "x64" in them (3) the x64 dlls are a similar size to the ones shipped with python and the x86 versions are smaller.我有理由确定我需要 x64 版本的 dll,因为 (1) 我的 python 安装是 x64 (2) 当我在 python 上使用 Visual Studio dumpbin.exe 工具时,我使用了 dll 来检查他们在其中说“x64”的标题(3) x64 dll 的大小与 python 随附的大小相似,而 x86 版本更小。

I was once able to do this following the above steps for an older version of python.对于旧版本的 python,我曾经能够按照上述步骤执行此操作。 That version shipped with openssl 1.1.3 (could be 4) and I built the dlls for 1.1.6 (could be 7) and replaced them and python had no issues.该版本随附 openssl 1.1.3(可能是 4),我为 1.1.6(可能是 7)构建了 dll 并替换了它们,python 没有问题。 Is it possible that the default configuration scripts have changed over these versions such that the default windows x64 configuration no longer builds openssl in a way that works with python and I therefore need to use custom settings?默认配置脚本是否可能在这些版本上发生了更改,以至于默认 windows x64 配置不再以与 python 一起使用的方式构建 openssl,因此我需要使用自定义设置?

I think the info at section 1.3 of this page may be relevant, but if it is I am not sure how to implement that in the openssl build process.我认为本页第 1.3 节中的信息可能是相关的,但如果是,我不确定如何在 openssl 构建过程中实现该信息。

I managed to solve this with some help.我设法在一些帮助下解决了这个问题。

The scripts used by CPython to build OpenSSL for the windows installers actually run the command: CPython 用于为 windows 安装程序构建 OpenSSL 的脚本实际上运行以下命令:

Perl Configure VC-WIN64A-masm no-asm

instead of代替

Perl Configure VC-WIN64A

After running the correct command on the setup described in my original post I was able to swap out the dlls and python accepted them without issue.在我原来的帖子中描述的设置上运行正确的命令后,我能够换出 dll 并且 python 毫无问题地接受了它们。

ssl.OPENSSL_VERSION now outputs 'OpenSSL 1.1.1i 8 Dec 2020'. ssl.OPENSSL_VERSION 现在输出“OpenSSL 1.1.1i 2020 年 12 月 8 日”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM