@@ -157,21 +157,26 @@ static void _PySSLFixErrno(void) {
157157#endif
158158
159159#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
160- # define HAVE_ALPN
160+ # define HAVE_ALPN 1
161+ #else
162+ # define HAVE_ALPN 0
161163#endif
162164
163165/* We cannot rely on OPENSSL_NO_NEXTPROTONEG because LibreSSL 2.6.1 dropped
164166 * NPN support but did not set OPENSSL_NO_NEXTPROTONEG for compatibility
165167 * reasons. The check for TLSEXT_TYPE_next_proto_neg works with
166168 * OpenSSL 1.0.1+ and LibreSSL.
169+ * OpenSSL 1.1.1-pre1 dropped NPN but still has TLSEXT_TYPE_next_proto_neg.
167170 */
168171#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
170175#elif defined(TLSEXT_TYPE_next_proto_neg )
171- # define HAVE_NPN 1
176+ # define HAVE_NPN 1
172177#else
173- # define HAVE_NPN 0
174- # endif
178+ # define HAVE_NPN 0
179+ #endif
175180
176181#ifndef INVALID_SOCKET /* MS defines this */
177182#define INVALID_SOCKET (-1)
@@ -341,11 +346,11 @@ static unsigned int _ssl_locks_count = 0;
341346typedef struct {
342347 PyObject_HEAD
343348 SSL_CTX * ctx ;
344- #ifdef HAVE_NPN
349+ #if HAVE_NPN
345350 unsigned char * npn_protocols ;
346351 int npn_protocols_len ;
347352#endif
348- #ifdef HAVE_ALPN
353+ #if HAVE_ALPN
349354 unsigned char * alpn_protocols ;
350355 unsigned int alpn_protocols_len ;
351356#endif
@@ -1922,7 +1927,7 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self)
19221927 return PyUnicode_FromString (version );
19231928}
19241929
1925- #ifdef HAVE_NPN
1930+ #if HAVE_NPN
19261931/*[clinic input]
19271932_ssl._SSLSocket.selected_npn_protocol
19281933[clinic start generated code]*/
@@ -1943,7 +1948,7 @@ _ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self)
19431948}
19441949#endif
19451950
1946- #ifdef HAVE_ALPN
1951+ #if HAVE_ALPN
19471952/*[clinic input]
19481953_ssl._SSLSocket.selected_alpn_protocol
19491954[clinic start generated code]*/
@@ -2887,10 +2892,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
28872892 self -> ctx = ctx ;
28882893 self -> hostflags = X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS ;
28892894 self -> protocol = proto_version ;
2890- #ifdef HAVE_NPN
2895+ #if HAVE_NPN
28912896 self -> npn_protocols = NULL ;
28922897#endif
2893- #ifdef HAVE_ALPN
2898+ #if HAVE_ALPN
28942899 self -> alpn_protocols = NULL ;
28952900#endif
28962901#ifndef OPENSSL_NO_TLSEXT
@@ -3026,10 +3031,10 @@ context_dealloc(PySSLContext *self)
30263031 PyObject_GC_UnTrack (self );
30273032 context_clear (self );
30283033 SSL_CTX_free (self -> ctx );
3029- #ifdef HAVE_NPN
3034+ #if HAVE_NPN
30303035 PyMem_FREE (self -> npn_protocols );
30313036#endif
3032- #ifdef HAVE_ALPN
3037+ #if HAVE_ALPN
30333038 PyMem_FREE (self -> alpn_protocols );
30343039#endif
30353040 Py_TYPE (self )-> tp_free (self );
@@ -3104,7 +3109,7 @@ _ssl__SSLContext_get_ciphers_impl(PySSLContext *self)
31043109#endif
31053110
31063111
3107- #if defined( HAVE_NPN ) || defined( HAVE_ALPN )
3112+ #if HAVE_NPN || HAVE_ALPN
31083113static int
31093114do_protocol_selection (int alpn , unsigned char * * out , unsigned char * outlen ,
31103115 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,
31303135}
31313136#endif
31323137
3133- #ifdef HAVE_NPN
3138+ #if HAVE_NPN
31343139/* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */
31353140static int
31363141_advertiseNPN_cb (SSL * s ,
@@ -3173,7 +3178,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
31733178 Py_buffer * protos )
31743179/*[clinic end generated code: output=72b002c3324390c6 input=319fcb66abf95bd7]*/
31753180{
3176- #ifdef HAVE_NPN
3181+ #if HAVE_NPN
31773182 PyMem_Free (self -> npn_protocols );
31783183 self -> npn_protocols = PyMem_Malloc (protos -> len );
31793184 if (self -> npn_protocols == NULL )
@@ -3198,7 +3203,7 @@ _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
31983203#endif
31993204}
32003205
3201- #ifdef HAVE_ALPN
3206+ #if HAVE_ALPN
32023207static int
32033208_selectALPN_cb (SSL * s ,
32043209 const unsigned char * * out , unsigned char * outlen ,
@@ -3223,7 +3228,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
32233228 Py_buffer * protos )
32243229/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/
32253230{
3226- #ifdef HAVE_ALPN
3231+ #if HAVE_ALPN
32273232 if ((size_t )protos -> len > UINT_MAX ) {
32283233 PyErr_Format (PyExc_OverflowError ,
32293234 "protocols longer than %d bytes" , UINT_MAX );
@@ -5718,15 +5723,15 @@ PyInit__ssl(void)
57185723 Py_INCREF (r );
57195724 PyModule_AddObject (m , "HAS_ECDH" , r );
57205725
5721- #ifdef HAVE_NPN
5726+ #if HAVE_NPN
57225727 r = Py_True ;
57235728#else
57245729 r = Py_False ;
57255730#endif
57265731 Py_INCREF (r );
57275732 PyModule_AddObject (m , "HAS_NPN" , r );
57285733
5729- #ifdef HAVE_ALPN
5734+ #if HAVE_ALPN
57305735 r = Py_True ;
57315736#else
57325737 r = Py_False ;
0 commit comments