2ca359
Based on https://bugzilla.osafoundation.org/attachment.cgi?id=5760
2ca359
by Sander Steffann <sander@steffann.nl>.
2ca359
2ca359
diff -ur M2Crypto/M2Crypto/SSL/Connection.py M2Crypto-0.21.1/M2Crypto/SSL/Connection.py
2ca359
--- M2Crypto/M2Crypto/SSL/Connection.py	2013-12-17 02:01:49.843287273 +0100
2ca359
+++ M2Crypto-0.21.1/M2Crypto/SSL/Connection.py	2013-12-17 02:28:28.357633159 +0100
2ca359
@@ -368,3 +368,7 @@
2ca359
 
2ca359
     def set_post_connection_check_callback(self, postConnectionCheck):
2ca359
         self.postConnectionCheck = postConnectionCheck
2ca359
+
2ca359
+    def set_tlsext_host_name(self, name):
2ca359
+        "Set the requested hostname for the SNI (Server Name Indication) extension"
2ca359
+        m2.ssl_set_tlsext_host_name(self.ssl, name)
2ca359
diff -ur M2Crypto/SWIG/_ssl.i M2Crypto-0.21.1/SWIG/_ssl.i
2ca359
--- M2Crypto/SWIG/_ssl.i	2013-12-17 02:01:49.863287264 +0100
2ca359
+++ M2Crypto-0.21.1/SWIG/_ssl.i	2013-12-17 02:39:28.138364398 +0100
2ca359
@@ -15,6 +15,7 @@
2ca359
 #include <openssl/bio.h>
2ca359
 #include <openssl/dh.h>
2ca359
 #include <openssl/ssl.h>
2ca359
+#include <openssl/tls1.h>
2ca359
 #include <openssl/x509.h>
2ca359
 #include <poll.h>
2ca359
 #include <sys/time.h>
2ca359
@@ -398,6 +399,17 @@
2ca359
     return SSL_get_mode(ssl);
2ca359
 }
2ca359
 
2ca359
+int ssl_set_tlsext_host_name(SSL *ssl, const char *name) {
2ca359
+    long l;
2ca359
+
2ca359
+    if (!(l = SSL_set_tlsext_host_name(ssl, name))) {
2ca359
+        PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error()));
2ca359
+        return -1;
2ca359
+    }
2ca359
+    /* Return an "int" to match the 'typemap(out) int' in _lib.i */
2ca359
+    return 1;
2ca359
+}
2ca359
+
2ca359
 void ssl_set_client_CA_list_from_file(SSL *ssl, const char *ca_file) {
2ca359
     SSL_set_client_CA_list(ssl, SSL_load_client_CA_file(ca_file));
2ca359
 }