python - 如何使用修改后的 OpenSSL(具有俄罗斯 GOST 支持)编译 python?

标签 python linux ssl openssl gost3410

我试图强制 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_incsssl_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/

相关文章:

Python如何为列表中的元素之一添加引号?

python - 正则表达式解析字符串

linux - 在 Bash/sed 中分隔字符

.net - 为 soap web 代理启用 TLS 1.2 的最简单方法是什么?

MongoDB 自签名 SSL 连接 : SSL peer certificate validation failed

python - 密集层的 LSTM 初始状态

python - 创建相同数字列表的有效方法?

linux - 在另一个目录中运行 cat 命令

c - dma_mmap_coherent 和 remap_pfn_range 有什么区别?

java - 获取 Java SSLSocket 的可信 X509Certificate