Skip to content

Commit df40862

Browse files
committed
gh-109945 Enable spec of multiple curves/groups for TLS
1 parent 94591dc commit df40862

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
@@ -4373,18 +4373,19 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43734373
/*[clinic end generated code: output=23022c196e40d7d2 input=c2bafb6f6e34726b]*/
43744374
{
43754375
PyObject *name_bytes;
4376-
int nid;
4376+
43774377
if (!PyUnicode_FSConverter(name, &name_bytes))
43784378
return NULL;
43794379
assert(PyBytes_Check(name_bytes));
4380+
#if OPENSSL_VERSION_MAJOR < 3
4381+
int nid;
43804382
nid = OBJ_sn2nid(PyBytes_AS_STRING(name_bytes));
43814383
Py_DECREF(name_bytes);
43824384
if (nid == 0) {
43834385
PyErr_Format(PyExc_ValueError,
43844386
"unknown elliptic curve name %R", name);
43854387
return NULL;
43864388
}
4387-
#if OPENSSL_VERSION_MAJOR < 3
43884389
EC_KEY *key = EC_KEY_new_by_curve_name(nid);
43894390
if (key == NULL) {
43904391
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
@@ -4393,7 +4394,9 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
43934394
SSL_CTX_set_tmp_ecdh(self->ctx, key);
43944395
EC_KEY_free(key);
43954396
#else
4396-
if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
4397+
int res = SSL_CTX_set1_groups_list(self->ctx, PyBytes_AS_STRING(name_bytes));
4398+
Py_DECREF(name_bytes);
4399+
if (!res) {
43974400
_setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
43984401
return NULL;
43994402
}

0 commit comments

Comments
 (0)