Skip to content

Commit 21d98be

Browse files
authored
gh-105293: Do not call SSL_CTX_set_session_id_context on client side SSL context (#105295)
* gh-105293: Do not call SSL_CTX_set_session_id_context on client side SSL context Openssl states this is a "server side only" operation. Calling this on a client side socket can result in unexpected behavior * Add news entry on SSL "set session id context" changes
1 parent 490295d commit 21d98be

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove call to ``SSL_CTX_set_session_id_context`` during client side context
2+
creation in the :mod:`ssl` module.

Modules/_ssl.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,15 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
847847
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
848848
return NULL;
849849
}
850+
851+
if (socket_type == PY_SSL_SERVER) {
852+
#define SID_CTX "Python"
853+
/* Set the session id context (server-side only) */
854+
SSL_set_session_id_context(self->ssl, (const unsigned char *) SID_CTX,
855+
sizeof(SID_CTX));
856+
#undef SID_CTX
857+
}
858+
850859
/* bpo43522 and OpenSSL < 1.1.1l: copy hostflags manually */
851860
#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION < 0x101010cf
852861
X509_VERIFY_PARAM *ssl_params = SSL_get0_param(self->ssl);
@@ -3186,11 +3195,6 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
31863195
usage for no cost at all. */
31873196
SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS);
31883197

3189-
#define SID_CTX "Python"
3190-
SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX,
3191-
sizeof(SID_CTX));
3192-
#undef SID_CTX
3193-
31943198
params = SSL_CTX_get0_param(self->ctx);
31953199
/* Improve trust chain building when cross-signed intermediate
31963200
certificates are present. See https://bugs.python.org/issue23476. */

0 commit comments

Comments
 (0)