@@ -301,8 +301,10 @@ typedef struct {
301
301
BIO * keylog_bio ;
302
302
/* Cached module state, also used in SSLSocket and SSLSession code. */
303
303
_sslmodulestate * state ;
304
+ #ifndef OPENSSL_NO_PSK
304
305
PyObject * psk_client_callback ;
305
306
PyObject * psk_server_callback ;
307
+ #endif
306
308
} PySSLContext ;
307
309
308
310
typedef struct {
@@ -3125,8 +3127,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
3125
3127
self -> alpn_protocols = NULL ;
3126
3128
self -> set_sni_cb = NULL ;
3127
3129
self -> state = get_ssl_state (module );
3130
+ #ifndef OPENSSL_NO_PSK
3128
3131
self -> psk_client_callback = NULL ;
3129
3132
self -> psk_server_callback = NULL ;
3133
+ #endif
3130
3134
3131
3135
/* Don't check host name by default */
3132
3136
if (proto_version == PY_SSL_VERSION_TLS_CLIENT ) {
@@ -3239,8 +3243,10 @@ context_clear(PySSLContext *self)
3239
3243
Py_CLEAR (self -> set_sni_cb );
3240
3244
Py_CLEAR (self -> msg_cb );
3241
3245
Py_CLEAR (self -> keylog_filename );
3246
+ #ifndef OPENSSL_NO_PSK
3242
3247
Py_CLEAR (self -> psk_client_callback );
3243
3248
Py_CLEAR (self -> psk_server_callback );
3249
+ #endif
3244
3250
if (self -> keylog_bio != NULL ) {
3245
3251
PySSL_BEGIN_ALLOW_THREADS
3246
3252
BIO_free_all (self -> keylog_bio );
@@ -4668,6 +4674,7 @@ _ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form)
4668
4674
return NULL ;
4669
4675
}
4670
4676
4677
+ #ifndef OPENSSL_NO_PSK
4671
4678
static unsigned int psk_client_callback (SSL * s ,
4672
4679
const char * hint ,
4673
4680
char * identity ,
@@ -4735,6 +4742,7 @@ static unsigned int psk_client_callback(SSL *s,
4735
4742
PyGILState_Release (gstate );
4736
4743
return 0 ;
4737
4744
}
4745
+ #endif
4738
4746
4739
4747
/*[clinic input]
4740
4748
_ssl._SSLContext.set_psk_client_callback
@@ -4747,6 +4755,7 @@ _ssl__SSLContext_set_psk_client_callback_impl(PySSLContext *self,
4747
4755
PyObject * callback )
4748
4756
/*[clinic end generated code: output=0aba86f6ed75119e input=7627bae0e5ee7635]*/
4749
4757
{
4758
+ #ifndef OPENSSL_NO_PSK
4750
4759
if (self -> protocol == PY_SSL_VERSION_TLS_SERVER ) {
4751
4760
_setSSLError (get_state_ctx (self ),
4752
4761
"Cannot add PSK client callback to a "
@@ -4774,8 +4783,14 @@ _ssl__SSLContext_set_psk_client_callback_impl(PySSLContext *self,
4774
4783
SSL_CTX_set_psk_client_callback (self -> ctx , ssl_callback );
4775
4784
4776
4785
Py_RETURN_NONE ;
4786
+ #else
4787
+ PyErr_SetString (PyExc_NotImplementedError ,
4788
+ "TLS-PSK is not supported by your OpenSSL version." );
4789
+ return NULL ;
4790
+ #endif
4777
4791
}
4778
4792
4793
+ #ifndef OPENSSL_NO_PSK
4779
4794
static unsigned int psk_server_callback (SSL * s ,
4780
4795
const char * identity ,
4781
4796
unsigned char * psk ,
@@ -4835,6 +4850,7 @@ static unsigned int psk_server_callback(SSL *s,
4835
4850
PyGILState_Release (gstate );
4836
4851
return 0 ;
4837
4852
}
4853
+ #endif
4838
4854
4839
4855
/*[clinic input]
4840
4856
_ssl._SSLContext.set_psk_server_callback
@@ -4849,6 +4865,7 @@ _ssl__SSLContext_set_psk_server_callback_impl(PySSLContext *self,
4849
4865
const char * identity_hint )
4850
4866
/*[clinic end generated code: output=1f4d6a4e09a92b03 input=65d4b6022aa85ea3]*/
4851
4867
{
4868
+ #ifndef OPENSSL_NO_PSK
4852
4869
if (self -> protocol == PY_SSL_VERSION_TLS_CLIENT ) {
4853
4870
_setSSLError (get_state_ctx (self ),
4854
4871
"Cannot add PSK server callback to a "
@@ -4882,6 +4899,11 @@ _ssl__SSLContext_set_psk_server_callback_impl(PySSLContext *self,
4882
4899
SSL_CTX_set_psk_server_callback (self -> ctx , ssl_callback );
4883
4900
4884
4901
Py_RETURN_NONE ;
4902
+ #else
4903
+ PyErr_SetString (PyExc_NotImplementedError ,
4904
+ "TLS-PSK is not supported by your OpenSSL version." );
4905
+ return NULL ;
4906
+ #endif
4885
4907
}
4886
4908
4887
4909
@@ -6243,6 +6265,12 @@ sslmodule_init_constants(PyObject *m)
6243
6265
addbool (m , "HAS_TLSv1_3" , 0 );
6244
6266
#endif
6245
6267
6268
+ #ifdef OPENSSL_NO_PSK
6269
+ addbool (m , "HAS_PSK" , 0 );
6270
+ #else
6271
+ addbool (m , "HAS_PSK" , 1 );
6272
+ #endif
6273
+
6246
6274
#undef addbool
6247
6275
#undef ADD_INT_CONST
6248
6276
0 commit comments