@@ -187,6 +187,11 @@ extern const SSL_METHOD *TLSv1_2_method(void);
187
187
#endif
188
188
189
189
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
+
190
195
enum py_ssl_error {
191
196
/* these mirror ssl.h */
192
197
PY_SSL_ERROR_NONE ,
@@ -231,7 +236,7 @@ enum py_proto_version {
231
236
PY_PROTO_TLSv1 = TLS1_VERSION ,
232
237
PY_PROTO_TLSv1_1 = TLS1_1_VERSION ,
233
238
PY_PROTO_TLSv1_2 = TLS1_2_VERSION ,
234
- #ifdef TLS1_3_VERSION
239
+ #if defined( TLS1_3_VERSION )
235
240
PY_PROTO_TLSv1_3 = TLS1_3_VERSION ,
236
241
#else
237
242
PY_PROTO_TLSv1_3 = 0x304 ,
@@ -293,7 +298,7 @@ typedef struct {
293
298
*/
294
299
unsigned int hostflags ;
295
300
int protocol ;
296
- #ifdef TLS1_3_VERSION
301
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
297
302
int post_handshake_auth ;
298
303
#endif
299
304
PyObject * msg_cb ;
@@ -873,7 +878,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
873
878
SSL_set_mode (self -> ssl ,
874
879
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | SSL_MODE_AUTO_RETRY );
875
880
876
- #ifdef TLS1_3_VERSION
881
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
877
882
if (sslctx -> post_handshake_auth == 1 ) {
878
883
if (socket_type == PY_SSL_SERVER ) {
879
884
/* bpo-37428: OpenSSL does not ignore SSL_VERIFY_POST_HANDSHAKE.
@@ -1016,6 +1021,7 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self)
1016
1021
} while (err .ssl == SSL_ERROR_WANT_READ ||
1017
1022
err .ssl == SSL_ERROR_WANT_WRITE );
1018
1023
Py_XDECREF (sock );
1024
+
1019
1025
if (ret < 1 )
1020
1026
return PySSL_SetError (self , __FILE__ , __LINE__ );
1021
1027
if (PySSL_ChainExceptions (self ) < 0 )
@@ -2775,7 +2781,7 @@ static PyObject *
2775
2781
_ssl__SSLSocket_verify_client_post_handshake_impl (PySSLSocket * self )
2776
2782
/*[clinic end generated code: output=532147f3b1341425 input=6bfa874810a3d889]*/
2777
2783
{
2778
- #ifdef TLS1_3_VERSION
2784
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
2779
2785
int err = SSL_verify_client_post_handshake (self -> ssl );
2780
2786
if (err == 0 )
2781
2787
return _setSSLError (get_state_sock (self ), NULL , 0 , __FILE__ , __LINE__ );
@@ -3198,7 +3204,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
3198
3204
X509_VERIFY_PARAM_set_flags (params , X509_V_FLAG_TRUSTED_FIRST );
3199
3205
X509_VERIFY_PARAM_set_hostflags (params , self -> hostflags );
3200
3206
3201
- #ifdef TLS1_3_VERSION
3207
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
3202
3208
self -> post_handshake_auth = 0 ;
3203
3209
SSL_CTX_set_post_handshake_auth (self -> ctx , self -> post_handshake_auth );
3204
3210
#endif
@@ -3576,7 +3582,7 @@ set_maximum_version(PySSLContext *self, PyObject *arg, void *c)
3576
3582
return set_min_max_proto_version (self , arg , 1 );
3577
3583
}
3578
3584
3579
- #ifdef TLS1_3_VERSION
3585
+ #if defined( TLS1_3_VERSION ) && !defined( OPENSSL_NO_TLS1_3 )
3580
3586
static PyObject *
3581
3587
get_num_tickets (PySSLContext * self , void * c )
3582
3588
{
@@ -3607,7 +3613,7 @@ set_num_tickets(PySSLContext *self, PyObject *arg, void *c)
3607
3613
3608
3614
PyDoc_STRVAR (PySSLContext_num_tickets_doc ,
3609
3615
"Control the number of TLSv1.3 session tickets" );
3610
- #endif /* TLS1_3_VERSION */
3616
+ #endif /* defined( TLS1_3_VERSION) */
3611
3617
3612
3618
static PyObject *
3613
3619
get_security_level (PySSLContext * self , void * c )
@@ -3710,14 +3716,14 @@ set_check_hostname(PySSLContext *self, PyObject *arg, void *c)
3710
3716
3711
3717
static PyObject *
3712
3718
get_post_handshake_auth (PySSLContext * self , void * c ) {
3713
- #if TLS1_3_VERSION
3719
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
3714
3720
return PyBool_FromLong (self -> post_handshake_auth );
3715
3721
#else
3716
3722
Py_RETURN_NONE ;
3717
3723
#endif
3718
3724
}
3719
3725
3720
- #if TLS1_3_VERSION
3726
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
3721
3727
static int
3722
3728
set_post_handshake_auth (PySSLContext * self , PyObject * arg , void * c ) {
3723
3729
if (arg == NULL ) {
@@ -4959,14 +4965,14 @@ static PyGetSetDef context_getsetlist[] = {
4959
4965
(setter ) _PySSLContext_set_msg_callback , NULL },
4960
4966
{"sni_callback" , (getter ) get_sni_callback ,
4961
4967
(setter ) set_sni_callback , PySSLContext_sni_callback_doc },
4962
- #ifdef TLS1_3_VERSION
4968
+ #if defined( TLS1_3_VERSION ) && ! defined ( OPENSSL_NO_TLS1_3 )
4963
4969
{"num_tickets" , (getter ) get_num_tickets ,
4964
4970
(setter ) set_num_tickets , PySSLContext_num_tickets_doc },
4965
4971
#endif
4966
4972
{"options" , (getter ) get_options ,
4967
4973
(setter ) set_options , NULL },
4968
4974
{"post_handshake_auth" , (getter ) get_post_handshake_auth ,
4969
- #ifdef TLS1_3_VERSION
4975
+ #if defined( PySSL_HAVE_POST_HS_AUTH )
4970
4976
(setter ) set_post_handshake_auth ,
4971
4977
#else
4972
4978
NULL ,
0 commit comments