GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable specification of multiple curves(/groups) for TLS · Issue #109945 · python/cpython

Enable specification of multiple curves(/groups) for TLS #109945

New issue
Copy link
New issue
Copy link
Closed
Closed
Enable specification of multiple curves(/groups) for TLS#109945
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-SSLtype-featureA feature request or enhancementA feature request or enhancement

Description

@martinschmatz
martinschmatz
opened on Sep 27, 2023
Issue body actions

Feature or enhancement

Proposal:

Context: Setting multiple curves/groups in the client hello of TLS clients. Enabling OpenSSLv3 providers.

Issue: Function set_ecdh_curve allows only to specify a single curve for an SSL context, which must support the generation of an EC key via OpenSSL function EC_KEY_new_by_curve_name(nid). This makes it impossible that a client offers more than one curve/group in the client hello (if not specified via openssl.cnf) and also is not supported by some OpenSSL providers (e.g. OQS).

Effect: When addressed, this would add the possibility to specify one or several curves (aka 'groups') by a colon separated string of curve names.

Implementation options: Change the existing code to avoid the somewhat cumbersome "string -> NID --> set single group" approach, but rather directly use the string value from the PyObject *name function argument and SSL_CTX_set1_groups_list().

As an alternative, we could add a new function SSLContext.set_ecdh_curves_list() which under the hood would use (for e.g OpenSSL >v3) SSL_CTX_set1_curves_list() (actually the more modern SSL_CTX_set1_groups_list())

I'm fine either way, with a slight preference for the former: It does NOT introduce a new function, which must be maintained going forward. But it isn't 110% guaranteed not to interfere with legacy code.

Preferred Implementation: ==> Code change for changing existing function (tested on v3.11.5):

static PyObject *
_ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
/*[clinic end generated code: output=23022c196e40d7d2 input=c2bafb6f6e34726b]*/
{
    PyObject *name_bytes;

    if (!PyUnicode_FSConverter(name, &name_bytes))
        return NULL;
    assert(PyBytes_Check(name_bytes));
#if OPENSSL_VERSION_MAJOR < 3
    int nid;
    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;
    }
    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
    int res = SSL_CTX_set1_groups_list(self->ctx, PyBytes_AS_STRING(name_bytes));
    Py_DECREF(name_bytes);
    if (!res) {
        _setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
        return NULL;
    }
#endif
    Py_RETURN_NONE;
}

Remark: This will also enable to use the OQS OpenSSL provider to achieve a 'quantum-hard' TLS key agreement, e.g. using x25519_kyber768.

Usage: If implemented as above, usage could look like this when using an SSL context:

myContext.set_ecdh_curve('x25519_kyber768:X25519:secp521r1')

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

This is a follow-up to #77063, an issue raised in 2018 which seemingly is no longer monitored.

Linked PRs

  • gh-109945: Enable spec of multiple curves/groups for TLS #119244

Activity

Next
  1. martinschmatz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Sep 27, 2023
  2. iritkatriel
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Nov 27, 2023
  3. planetf1
    added 2 commits that reference this issue on May 20, 2024

    pythongh-109945 Enable spec of multiple curves/groups for TLS

    df40862

    pythongh-109945 Enable spec of multiple curves/groups for TLS

    fea40c6
  4. planetf1
    added 11 commits that reference this issue on Jun 3, 2024

    pythongh-109945 Enable spec of multiple curves/groups for TLS

    1675d76

    pythongh-109945 Additional testcases for ssl

    68c5662

    pythongh-109945 Refine exception & add more tests

    f88f0b2

    pythongh-109945 update documentation

    889f0d2

    pythongh-109945 fix incorrect reference management of string

    d3fdd5f

    pythongh-109945 fix openssl<3 tests

    d9d035d

    pythongh-109945 update docs to clarify change is OpenSSL 3 and above

    4845361

    pythongh-109945 Additional testcases for ssl

    a9756d0

    pythongh-109945 Refine exception & add more tests

    55df633

    pythongh-109945 update documentation

    ce3ef69

    pythongh-109945 fix incorrect reference management of string

    e2be1e1
  5. 25 remaining items

  6. planetf1
    added 11 commits that reference this issue on Jul 17, 2024

    pythongh-109945 Additional testcases for ssl

    8ac3842

    pythongh-109945 Refine exception & add more tests

    65490a2

    pythongh-109945 update documentation

    ebad50c

    pythongh-109945 fix incorrect reference management of string

    af71eee

    pythongh-109945 fix openssl<3 tests

    8459b66

    pythongh-109945 update docs to clarify change is OpenSSL 3 and above

    1af4b23

    pythongh-109945 Corrected typo/whitespace in docs

    b48e5bc

    pythongh-109945 Correct thread issue

    42ec0c8

    pythongh-109945 do not call _setSSLError

    67fd580

    pythongh-109945 remove commented code

    fae2620

    pythongh-109945 update NEWS to correct function call format check

    8a2cbde
  7. gpshead
    added
    topic-SSL
    on Jul 19, 2024
  8. ronf commented on Jul 29, 2025

    @ronf
    ronf
    on Jul 29, 2025
    Contributor
    More actions

    Enhanced support for setting TLS groups is now available via #136306. That provides support for setting multiple curves and also supports setting other types of groups such as post-quantum crypto and fixed-field DHE, on versions of OpenSSL which support these.

    With this support, it should be possible to deprecate the existing SSLContext set_ecdh_curve method.

  9. martinschmatz commented on Jul 29, 2025

    @martinschmatz
    martinschmatz
    on Jul 29, 2025
    Author
    More actions

    @ronf Many thanks for your great work which addresses this issue.

    --> I'll close this issue.

  10. martinschmatz
    closed this as completedon Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-SSLtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.