--- Python-3.4.6-orig/Modules/_ssl.c 2017-10-13 14:59:37.118231718 +1100 +++ Python-3.4.6/Modules/_ssl.c 2017-10-13 16:30:03.634881306 +1100 @@ -72,6 +72,7 @@ #include "openssl/ssl.h" #include "openssl/err.h" #include "openssl/rand.h" +#include "openssl/dh.h" /* SSL error object */ static PyObject *PySSLErrorObject; @@ -131,6 +132,14 @@ #endif #define TLS_method SSLv23_method +#define TLS_client_method SSLv23_client_method +#define TLS_server_method SSLv23_server_method +#define X509_get0_notBefore X509_get_notBefore +#define X509_get0_notAfter X509_get_notAfter +#define ASN1_STRING_get0_data ASN1_STRING_data +#define OpenSSL_version_num SSLeay +#define OpenSSL_version SSLeay_version +#define OPENSSL_VERSION SSLEAY_VERSION static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) { @@ -961,7 +970,7 @@ goto fail; } PyTuple_SET_ITEM(t, 0, v); - v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as), + v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_get0_data(as), ASN1_STRING_length(as)); if (v == NULL) { Py_DECREF(t); @@ -1237,7 +1246,7 @@ Py_DECREF(sn_obj); (void) BIO_reset(biobuf); - notBefore = X509_get_notBefore(certificate); + notBefore = X509_get0_notBefore(certificate); ASN1_TIME_print(biobuf, notBefore); len = BIO_gets(biobuf, buf, sizeof(buf)-1); if (len < 0) { @@ -1254,7 +1263,7 @@ Py_DECREF(pnotBefore); (void) BIO_reset(biobuf); - notAfter = X509_get_notAfter(certificate); + notAfter = X509_get0_notAfter(certificate); ASN1_TIME_print(biobuf, notAfter); len = BIO_gets(biobuf, buf, sizeof(buf)-1); if (len < 0) { @@ -2053,7 +2062,7 @@ { char *kwlist[] = {"protocol", NULL}; PySSLContext *self; - int proto_version = PY_SSL_VERSION_SSL23; + int proto_version = PY_SSL_VERSION_TLS; long options; SSL_CTX *ctx = NULL; int result = 0; @@ -3419,7 +3428,11 @@ if (bytes == NULL) return NULL; if (pseudo) { +#ifdef OPENSSL_VERSION_1_1 + ok = RAND_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); +#else ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); +#endif if (ok == 0 || ok == 1) return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False); } @@ -4082,9 +4095,14 @@ return NULL; PySocketModule = *socket_api; +#ifdef OPENSSL_VERSION_1_1 + OPENSSL_init_ssl(0, NULL); +#else /* Init OpenSSL */ SSL_load_error_strings(); SSL_library_init(); +#endif + #ifdef WITH_THREAD #ifdef HAVE_OPENSSL_CRYPTO_LOCK /* note that this will start threading if not already started */ @@ -4096,7 +4114,10 @@ _ssl_locks_count++; #endif #endif /* WITH_THREAD */ + +#ifndef OPENSSL_VERSION_1_1 OpenSSL_add_all_algorithms(); +#endif /* Add symbols to module dict */ sslerror_type_slots[0].pfunc = PyExc_OSError; @@ -4349,10 +4370,10 @@ return NULL; /* OpenSSL version */ - /* SSLeay() gives us the version of the library linked against, + /* OpenSSL_version_num() gives us the version of the library linked against, which could be different from the headers version. */ - libver = SSLeay(); + libver = OpenSSL_version_num(); r = PyLong_FromUnsignedLong(libver); if (r == NULL) return NULL; @@ -4362,7 +4383,7 @@ r = Py_BuildValue("IIIII", major, minor, fix, patch, status); if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) return NULL; - r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION)); + r = PyUnicode_FromString(OpenSSL_version(OPENSSL_VERSION)); if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) return NULL; --- Python-3.4.6-orig/Modules/_hashopenssl.c 2017-10-12 17:51:13.000000000 +1100 +++ Python-3.4.6/Modules/_hashopenssl.c 2017-10-13 15:56:46.079180074 +1100 @@ -893,8 +893,10 @@ { PyObject *m, *openssl_md_meth_names; +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) OpenSSL_add_all_digests(); ERR_load_crypto_strings(); +#endif /* TODO build EVP_functions openssl_* entries dynamically based * on what hashes are supported rather than listing many