Skip to content

Commit

Permalink
pythongh-103242: Migrate SSLContext.set_ecdh_curve not to use depreca…
Browse files Browse the repository at this point in the history
…ted APIs (python#103378)

Migrate `SSLContext.set_ecdh_curve()` not to use deprecated OpenSSL APIs.
  • Loading branch information
corona10 committed Apr 8, 2023
1 parent 0ba0ca0 commit 3516704
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Migrate :meth:`~ssl.SSLContext.set_ecdh_curve` method not to use deprecated
OpenSSL APIs. Patch by Dong-hee Na.
11 changes: 8 additions & 3 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4336,8 +4336,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));
Expand All @@ -4348,13 +4346,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;
}

Expand Down

0 comments on commit 3516704

Please sign in to comment.