在FreeBSD上使用旧的python版本(2.7.3)的SSL

问题描述 投票:0回答:2

我从源代码安装了一个旧版本的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的情况下使用它们)

python python-2.7 openssl setuptools freebsd
2个回答
1
投票

使用较新的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。


0
投票

python27和python36都可以从ports和packages安装(参见下面的依赖项)。我认为问题来自混合pip与freebsd端口和包。尝试干净安装和“pkg install python27 python36”。

# pkg info | grep python
py27-asn1crypto-0.22.0         ASN.1 library with a focus on performance and a 
pythonic API
py27-requests-toolbelt-0.8.0   Utility belt for advanced users of python-requests
py36-asn1crypto-0.22.0         ASN.1 library with a focus on performance and a 
pythonic API
py36-requests-toolbelt-0.8.0   Utility belt for advanced users of python-requests
python27-2.7.16                Interpreted object-oriented programming language
python36-3.6.8_1               Interpreted object-oriented programming language

# pkg info -dx python27
python27-2.7.16:
    openssl-1.0.2r,1
    readline-7.0.5
    libffi-3.2.1_3
© www.soinside.com 2019 - 2024. All rights reserved.