@@ -127,21 +127,26 @@ struct py_ssl_library_code {
127
127
#endif
128
128
129
129
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
130
- # define HAVE_ALPN
130
+ # define HAVE_ALPN 1
131
+ #else
132
+ # define HAVE_ALPN 0
131
133
#endif
132
134
133
135
/* We cannot rely on OPENSSL_NO_NEXTPROTONEG because LibreSSL 2.6.1 dropped
134
136
* NPN support but did not set OPENSSL_NO_NEXTPROTONEG for compatibility
135
137
* reasons. The check for TLSEXT_TYPE_next_proto_neg works with
136
138
* OpenSSL 1.0.1+ and LibreSSL.
139
+ * OpenSSL 1.1.1-pre1 dropped NPN but still has TLSEXT_TYPE_next_proto_neg.
137
140
*/
138
141
#ifdef OPENSSL_NO_NEXTPROTONEG
139
- # define HAVE_NPN 0
142
+ # define HAVE_NPN 0
143
+ #elif (OPENSSL_VERSION_NUMBER >= 0x10101000L ) && !defined(LIBRESSL_VERSION_NUMBER )
144
+ # define HAVE_NPN 0
140
145
#elif defined(TLSEXT_TYPE_next_proto_neg )
141
- # define HAVE_NPN 1
146
+ # define HAVE_NPN 1
142
147
#else
143
- # define HAVE_NPN 0
144
- # endif
148
+ # define HAVE_NPN 0
149
+ #endif
145
150
146
151
#ifndef INVALID_SOCKET /* MS defines this */
147
152
#define INVALID_SOCKET (-1)
@@ -297,11 +302,11 @@ static unsigned int _ssl_locks_count = 0;
297
302
typedef struct {
298
303
PyObject_HEAD
299
304
SSL_CTX * ctx ;
300
- #ifdef HAVE_NPN
305
+ #if HAVE_NPN
301
306
unsigned char * npn_protocols ;
302
307
int npn_protocols_len ;
303
308
#endif
304
- #ifdef HAVE_ALPN
309
+ #if HAVE_ALPN
305
310
unsigned char * alpn_protocols ;
306
311
int alpn_protocols_len ;
307
312
#endif
@@ -1789,7 +1794,7 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self)
1789
1794
return PyUnicode_FromString (version );
1790
1795
}
1791
1796
1792
- #ifdef HAVE_NPN
1797
+ #if HAVE_NPN
1793
1798
/*[clinic input]
1794
1799
_ssl._SSLSocket.selected_npn_protocol
1795
1800
[clinic start generated code]*/
@@ -1810,7 +1815,7 @@ _ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self)
1810
1815
}
1811
1816
#endif
1812
1817
1813
- #ifdef HAVE_ALPN
1818
+ #if HAVE_ALPN
1814
1819
/*[clinic input]
1815
1820
_ssl._SSLSocket.selected_alpn_protocol
1816
1821
[clinic start generated code]*/
@@ -2745,7 +2750,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
2745
2750
#ifdef HAVE_NPN
2746
2751
self -> npn_protocols = NULL ;
2747
2752
#endif
2748
- #ifdef HAVE_ALPN
2753
+ #if HAVE_ALPN
2749
2754
self -> alpn_protocols = NULL ;
2750
2755
#endif
2751
2756
#ifndef OPENSSL_NO_TLSEXT
@@ -2877,10 +2882,10 @@ context_dealloc(PySSLContext *self)
2877
2882
PyObject_GC_UnTrack (self );
2878
2883
context_clear (self );
2879
2884
SSL_CTX_free (self -> ctx );
2880
- #ifdef HAVE_NPN
2885
+ #if HAVE_NPN
2881
2886
PyMem_FREE (self -> npn_protocols );
2882
2887
#endif
2883
- #ifdef HAVE_ALPN
2888
+ #if HAVE_ALPN
2884
2889
PyMem_FREE (self -> alpn_protocols );
2885
2890
#endif
2886
2891
Py_TYPE (self )-> tp_free (self );
@@ -2955,7 +2960,7 @@ _ssl__SSLContext_get_ciphers_impl(PySSLContext *self)
2955
2960
#endif
2956
2961
2957
2962
2958
- #if defined( HAVE_NPN ) || defined( HAVE_ALPN )
2963
+ #if HAVE_NPN || HAVE_ALPN
2959
2964
static int
2960
2965
do_protocol_selection (int alpn , unsigned char * * out , unsigned char * outlen ,
2961
2966
const unsigned char * server_protocols , unsigned int server_protocols_len ,
@@ -2981,7 +2986,7 @@ do_protocol_selection(int alpn, unsigned char **out, unsigned char *outlen,
2981
2986
}
2982
2987
#endif
2983
2988
2984
- #ifdef HAVE_NPN
2989
+ #if HAVE_NPN
2985
2990
/* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */
2986
2991
static int
2987
2992
_advertiseNPN_cb (SSL * s ,
@@ -3024,7 +3029,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
3024
3029
Py_buffer * protos )
3025
3030
/*[clinic end generated code: output=72b002c3324390c6 input=319fcb66abf95bd7]*/
3026
3031
{
3027
- #ifdef HAVE_NPN
3032
+ #if HAVE_NPN
3028
3033
PyMem_Free (self -> npn_protocols );
3029
3034
self -> npn_protocols = PyMem_Malloc (protos -> len );
3030
3035
if (self -> npn_protocols == NULL )
@@ -3049,7 +3054,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
3049
3054
#endif
3050
3055
}
3051
3056
3052
- #ifdef HAVE_ALPN
3057
+ #if HAVE_ALPN
3053
3058
static int
3054
3059
_selectALPN_cb (SSL * s ,
3055
3060
const unsigned char * * out , unsigned char * outlen ,
@@ -3074,7 +3079,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
3074
3079
Py_buffer * protos )
3075
3080
/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/
3076
3081
{
3077
- #ifdef HAVE_ALPN
3082
+ #if HAVE_ALPN
3078
3083
if ((size_t )protos -> len > UINT_MAX ) {
3079
3084
PyErr_Format (PyExc_OverflowError ,
3080
3085
"protocols longer than %d bytes" , UINT_MAX );
@@ -5494,15 +5499,15 @@ PyInit__ssl(void)
5494
5499
Py_INCREF (r );
5495
5500
PyModule_AddObject (m , "HAS_ECDH" , r );
5496
5501
5497
- #ifdef HAVE_NPN
5502
+ #if HAVE_NPN
5498
5503
r = Py_True ;
5499
5504
#else
5500
5505
r = Py_False ;
5501
5506
#endif
5502
5507
Py_INCREF (r );
5503
5508
PyModule_AddObject (m , "HAS_NPN" , r );
5504
5509
5505
- #ifdef HAVE_ALPN
5510
+ #if HAVE_ALPN
5506
5511
r = Py_True ;
5507
5512
#else
5508
5513
r = Py_False ;
0 commit comments