4

我正在尝试强制 python 2.7 与修改后的 openssl 库一起使用。我需要支持俄罗斯 GOST 密码。所以我像这样配置了OpenSSL

./config shared zlib enable-rfc3779 --prefix=/my/path/

并安装它(制作依赖,制作,制作测试,制作安装)。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 lib 编译 python:我取消注释并将 Modules/Setup.dist 中的 SSL 变量更改为/my/path及其下的相关行,并且还更改了 setup.py 中ssl_incsssl_libs变量。我已将 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

4

1 回答 1

0

尝试通过 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 函数内部。

于 2018-02-07T14:41:27.553 回答