我有一个使用M2Crypto编写的python SSL客户端,我想添加SNI支持。
看起来像OpenSSL会使用''' SSL_set_tlsext_host_name(ssl, servername)'',但我没有看到M2Crypto API中暴露的函数。
是我错过了它还是有其他方法可以做到这一点?
我查看了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 bug/增强跟踪器