Skip to content

bpo-32882: Added support for X25519 in SSLContext.set_ecdh_curve() #5770

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,10 @@ def test_set_ecdh_curve(self):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.set_ecdh_curve("prime256v1")
ctx.set_ecdh_curve(b"prime256v1")
ctx.set_ecdh_curve("X25519")
ctx.set_ecdh_curve(b"X25519")
ctx.set_ecdh_curve("X25519:prime256v1")
ctx.set_ecdh_curve(b"X25519:prime256v1")
self.assertRaises(TypeError, ctx.set_ecdh_curve)
self.assertRaises(TypeError, ctx.set_ecdh_curve, None)
self.assertRaises(ValueError, ctx.set_ecdh_curve, "foo")
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ Craig Rowland
Clinton Roy
Paul Rubin
Sam Ruby
Stefan Rüster
Demur Rumed
Audun S. Runde
Eran Rundstein
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for selecting X25519 in SSLContext.set_ecdh_curve().
26 changes: 10 additions & 16 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3936,27 +3936,21 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
/*[clinic end generated code: output=23022c196e40d7d2 input=c2bafb6f6e34726b]*/
{
PyObject *name_bytes;
int nid;
EC_KEY *key;

if (!PyUnicode_FSConverter(name, &name_bytes))
return NULL;
assert(PyBytes_Check(name_bytes));
nid = OBJ_sn2nid(PyBytes_AS_STRING(name_bytes));
Py_DECREF(name_bytes);
if (nid == 0) {
PyErr_Format(PyExc_ValueError,
"unknown elliptic curve name %R", name);
return NULL;
}
key = EC_KEY_new_by_curve_name(nid);
if (key == NULL) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
return NULL;

if(SSL_CTX_set1_curves_list(self->ctx, PyBytes_AS_STRING(name_bytes)))
{
Py_DECREF(name_bytes);
Py_RETURN_NONE;
}
SSL_CTX_set_tmp_ecdh(self->ctx, key);
EC_KEY_free(key);
Py_RETURN_NONE;

Py_DECREF(name_bytes);
PyErr_Format(PyExc_ValueError,
"invalid elliptic curves list %R", name);
return NULL;
}
#endif

Expand Down