@@ -187,6 +187,11 @@ extern const SSL_METHOD *TLSv1_2_method(void);
187187#endif
188188
189189
190+ #if defined(SSL_VERIFY_POST_HANDSHAKE ) && defined(TLS1_3_VERSION ) && !defined(OPENSSL_NO_TLS1_3 )
191+ #define PySSL_HAVE_POST_HS_AUTH
192+ #endif
193+
194+
190195enum py_ssl_error {
191196 /* these mirror ssl.h */
192197 PY_SSL_ERROR_NONE ,
@@ -231,7 +236,7 @@ enum py_proto_version {
231236 PY_PROTO_TLSv1 = TLS1_VERSION ,
232237 PY_PROTO_TLSv1_1 = TLS1_1_VERSION ,
233238 PY_PROTO_TLSv1_2 = TLS1_2_VERSION ,
234- #ifdef TLS1_3_VERSION
239+ #if defined( TLS1_3_VERSION )
235240 PY_PROTO_TLSv1_3 = TLS1_3_VERSION ,
236241#else
237242 PY_PROTO_TLSv1_3 = 0x304 ,
@@ -293,7 +298,7 @@ typedef struct {
293298 */
294299 unsigned int hostflags ;
295300 int protocol ;
296- #ifdef TLS1_3_VERSION
301+ #if defined( PySSL_HAVE_POST_HS_AUTH )
297302 int post_handshake_auth ;
298303#endif
299304 PyObject * msg_cb ;
@@ -873,7 +878,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
873878 SSL_set_mode (self -> ssl ,
874879 SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | SSL_MODE_AUTO_RETRY );
875880
876- #ifdef TLS1_3_VERSION
881+ #if defined( PySSL_HAVE_POST_HS_AUTH )
877882 if (sslctx -> post_handshake_auth == 1 ) {
878883 if (socket_type == PY_SSL_SERVER ) {
879884 /* bpo-37428: OpenSSL does not ignore SSL_VERIFY_POST_HANDSHAKE.
@@ -1016,6 +1021,7 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self)
10161021 } while (err .ssl == SSL_ERROR_WANT_READ ||
10171022 err .ssl == SSL_ERROR_WANT_WRITE );
10181023 Py_XDECREF (sock );
1024+
10191025 if (ret < 1 )
10201026 return PySSL_SetError (self , __FILE__ , __LINE__ );
10211027 if (PySSL_ChainExceptions (self ) < 0 )
@@ -2775,7 +2781,7 @@ static PyObject *
27752781_ssl__SSLSocket_verify_client_post_handshake_impl (PySSLSocket * self )
27762782/*[clinic end generated code: output=532147f3b1341425 input=6bfa874810a3d889]*/
27772783{
2778- #ifdef TLS1_3_VERSION
2784+ #if defined( PySSL_HAVE_POST_HS_AUTH )
27792785 int err = SSL_verify_client_post_handshake (self -> ssl );
27802786 if (err == 0 )
27812787 return _setSSLError (get_state_sock (self ), NULL , 0 , __FILE__ , __LINE__ );
@@ -3198,7 +3204,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
31983204 X509_VERIFY_PARAM_set_flags (params , X509_V_FLAG_TRUSTED_FIRST );
31993205 X509_VERIFY_PARAM_set_hostflags (params , self -> hostflags );
32003206
3201- #ifdef TLS1_3_VERSION
3207+ #if defined( PySSL_HAVE_POST_HS_AUTH )
32023208 self -> post_handshake_auth = 0 ;
32033209 SSL_CTX_set_post_handshake_auth (self -> ctx , self -> post_handshake_auth );
32043210#endif
@@ -3576,7 +3582,7 @@ set_maximum_version(PySSLContext *self, PyObject *arg, void *c)
35763582 return set_min_max_proto_version (self , arg , 1 );
35773583}
35783584
3579- #ifdef TLS1_3_VERSION
3585+ #if defined( TLS1_3_VERSION ) && !defined( OPENSSL_NO_TLS1_3 )
35803586static PyObject *
35813587get_num_tickets (PySSLContext * self , void * c )
35823588{
@@ -3607,7 +3613,7 @@ set_num_tickets(PySSLContext *self, PyObject *arg, void *c)
36073613
36083614PyDoc_STRVAR (PySSLContext_num_tickets_doc ,
36093615"Control the number of TLSv1.3 session tickets" );
3610- #endif /* TLS1_3_VERSION */
3616+ #endif /* defined( TLS1_3_VERSION) */
36113617
36123618static PyObject *
36133619get_security_level (PySSLContext * self , void * c )
@@ -3710,14 +3716,14 @@ set_check_hostname(PySSLContext *self, PyObject *arg, void *c)
37103716
37113717static PyObject *
37123718get_post_handshake_auth (PySSLContext * self , void * c ) {
3713- #if TLS1_3_VERSION
3719+ #if defined( PySSL_HAVE_POST_HS_AUTH )
37143720 return PyBool_FromLong (self -> post_handshake_auth );
37153721#else
37163722 Py_RETURN_NONE ;
37173723#endif
37183724}
37193725
3720- #if TLS1_3_VERSION
3726+ #if defined( PySSL_HAVE_POST_HS_AUTH )
37213727static int
37223728set_post_handshake_auth (PySSLContext * self , PyObject * arg , void * c ) {
37233729 if (arg == NULL ) {
@@ -4959,14 +4965,14 @@ static PyGetSetDef context_getsetlist[] = {
49594965 (setter ) _PySSLContext_set_msg_callback , NULL },
49604966 {"sni_callback" , (getter ) get_sni_callback ,
49614967 (setter ) set_sni_callback , PySSLContext_sni_callback_doc },
4962- #ifdef TLS1_3_VERSION
4968+ #if defined( TLS1_3_VERSION ) && ! defined ( OPENSSL_NO_TLS1_3 )
49634969 {"num_tickets" , (getter ) get_num_tickets ,
49644970 (setter ) set_num_tickets , PySSLContext_num_tickets_doc },
49654971#endif
49664972 {"options" , (getter ) get_options ,
49674973 (setter ) set_options , NULL },
49684974 {"post_handshake_auth" , (getter ) get_post_handshake_auth ,
4969- #ifdef TLS1_3_VERSION
4975+ #if defined( PySSL_HAVE_POST_HS_AUTH )
49704976 (setter ) set_post_handshake_auth ,
49714977#else
49724978 NULL ,
0 commit comments