2

我有一个使用 M2Crypto 编写的 python SSL 客户端,我想添加SNI支持。

看起来像使用 OpenSSL 的人会使用 ```SSL_set_tlsext_host_name(ssl, servername)''' 但我没有看到 M2Crypto API 中公开了该函数。

我只是想念它还是有其他方法可以做到这一点?

4

1 回答 1

2

我查看了 M2Crypto SVN 存储库中的最新代码,但 SNI 尚不支持。我也需要 SNI,所以本着真正的开源精神,我为它写了一个补丁 :-)

添加它的补丁其实很简单:

Index: SWIG/_ssl.i
===================================================================
--- SWIG/_ssl.i (revision 739)
+++ SWIG/_ssl.i (working copy)
@@ -14,6 +14,7 @@
 #include <openssl/bio.h>
 #include <openssl/dh.h>
 #include <openssl/ssl.h>
+#include <openssl/tls1.h>
 #include <openssl/x509.h>
 %}

@@ -375,6 +376,10 @@
     return SSL_get_mode(ssl);
 }

+long ssl_set_tlsext_host_name(SSL *ssl, const char *name) {
+    return SSL_set_tlsext_host_name(ssl, name);
+}
+
 void ssl_set_client_CA_list_from_file(SSL *ssl, const char *ca_file) {
     SSL_set_client_CA_list(ssl, SSL_load_client_CA_file(ca_file));
 }
Index: M2Crypto/SSL/Connection.py
===================================================================
--- M2Crypto/SSL/Connection.py  (revision 739)
+++ M2Crypto/SSL/Connection.py  (working copy)
@@ -359,3 +359,7 @@

     def set_post_connection_check_callback(self, postConnectionCheck):
         self.postConnectionCheck = postConnectionCheck
+
+    def set_tlsext_host_name(self, name):
+        "Set the requested hostname for the SNI (Server Name Indication) extension"
+        m2.ssl_set_tlsext_host_name(self.ssl, name)

当然,这也已提交给 M2Crypto 错误/增强跟踪器。

于 2012-12-01T14:06:05.117 回答