我试图强制 python 2.7 使用修改后的 openssl 库。我需要支持俄罗斯 GOST 密码。所以我像这样配置 OpenSSL
./config shared zlib enable-rfc3779 --prefix=/my/path/
并安装它(make depend、make、make test、make install)。 openssl.conf 包含
openssl_conf = openssl_def
[openssl_def]
engines = engine_section
[engine_section]
gost = gost_section
[gost_section]
engine_id = gost
default_algorithms = ALL
在那个命令之后/my/path/bin/openssl ciphers | tr ":" "\n" | grep GOST
返回
GOST2001-GOST89-GOST89
GOST94-GOST89-GOST89
和openssl s_client -connect test.domain.ru:443
连接成功,我可以发送 GET 请求(标准 OpenSSL 不适用于此站点)。之后,我尝试使用该 openssl 库编译 python:我取消注释并将 Modules/Setup.dist 中的 SSL 变量更改为 /my/path
和它下面的相关行,也改变了ssl_incs
和 ssl_libs
setup.py 中的变量。我已将 python 安装到我的主文件夹并从该文件夹运行脚本。但是当我那样运行脚本时
import urllib2
print(urllib2.urlopen('https://test.domain.ru/').read())
还是报错
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:501: error:140920F8:SSL routines:SSL3_GET_SERVER_HELLO:unknown cipher returned>
我应该怎么做才能强制 python 使用新的 OpenSSL(gost 引擎),可能有什么简单的方法可以做到这一点?
操作系统:Linux Mint 17 x64
最佳答案
尝试在 Modules/_ssl.c 中进行一些更改来重建 _ssl.pyd。 1) 在行后添加#include
#include <openssl/x509.h>
#include <openssl/err.h>
#include <openssl/rand.h>
2) 添加 OPENSSL_config(NULL);行前
SSL_library_init();
SSL_load_error_strings();
在 init_ssl 函数中。
关于python - 如何使用修改后的 OpenSSL(具有俄罗斯 GOST 支持)编译 python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834760/