Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在FreeBSD上使用旧python版本(2.7.3)的SSL_Python_Python 2.7_Openssl_Setuptools_Freebsd - Fatal编程技术网

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

在FreeBSD上使用旧python版本(2.7.3)的SSL,python,python-2.7,openssl,setuptools,freebsd,Python,Python 2.7,Openssl,Setuptools,Freebsd,我将一个旧版本的Python(2.7.3)从源代码安装到一个目录(不是系统默认的Python)中,以便能够偶尔运行一个旧的应用程序。我想用pip或easy_install配置这个环境,但这不起作用,因为需要SSL,我不能用SSL构建这个版本。构建工作正常,但我明白了这一点 Failed to build these modules: _ctypes _hashlib _ssl 已安装OpenSSL(它是一台FreeBSD机器)。从源代码构建Python

我将一个旧版本的Python(2.7.3)从源代码安装到一个目录(不是系统默认的Python)中,以便能够偶尔运行一个旧的应用程序。我想用pip或easy_install配置这个环境,但这不起作用,因为需要SSL,我不能用SSL构建这个版本。构建工作正常,但我明白了这一点

Failed to build these modules:
_ctypes            _hashlib           _ssl
已安装OpenSSL(它是一台FreeBSD机器)。从源代码构建Python2.7.15并安装这些模块

我猜2.7.3可能需要一个较旧版本的OpenSSL(我已经安装了1.1.1a-freebsd)


如何在启用SSL的情况下构建此Python版本?(我设法安装了setuptools,但如果没有SSL,我无法使用它们)

可以从端口和软件包安装python27和python36(请参见下文,包括依赖项)。我认为问题来自pip与freebsd端口和包的混合。尝试清洁安装和“pkg安装python27 python36”


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

您是否尝试过安装libssl dev?我记得Linux Mint早就遇到了同样的问题。我的服务器运行在FreeBSD上,我已经安装了openssl,并成功地运行在我的其他Python安装上(BSD上没有libssl dev)。您可能需要检查build.log以找出无法构建openssl模块的原因。好的,尽管我没有找到这样的文件,我在运行make时创建了一个,包括错误(
make2>&1 | tee build.log
)。因此,此Python版本中需要的一些协议(如SSLv3)在已安装的openssl版本中被标记为已弃用。谢谢你给我指明了正确的方向。与此同时,我试图为这个Python版本构建一个较旧版本的openssl(0.9.8),但我无法用clang编译它。混合使用gcc编译的openssl和clang编译的Python似乎不是一个好主意。也许我应该试着用gcc来编译这两种语言。谢谢你的输入。但我没有将端口与软件包混用,也不是关于系统范围的Python,在我的例子中,它是2.7.15(我从软件包安装的),运行良好。它是从源代码构建的几个独立Python安装中的一个。我在构建2.3.6、2.4.3和2.7.15时没有遇到任何问题,但在构建2.7.3时遇到了SSL问题。不幸的是,这对我来说不起作用。我想Python 2.7.3和OpenSSL 1.1.1之间的距离比2.7.10和1.1.0要远。仍然有10个错误和10个警告,比如
Modules/\u ssl.c:629:26:error:type'struct X509\u name\u entry\u st'rdn\u level=entry->set的定义不完整
模块/_hashopenssl.c:163:16:错误:变量具有不完整的类型“EVP\u MD\u CTX”(又名“struct EVP\u MD\u CTX st”)EVP\u MD\u CTX temp\u CTX
--- 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.