Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-105293: Do not call SSL_CTX_set_session_id_context on client side SSL context #105295

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove call to ``SSL_CTX_set_session_id_context`` during client side context
creation in the :mod:`ssl` module.
14 changes: 9 additions & 5 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,15 @@
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
return NULL;
}

if (socket_type == PY_SSL_SERVER) {
#define SID_CTX "Python"
/* Set the session id context (server-side only) */
SSL_set_session_id_context(self->ssl, (const unsigned char *) SID_CTX,
sizeof(SID_CTX));
#undef SID_CTX
}

/* bpo43522 and OpenSSL < 1.1.1l: copy hostflags manually */
#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION < 0x101010cf
X509_VERIFY_PARAM *ssl_params = SSL_get0_param(self->ssl);
Expand Down Expand Up @@ -3186,11 +3195,6 @@
usage for no cost at all. */
SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS);

#define SID_CTX "Python"
SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX,
sizeof(SID_CTX));
#undef SID_CTX

params = SSL_CTX_get0_param(self->ctx);
/* Improve trust chain building when cross-signed intermediate
certificates are present. See https://bugs.python.org/issue23476. */
Expand Down Expand Up @@ -3614,7 +3618,7 @@
static PyObject *
get_options(PySSLContext *self, void *c)
{
return PyLong_FromLong(SSL_CTX_get_options(self->ctx));

Check warning on line 3621 in Modules/_ssl.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'function': conversion from 'uint64_t' to 'long', possible loss of data [D:\a\cpython\cpython\PCbuild\_ssl.vcxproj]

Check warning on line 3621 in Modules/_ssl.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'function': conversion from 'uint64_t' to 'long', possible loss of data [D:\a\cpython\cpython\PCbuild\_ssl.vcxproj]
}

static int
Expand All @@ -3628,7 +3632,7 @@

if (!PyArg_Parse(arg, "l", &new_opts))
return -1;
opts = SSL_CTX_get_options(self->ctx);

Check warning on line 3635 in Modules/_ssl.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'=': conversion from 'uint64_t' to 'long', possible loss of data [D:\a\cpython\cpython\PCbuild\_ssl.vcxproj]

Check warning on line 3635 in Modules/_ssl.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'=': conversion from 'uint64_t' to 'long', possible loss of data [D:\a\cpython\cpython\PCbuild\_ssl.vcxproj]
clear = opts & ~new_opts;
set = ~opts & new_opts;

Expand Down