@@ -63,6 +63,7 @@ static PySocketModule_APIObject PySocketModule;
63
63
#include "openssl/err.h"
64
64
#include "openssl/rand.h"
65
65
#include "openssl/bio.h"
66
+ #include "openssl/dh.h"
66
67
67
68
/* SSL error object */
68
69
static PyObject * PySSLErrorObject ;
@@ -162,9 +163,17 @@ static void _PySSLFixErrno(void) {
162
163
#else /* OpenSSL < 1.1.0 */
163
164
#define HAVE_OPENSSL_CRYPTO_LOCK
164
165
166
+ #ifndef OPENSSL_VERSION_1_1
165
167
#define TLS_method SSLv23_method
166
168
#define TLS_client_method SSLv23_client_method
167
169
#define TLS_server_method SSLv23_server_method
170
+ #define X509_get0_notBefore X509_get_notBefore
171
+ #define X509_get0_notAfter X509_get_notAfter
172
+ #define ASN1_STRING_get0_data ASN1_STRING_data
173
+ #define OpenSSL_version_num SSLeay
174
+ #define OpenSSL_version SSLeay_version
175
+ #define OPENSSL_VERSION SSLEAY_VERSION
176
+ #endif
168
177
169
178
static int X509_NAME_ENTRY_set (const X509_NAME_ENTRY * ne )
170
179
{
@@ -1123,7 +1132,7 @@ _get_peer_alt_names (X509 *certificate) {
1123
1132
goto fail ;
1124
1133
}
1125
1134
PyTuple_SET_ITEM (t , 0 , v );
1126
- v = PyUnicode_FromStringAndSize ((char * )ASN1_STRING_data (as ),
1135
+ v = PyUnicode_FromStringAndSize ((char * )ASN1_STRING_get0_data (as ),
1127
1136
ASN1_STRING_length (as ));
1128
1137
if (v == NULL ) {
1129
1138
Py_DECREF (t );
@@ -1426,7 +1435,7 @@ _decode_certificate(X509 *certificate) {
1426
1435
Py_DECREF (sn_obj );
1427
1436
1428
1437
(void ) BIO_reset (biobuf );
1429
- notBefore = X509_get_notBefore (certificate );
1438
+ notBefore = X509_get0_notBefore (certificate );
1430
1439
ASN1_TIME_print (biobuf , notBefore );
1431
1440
len = BIO_gets (biobuf , buf , sizeof (buf )- 1 );
1432
1441
if (len < 0 ) {
@@ -1443,7 +1452,7 @@ _decode_certificate(X509 *certificate) {
1443
1452
Py_DECREF (pnotBefore );
1444
1453
1445
1454
(void ) BIO_reset (biobuf );
1446
- notAfter = X509_get_notAfter (certificate );
1455
+ notAfter = X509_get0_notAfter (certificate );
1447
1456
ASN1_TIME_print (biobuf , notAfter );
1448
1457
len = BIO_gets (biobuf , buf , sizeof (buf )- 1 );
1449
1458
if (len < 0 ) {
@@ -2822,7 +2831,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
2822
2831
conservative and assume it wasn't fixed until release. We do this check
2823
2832
at runtime to avoid problems from the dynamic linker.
2824
2833
See #25672 for more on this. */
2825
- libver = SSLeay ();
2834
+ libver = OpenSSL_version_num ();
2826
2835
if (!(libver >= 0x10001000UL && libver < 0x1000108fUL ) &&
2827
2836
!(libver >= 0x10000000UL && libver < 0x100000dfUL )) {
2828
2837
SSL_CTX_set_mode (self -> ctx , SSL_MODE_RELEASE_BUFFERS );
@@ -4625,7 +4634,11 @@ PySSL_RAND(int len, int pseudo)
4625
4634
if (bytes == NULL )
4626
4635
return NULL ;
4627
4636
if (pseudo ) {
4637
+ #ifdef OPENSSL_VERSION_1_1
4638
+ ok = RAND_bytes ((unsigned char * )PyBytes_AS_STRING (bytes ), len );
4639
+ #else
4628
4640
ok = RAND_pseudo_bytes ((unsigned char * )PyBytes_AS_STRING (bytes ), len );
4641
+ #endif
4629
4642
if (ok == 0 || ok == 1 )
4630
4643
return Py_BuildValue ("NO" , bytes , ok == 1 ? Py_True : Py_False );
4631
4644
}
@@ -5264,7 +5277,9 @@ PyInit__ssl(void)
5264
5277
return NULL ;
5265
5278
PySocketModule = * socket_api ;
5266
5279
5267
- #ifndef OPENSSL_VERSION_1_1
5280
+ #ifdef OPENSSL_VERSION_1_1
5281
+ OPENSSL_init_ssl (0 , NULL );
5282
+ #else
5268
5283
/* Load all algorithms and initialize cpuid */
5269
5284
OPENSSL_add_all_algorithms_noconf ();
5270
5285
/* Init OpenSSL */
@@ -5573,10 +5588,10 @@ PyInit__ssl(void)
5573
5588
return NULL ;
5574
5589
5575
5590
/* OpenSSL version */
5576
- /* SSLeay () gives us the version of the library linked against,
5591
+ /* OpenSSL_version_num () gives us the version of the library linked against,
5577
5592
which could be different from the headers version.
5578
5593
*/
5579
- libver = SSLeay ();
5594
+ libver = OpenSSL_version_num ();
5580
5595
r = PyLong_FromUnsignedLong (libver );
5581
5596
if (r == NULL )
5582
5597
return NULL ;
@@ -5586,7 +5601,7 @@ PyInit__ssl(void)
5586
5601
r = Py_BuildValue ("IIIII" , major , minor , fix , patch , status );
5587
5602
if (r == NULL || PyModule_AddObject (m , "OPENSSL_VERSION_INFO" , r ))
5588
5603
return NULL ;
5589
- r = PyUnicode_FromString (SSLeay_version ( SSLEAY_VERSION ));
5604
+ r = PyUnicode_FromString (OpenSSL_version ( OPENSSL_VERSION ));
5590
5605
if (r == NULL || PyModule_AddObject (m , "OPENSSL_VERSION" , r ))
5591
5606
return NULL ;
5592
5607
0 commit comments