@@ -293,10 +293,6 @@ typedef struct {
293293 unsigned int alpn_protocols_len ;
294294 PyObject * set_sni_cb ;
295295 int check_hostname ;
296- /* OpenSSL has no API to get hostflags from X509_VERIFY_PARAM* struct.
297- * We have to maintain our own copy. OpenSSL's hostflags default to 0.
298- */
299- unsigned int hostflags ;
300296 int protocol ;
301297#if defined(PySSL_HAVE_POST_HS_AUTH )
302298 int post_handshake_auth ;
@@ -824,15 +820,15 @@ _ssl_configure_hostname(PySSLSocket *self, const char* server_hostname)
824820 }
825821 }
826822 if (self -> ctx -> check_hostname ) {
827- X509_VERIFY_PARAM * param = SSL_get0_param (self -> ssl );
823+ X509_VERIFY_PARAM * ssl_verification_params = SSL_get0_param (self -> ssl );
828824 if (ip == NULL ) {
829- if (!X509_VERIFY_PARAM_set1_host (param , server_hostname ,
825+ if (!X509_VERIFY_PARAM_set1_host (ssl_verification_params , server_hostname ,
830826 strlen (server_hostname ))) {
831827 _setSSLError (get_state_sock (self ), NULL , 0 , __FILE__ , __LINE__ );
832828 goto error ;
833829 }
834830 } else {
835- if (!X509_VERIFY_PARAM_set1_ip (param , ASN1_STRING_get0_data (ip ),
831+ if (!X509_VERIFY_PARAM_set1_ip (ssl_verification_params , ASN1_STRING_get0_data (ip ),
836832 ASN1_STRING_length (ip ))) {
837833 _setSSLError (get_state_sock (self ), NULL , 0 , __FILE__ , __LINE__ );
838834 goto error ;
@@ -909,8 +905,11 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
909905
910906 /* bpo43522 and OpenSSL < 1.1.1l: copy hostflags manually */
911907#if OPENSSL_VERSION < 0x101010cf
912- X509_VERIFY_PARAM * ssl_params = SSL_get0_param (self -> ssl );
913- X509_VERIFY_PARAM_set_hostflags (ssl_params , sslctx -> hostflags );
908+ X509_VERIFY_PARAM * ssl_verification_params = SSL_get0_param (self -> ssl );
909+ X509_VERIFY_PARAM * ssl_ctx_verification_params = SSL_CTX_get0_param (ctx );
910+
911+ unsigned int ssl_ctx_host_flags = X509_VERIFY_PARAM_get_hostflags (ssl_ctx_verification_params );
912+ X509_VERIFY_PARAM_set_hostflags (ssl_verification_params , ssl_ctx_host_flags );
914913#endif
915914 SSL_set_app_data (self -> ssl , self );
916915 if (sock ) {
@@ -3097,7 +3096,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
30973096 uint64_t options ;
30983097 const SSL_METHOD * method = NULL ;
30993098 SSL_CTX * ctx = NULL ;
3100- X509_VERIFY_PARAM * params ;
3099+ X509_VERIFY_PARAM * ssl_verification_params ;
31013100 int result ;
31023101
31033102 /* slower approach, walk MRO and get borrowed reference to module.
@@ -3181,7 +3180,6 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
31813180 return NULL ;
31823181 }
31833182 self -> ctx = ctx ;
3184- self -> hostflags = X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS ;
31853183 self -> protocol = proto_version ;
31863184 self -> msg_cb = NULL ;
31873185 self -> keylog_filename = NULL ;
@@ -3271,11 +3269,11 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
32713269 usage for no cost at all. */
32723270 SSL_CTX_set_mode (self -> ctx , SSL_MODE_RELEASE_BUFFERS );
32733271
3274- params = SSL_CTX_get0_param (self -> ctx );
3272+ ssl_verification_params = SSL_CTX_get0_param (self -> ctx );
32753273 /* Improve trust chain building when cross-signed intermediate
32763274 certificates are present. See https://bugs.python.org/issue23476. */
3277- X509_VERIFY_PARAM_set_flags (params , X509_V_FLAG_TRUSTED_FIRST );
3278- X509_VERIFY_PARAM_set_hostflags (params , self -> hostflags );
3275+ X509_VERIFY_PARAM_set_flags (ssl_verification_params , X509_V_FLAG_TRUSTED_FIRST );
3276+ X509_VERIFY_PARAM_set_hostflags (ssl_verification_params , X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS );
32793277
32803278#if defined(PySSL_HAVE_POST_HS_AUTH )
32813279 self -> post_handshake_auth = 0 ;
@@ -3530,11 +3528,11 @@ static PyObject *
35303528_ssl__SSLContext_verify_flags_get_impl (PySSLContext * self )
35313529/*[clinic end generated code: output=fbbf8ba28ad6e56e input=c1ec36d610b3f391]*/
35323530{
3533- X509_VERIFY_PARAM * param ;
3531+ X509_VERIFY_PARAM * ssl_verification_params ;
35343532 unsigned long flags ;
35353533
3536- param = SSL_CTX_get0_param (self -> ctx );
3537- flags = X509_VERIFY_PARAM_get_flags (param );
3534+ ssl_verification_params = SSL_CTX_get0_param (self -> ctx );
3535+ flags = X509_VERIFY_PARAM_get_flags (ssl_verification_params );
35383536 return PyLong_FromUnsignedLong (flags );
35393537}
35403538
@@ -3548,23 +3546,23 @@ static int
35483546_ssl__SSLContext_verify_flags_set_impl (PySSLContext * self , PyObject * value )
35493547/*[clinic end generated code: output=a3e3b2a0ce6c2e99 input=b2a0c42583d4f34e]*/
35503548{
3551- X509_VERIFY_PARAM * param ;
3549+ X509_VERIFY_PARAM * ssl_verification_params ;
35523550 unsigned long new_flags , flags , set , clear ;
35533551
35543552 if (!PyArg_Parse (value , "k" , & new_flags ))
35553553 return -1 ;
3556- param = SSL_CTX_get0_param (self -> ctx );
3557- flags = X509_VERIFY_PARAM_get_flags (param );
3554+ ssl_verification_params = SSL_CTX_get0_param (self -> ctx );
3555+ flags = X509_VERIFY_PARAM_get_flags (ssl_verification_params );
35583556 clear = flags & ~new_flags ;
35593557 set = ~flags & new_flags ;
35603558 if (clear ) {
3561- if (!X509_VERIFY_PARAM_clear_flags (param , clear )) {
3559+ if (!X509_VERIFY_PARAM_clear_flags (ssl_verification_params , clear )) {
35623560 _setSSLError (get_state_ctx (self ), NULL , 0 , __FILE__ , __LINE__ );
35633561 return -1 ;
35643562 }
35653563 }
35663564 if (set ) {
3567- if (!X509_VERIFY_PARAM_set_flags (param , set )) {
3565+ if (!X509_VERIFY_PARAM_set_flags (ssl_verification_params , set )) {
35683566 _setSSLError (get_state_ctx (self ), NULL , 0 , __FILE__ , __LINE__ );
35693567 return -1 ;
35703568 }
@@ -3859,7 +3857,12 @@ static PyObject *
38593857_ssl__SSLContext__host_flags_get_impl (PySSLContext * self )
38603858/*[clinic end generated code: output=0f9db6654ce32582 input=8e3c49499eefd0e5]*/
38613859{
3862- return PyLong_FromUnsignedLong (self -> hostflags );
3860+ X509_VERIFY_PARAM * ssl_verification_params ;
3861+ unsigned int host_flags ;
3862+
3863+ ssl_verification_params = SSL_CTX_get0_param (self -> ctx );
3864+ host_flags = X509_VERIFY_PARAM_get_hostflags (ssl_verification_params );
3865+ return PyLong_FromUnsignedLong (host_flags );
38633866}
38643867
38653868/*[clinic input]
@@ -3872,15 +3875,14 @@ static int
38723875_ssl__SSLContext__host_flags_set_impl (PySSLContext * self , PyObject * value )
38733876/*[clinic end generated code: output=1ed6f4027aaf2e3e input=28caf1fb9c32f6cb]*/
38743877{
3875- X509_VERIFY_PARAM * param ;
3878+ X509_VERIFY_PARAM * ssl_verification_params ;
38763879 unsigned int new_flags = 0 ;
38773880
38783881 if (!PyArg_Parse (value , "I" , & new_flags ))
38793882 return -1 ;
38803883
3881- param = SSL_CTX_get0_param (self -> ctx );
3882- self -> hostflags = new_flags ;
3883- X509_VERIFY_PARAM_set_hostflags (param , new_flags );
3884+ ssl_verification_params = SSL_CTX_get0_param (self -> ctx );
3885+ X509_VERIFY_PARAM_set_hostflags (ssl_verification_params , new_flags );
38843886 return 0 ;
38853887}
38863888
0 commit comments