python - 在 FreeBSD 上使用旧 python 版本 (2.7.3) 的 SSL
问题描述
我将旧版本的 Python (2.7.3) 从源代码安装到目录中(不是系统的默认 python),以便偶尔运行旧应用程序。我想用 pip 或 easy_install 配置这个环境,但这不起作用,因为需要 SSL,我不能用 ssl 构建这个版本。构建工作,但我得到了消息
Failed to build these modules:
_ctypes _hashlib _ssl
已安装 OpenSSL(它是一台 FreeBSD 机器)。从源代码构建 Python 2.7.15 并安装这些模块。
我的猜测是 2.7.3 可能需要旧版本的 OpenSSL(我安装了 1.1.1a-freebsd)。
如何在启用 SSL 的情况下构建这个 Python 版本?(我设法安装了 setuptools,但没有 SSL 就无法使用它们)
解决方案
使用更新的 OpenSSL 构建 Python 2.7 的补丁:
--- Modules/_ssl.c.orig 2018-03-05 01:25:37.803984781 +0300
+++ Modules/_ssl.c 2018-03-05 01:25:04.499198913 +0300
@@ -300,8 +300,10 @@
PySSL_BEGIN_ALLOW_THREADS
if (proto_version == PY_SSL_VERSION_TLS1)
self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */
+#ifndef OPENSSL_NO_SSL3
else if (proto_version == PY_SSL_VERSION_SSL3)
self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
+#endif
#ifndef OPENSSL_NO_SSL2
else if (proto_version == PY_SSL_VERSION_SSL2)
self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
--- Lib/ssl.py.orig 2017-09-19 10:32:02.000000000 +0300
+++ Lib/ssl.py 2018-03-05 01:38:26.358119752 +0300
@@ -91,14 +91,13 @@
SSL_ERROR_INVALID_ERROR_CODE,
)
from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN
-from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23,
+from _ssl import (PROTOCOL_SSLv23,
PROTOCOL_TLSv1)
from _ssl import _OPENSSL_API_VERSION
_PROTOCOL_NAMES = {
PROTOCOL_TLSv1: "TLSv1",
PROTOCOL_SSLv23: "SSLv23",
- PROTOCOL_SSLv3: "SSLv3",
}
try:
from _ssl import PROTOCOL_SSLv2
@@ -664,7 +663,7 @@
d = pem_cert_string.strip()[len(PEM_HEADER):-len(PEM_FOOTER)]
return base64.decodebytes(d.encode('ASCII', 'strict'))
-def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
+def get_server_certificate(addr, ssl_version=PROTOCOL_TLSv1, ca_certs=None):
"""Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
我在 Debian 9 下使用 OpenSSL 1.1.0j 编译了 Python 2.7.10。
推荐阅读
- internet-explorer - IE 11 浏览器后退按钮抛出 NullPointerException
- hyperledger-fabric - 已部署网络中缺少 lib/logic.js 文件
- sql - 具有多个过滤条件的 SQL 存储过程更新
- laravel - 这个错误 [Composer\Downloader\TransportException] 有解决方案吗?
- java - 当每个页面中的定位器 ID 不同时,如何在 Selenium WebDriver 中选择单选按钮
- javascript - 同时在javascript中循环两个数组
- c# - 在 Revit API 中使用“Set()”方法定义一个参数的布尔值的正确方法是什么?
- awk - 列之间是否有用于字符串减法的 Linux 命令?
- javascript - 每次手动添加选择选项都不能正常工作,即使做到了,第二次尝试总是失败
- javascript - 如何在单击按钮时向右滚动。?