Skip to content

Commit 3516704

Browse files
authored
gh-103242: Migrate SSLContext.set_ecdh_curve not to use deprecated APIs (#103378)
Migrate `SSLContext.set_ecdh_curve()` not to use deprecated OpenSSL APIs.
1 parent 0ba0ca0 commit 3516704

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
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

+8-3
Original file line numberDiff line numberDiff line change
@@ -4336,8 +4336,6 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43364336
{
43374337
PyObject *name_bytes;
43384338
int nid;
4339-
EC_KEY *key;
4340-
43414339
if (!PyUnicode_FSConverter(name, &name_bytes))
43424340
return NULL;
43434341
assert(PyBytes_Check(name_bytes));
@@ -4348,13 +4346,20 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43484346
"unknown elliptic curve name %R", name);
43494347
return NULL;
43504348
}
4351-
key = EC_KEY_new_by_curve_name(nid);
4349+
#if OPENSSL_VERSION_MAJOR < 3
4350+
EC_KEY *key = EC_KEY_new_by_curve_name(nid);
43524351
if (key == NULL) {
43534352
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
43544353
return NULL;
43554354
}
43564355
SSL_CTX_set_tmp_ecdh(self->ctx, key);
43574356
EC_KEY_free(key);
4357+
#else
4358+
if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
4359+
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
4360+
return NULL;
4361+
}
4362+
#endif
43584363
Py_RETURN_NONE;
43594364
}
43604365

0 commit comments

Comments
 (0)