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

Manually update the openssl version used by python on windows x64

我正在 运行宁 python 3.9.1 for windows 10 (x64)。我注意到 python(libcrypto-1_1.dll 和 libssl-1_1.dll)附带的 openssl dll 文件只有 1.1.1.7 版本。因此,我想用最新版本替换它们。

我已经能够按照发行版中的说明在 windows 10 中成功构建 openssl 1.1.1.9。我正在使用 Microsoft visual studio 2019 + strawberry perl + nasm。我 运行 以下配置命令使用 vs 2019 的 x64 本机工具命令提示符:

perl Configure VC-WIN64A

然后我运行 nmake 命令。这会生成我需要的两个 dll:libcrypto-1_1-x64.dll 和 libssl-1_1-x64.dll

我重命名了这两个文件以删除名称末尾的“-x64”,然后用它们替换 python 安装中现有的 dll。

当我尝试在 python 中导入 ssl 库时,出现错误:

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

然后我为 x86 构建了 openssl,使用 vs 2019 的 x86 本机工具命令提示符和命令:

perl Configure VC-WIN32

然后我 运行 nmake 生成了:libcrypto-1_1.dll 和 libssl-1_1.dll

我用那些替换了 python 安装中的 dll。当我尝试在 python 中导入 ssl 库时,我得到:

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

我相当确定我需要 dll 的 x64 版本,因为 (1) 我的 python 安装是 x64 (2) 当我使用 visual studio dumpbin.exe 工具时python 运送 dll 以检查 headers 他们在其中说“x64”(3) x64 dll 的大小与 python 附带的大小相似,而 x86 版本更小。

我曾经能够按照旧版本 python 的上述步骤执行此操作。该版本随 openssl 1.1.3(可能是 4)一起发布,我为 1.1.6(可能是 7)构建了 dll 并替换了它们,python 没有问题。默认配置脚本是否有可能在这些版本上发生了变化,以至于默认 windows x64 配置不再以与 python 一起使用的方式构建 openssl,因此我需要使用自定义设置?

我认为 this page 第 1.3 节的信息可能相关,但如果相关,我不确定如何在 openssl 构建过程中实现它。

我在一些帮助下设法解决了这个问题。

CPython 用于为 windows 安装程序构建 OpenSSL 的脚本实际上 运行 命令:

Perl Configure VC-WIN64A-masm no-asm

而不是

Perl Configure VC-WIN64A

运行在我的原始 post 中描述的设置上执行正确的命令后,我能够换出 dll 并且 python 毫无问题地接受了它们。

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