@@ -157,21 +157,26 @@ static void _PySSLFixErrno(void) {
157
157
#endif
158
158
159
159
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
160
- # define HAVE_ALPN
160
+ # define HAVE_ALPN 1
161
+ #else
162
+ # define HAVE_ALPN 0
161
163
#endif
162
164
163
165
/* We cannot rely on OPENSSL_NO_NEXTPROTONEG because LibreSSL 2.6.1 dropped
164
166
* NPN support but did not set OPENSSL_NO_NEXTPROTONEG for compatibility
165
167
* reasons. The check for TLSEXT_TYPE_next_proto_neg works with
166
168
* OpenSSL 1.0.1+ and LibreSSL.
169
+ * OpenSSL 1.1.1-pre1 dropped NPN but still has TLSEXT_TYPE_next_proto_neg.
167
170
*/
168
171
#ifdef OPENSSL_NO_NEXTPROTONEG
169
- # define HAVE_NPN 0
172
+ # define HAVE_NPN 0
173
+ #elif (OPENSSL_VERSION_NUMBER >= 0x10101000L ) && !defined(LIBRESSL_VERSION_NUMBER )
174
+ # define HAVE_NPN 0
170
175
#elif defined(TLSEXT_TYPE_next_proto_neg )
171
- # define HAVE_NPN 1
176
+ # define HAVE_NPN 1
172
177
#else
173
- # define HAVE_NPN 0
174
- # endif
178
+ # define HAVE_NPN 0
179
+ #endif
175
180
176
181
#ifndef INVALID_SOCKET /* MS defines this */
177
182
#define INVALID_SOCKET (-1)
@@ -341,11 +346,11 @@ static unsigned int _ssl_locks_count = 0;
341
346
typedef struct {
342
347
PyObject_HEAD
343
348
SSL_CTX * ctx ;
344
- #ifdef HAVE_NPN
349
+ #if HAVE_NPN
345
350
unsigned char * npn_protocols ;
346
351
int npn_protocols_len ;
347
352
#endif
348
- #ifdef HAVE_ALPN
353
+ #if HAVE_ALPN
349
354
unsigned char * alpn_protocols ;
350
355
unsigned int alpn_protocols_len ;
351
356
#endif
@@ -1922,7 +1927,7 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self)
1922
1927
return PyUnicode_FromString (version );
1923
1928
}
1924
1929
1925
- #ifdef HAVE_NPN
1930
+ #if HAVE_NPN
1926
1931
/*[clinic input]
1927
1932
_ssl._SSLSocket.selected_npn_protocol
1928
1933
[clinic start generated code]*/
@@ -1943,7 +1948,7 @@ _ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self)
1943
1948
}
1944
1949
#endif
1945
1950
1946
- #ifdef HAVE_ALPN
1951
+ #if HAVE_ALPN
1947
1952
/*[clinic input]
1948
1953
_ssl._SSLSocket.selected_alpn_protocol
1949
1954
[clinic start generated code]*/
@@ -2887,10 +2892,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
2887
2892
self -> ctx = ctx ;
2888
2893
self -> hostflags = X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS ;
2889
2894
self -> protocol = proto_version ;
2890
- #ifdef HAVE_NPN
2895
+ #if HAVE_NPN
2891
2896
self -> npn_protocols = NULL ;
2892
2897
#endif
2893
- #ifdef HAVE_ALPN
2898
+ #if HAVE_ALPN
2894
2899
self -> alpn_protocols = NULL ;
2895
2900
#endif
2896
2901
#ifndef OPENSSL_NO_TLSEXT
@@ -3026,10 +3031,10 @@ context_dealloc(PySSLContext *self)
3026
3031
PyObject_GC_UnTrack (self );
3027
3032
context_clear (self );
3028
3033
SSL_CTX_free (self -> ctx );
3029
- #ifdef HAVE_NPN
3034
+ #if HAVE_NPN
3030
3035
PyMem_FREE (self -> npn_protocols );
3031
3036
#endif
3032
- #ifdef HAVE_ALPN
3037
+ #if HAVE_ALPN
3033
3038
PyMem_FREE (self -> alpn_protocols );
3034
3039
#endif
3035
3040
Py_TYPE (self )-> tp_free (self );
@@ -3104,7 +3109,7 @@ _ssl__SSLContext_get_ciphers_impl(PySSLContext *self)
3104
3109
#endif
3105
3110
3106
3111
3107
- #if defined( HAVE_NPN ) || defined( HAVE_ALPN )
3112
+ #if HAVE_NPN || HAVE_ALPN
3108
3113
static int
3109
3114
do_protocol_selection (int alpn , unsigned char * * out , unsigned char * outlen ,
3110
3115
const unsigned char * server_protocols , unsigned int server_protocols_len ,
@@ -3130,7 +3135,7 @@ do_protocol_selection(int alpn, unsigned char **out, unsigned char *outlen,
3130
3135
}
3131
3136
#endif
3132
3137
3133
- #ifdef HAVE_NPN
3138
+ #if HAVE_NPN
3134
3139
/* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */
3135
3140
static int
3136
3141
_advertiseNPN_cb (SSL * s ,
@@ -3173,7 +3178,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
3173
3178
Py_buffer * protos )
3174
3179
/*[clinic end generated code: output=72b002c3324390c6 input=319fcb66abf95bd7]*/
3175
3180
{
3176
- #ifdef HAVE_NPN
3181
+ #if HAVE_NPN
3177
3182
PyMem_Free (self -> npn_protocols );
3178
3183
self -> npn_protocols = PyMem_Malloc (protos -> len );
3179
3184
if (self -> npn_protocols == NULL )
@@ -3198,7 +3203,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
3198
3203
#endif
3199
3204
}
3200
3205
3201
- #ifdef HAVE_ALPN
3206
+ #if HAVE_ALPN
3202
3207
static int
3203
3208
_selectALPN_cb (SSL * s ,
3204
3209
const unsigned char * * out , unsigned char * outlen ,
@@ -3223,7 +3228,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
3223
3228
Py_buffer * protos )
3224
3229
/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/
3225
3230
{
3226
- #ifdef HAVE_ALPN
3231
+ #if HAVE_ALPN
3227
3232
if ((size_t )protos -> len > UINT_MAX ) {
3228
3233
PyErr_Format (PyExc_OverflowError ,
3229
3234
"protocols longer than %d bytes" , UINT_MAX );
@@ -5718,15 +5723,15 @@ PyInit__ssl(void)
5718
5723
Py_INCREF (r );
5719
5724
PyModule_AddObject (m , "HAS_ECDH" , r );
5720
5725
5721
- #ifdef HAVE_NPN
5726
+ #if HAVE_NPN
5722
5727
r = Py_True ;
5723
5728
#else
5724
5729
r = Py_False ;
5725
5730
#endif
5726
5731
Py_INCREF (r );
5727
5732
PyModule_AddObject (m , "HAS_NPN" , r );
5728
5733
5729
- #ifdef HAVE_ALPN
5734
+ #if HAVE_ALPN
5730
5735
r = Py_True ;
5731
5736
#else
5732
5737
r = Py_False ;
0 commit comments