Skip to content

Commit 403b917

Browse files
committed
gh-109945 Enable spec of multiple curves/groups for TLS
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
1 parent ac07451 commit 403b917

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/_ssl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,18 +4379,19 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43794379
/*[clinic end generated code: output=23022c196e40d7d2 input=c2bafb6f6e34726b]*/
43804380
{
43814381
PyObject *name_bytes;
4382-
int nid;
4382+
43834383
if (!PyUnicode_FSConverter(name, &name_bytes))
43844384
return NULL;
43854385
assert(PyBytes_Check(name_bytes));
4386+
#if OPENSSL_VERSION_MAJOR < 3
4387+
int nid;
43864388
nid = OBJ_sn2nid(PyBytes_AS_STRING(name_bytes));
43874389
Py_DECREF(name_bytes);
43884390
if (nid == 0) {
43894391
PyErr_Format(PyExc_ValueError,
43904392
"unknown elliptic curve name %R", name);
43914393
return NULL;
43924394
}
4393-
#if OPENSSL_VERSION_MAJOR < 3
43944395
EC_KEY *key = EC_KEY_new_by_curve_name(nid);
43954396
if (key == NULL) {
43964397
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
@@ -4399,7 +4400,9 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43994400
SSL_CTX_set_tmp_ecdh(self->ctx, key);
44004401
EC_KEY_free(key);
44014402
#else
4402-
if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
4403+
int res = SSL_CTX_set1_groups_list(self->ctx, PyBytes_AS_STRING(name_bytes));
4404+
Py_DECREF(name_bytes);
4405+
if (!res) {
44034406
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
44044407
return NULL;
44054408
}

0 commit comments

Comments
 (0)