| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 48dfd74 commit e413daf
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -908,6 +908,12 @@ Constants | |||
| 908 | 908 | ||
| 909 | 909 | .. versionadded:: 3.7 | |
| 910 | 910 | ||
| 911 | + .. data:: HAS_PSK | ||
| 912 | + | ||
| 913 | + Whether the OpenSSL library has built-in support for TLS-PSK. | ||
| 914 | + | ||
| 915 | + .. versionadded:: 3.13 | ||
| 916 | + | ||
| 911 | 917 | .. data:: CHANNEL_BINDING_TYPES | |
| 912 | 918 | ||
| 913 | 919 | List of supported TLS channel binding types. Strings in this list | |
@@ -2050,6 +2056,9 @@ to speed up repeated connections from the same clients. | |||
| 2050 | 2056 | return 'ClientId_1', psk_table.get(hint, b'') | |
| 2051 | 2057 | context.set_psk_client_callback(callback) | |
| 2052 | 2058 | ||
| 2059 | + This method will raise :exc:`NotImplementedError` if :data:`HAS_PSK` is | ||
| 2060 | + ``False``. | ||
| 2061 | + | ||
| 2053 | 2062 | .. versionadded:: 3.13 | |
| 2054 | 2063 | ||
| 2055 | 2064 | .. method:: SSLContext.set_psk_server_callback(callback, identity_hint=None) | |
@@ -2092,6 +2101,9 @@ to speed up repeated connections from the same clients. | |||
| 2092 | 2101 | return psk_table.get(identity, b'') | |
| 2093 | 2102 | context.set_psk_server_callback(callback, 'ServerId_1') | |
| 2094 | 2103 | ||
| 2104 | + This method will raise :exc:`NotImplementedError` if :data:`HAS_PSK` is | ||
| 2105 | + ``False``. | ||
| 2106 | + | ||
| 2095 | 2107 | .. versionadded:: 3.13 | |
| 2096 | 2108 | ||
| 2097 | 2109 | .. index:: single: certificates | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,7 +116,7 @@ | |||
| 116 | 116 | ||
| 117 | 117 | from _ssl import ( | |
| 118 | 118 | HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, | |
| 119 | - HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3 | ||
| 119 | + HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK | ||
| 120 | 120 | ) | |
| 121 | 121 | from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION | |
| 122 | 122 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4259,6 +4259,7 @@ def test_session_handling(self): | |||
| 4259 | 4259 | 'Session refers to a different SSLContext.') | |
| 4260 | 4260 | ||
| 4261 | 4261 | @requires_tls_version('TLSv1_2') | |
| 4262 | + @unittest.skipUnless(ssl.HAS_PSK, 'TLS-PSK disabled on this OpenSSL build') | ||
| 4262 | 4263 | def test_psk(self): | |
| 4263 | 4264 | psk = bytes.fromhex('deadbeef') | |
| 4264 | 4265 | ||
@@ -4326,6 +4327,7 @@ def server_callback(identity): | |||
| 4326 | 4327 | s.connect((HOST, server.port)) | |
| 4327 | 4328 | ||
| 4328 | 4329 | @requires_tls_version('TLSv1_3') | |
| 4330 | + @unittest.skipUnless(ssl.HAS_PSK, 'TLS-PSK disabled on this OpenSSL build') | ||
| 4329 | 4331 | def test_psk_tls1_3(self): | |
| 4330 | 4332 | psk = bytes.fromhex('deadbeef') | |
| 4331 | 4333 | identity_hint = 'identity-hint' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments