Skip to content

Commit 4fa5fda

Browse files
gh-103242: Migrate SSLContext.set_ecdh_curve not to use deprecated APIs (GH-103378)
Migrate `SSLContext.set_ecdh_curve()` not to use deprecated OpenSSL APIs. (cherry picked from commit 3516704) Co-authored-by: Dong-hee Na <[email protected]>
1 parent 77359a8 commit 4fa5fda

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Migrate :meth:`~ssl.SSLContext.set_ecdh_curve` method not to use deprecated
2+
OpenSSL APIs. Patch by Dong-hee Na.

Modules/_ssl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,8 +4355,6 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43554355
{
43564356
PyObject *name_bytes;
43574357
int nid;
4358-
EC_KEY *key;
4359-
43604358
if (!PyUnicode_FSConverter(name, &name_bytes))
43614359
return NULL;
43624360
assert(PyBytes_Check(name_bytes));
@@ -4367,13 +4365,20 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43674365
"unknown elliptic curve name %R", name);
43684366
return NULL;
43694367
}
4370-
key = EC_KEY_new_by_curve_name(nid);
4368+
#if OPENSSL_VERSION_MAJOR < 3
4369+
EC_KEY *key = EC_KEY_new_by_curve_name(nid);
43714370
if (key == NULL) {
43724371
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
43734372
return NULL;
43744373
}
43754374
SSL_CTX_set_tmp_ecdh(self->ctx, key);
43764375
EC_KEY_free(key);
4376+
#else
4377+
if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
4378+
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
4379+
return NULL;
4380+
}
4381+
#endif
43774382
Py_RETURN_NONE;
43784383
}
43794384

0 commit comments

Comments
 (0)