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 35167043e3)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
This commit is contained in:
Miss Islington (bot) 2023-04-08 11:21:27 -07:00 committed by GitHub
parent 77359a86b8
commit 4fa5fda14b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1,2 @@
Migrate :meth:`~ssl.SSLContext.set_ecdh_curve` method not to use deprecated
OpenSSL APIs. Patch by Dong-hee Na.

View file

@ -4355,8 +4355,6 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
{
PyObject *name_bytes;
int nid;
EC_KEY *key;
if (!PyUnicode_FSConverter(name, &name_bytes))
return NULL;
assert(PyBytes_Check(name_bytes));
@ -4367,13 +4365,20 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
"unknown elliptic curve name %R", name);
return NULL;
}
key = EC_KEY_new_by_curve_name(nid);
#if OPENSSL_VERSION_MAJOR < 3
EC_KEY *key = EC_KEY_new_by_curve_name(nid);
if (key == NULL) {
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
return NULL;
}
SSL_CTX_set_tmp_ecdh(self->ctx, key);
EC_KEY_free(key);
#else
if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
return NULL;
}
#endif
Py_RETURN_NONE;
}