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 — Add support in SSL module for getting/setting groups used for key agreement · Issue #136306 · python/cpython

Add support in SSL module for getting/setting groups used for key agreement #136306

New issue
Copy link
New issue
Copy link
Closed
Closed
Add support in SSL module for getting/setting groups used for key agreement#136306
Copy link
Assignees
picnixz
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-SSLtype-featureA feature request or enhancementA feature request or enhancement

Description

@ronf
ronf
opened on Jul 4, 2025
Issue body actions

Add support for getting/setting groups used for key agreement

Proposal:

This feature proposal is an expansion of the feature proposed in issue #109945. It began as a discussion on the PR where I provided some suggestions on generalizing that feature to include supporting more than just EC curves, and I provided some rough example code. Since then, I've put together a more complete version of this which I'll be submitting shortly as a PR attached to this issue.

The basic idea is to add three new methods related to getting & setting groups used for key agreement:

    SSLContext.get_groups() -> List[str]:
        """Get a list of groups implemented for key agreement, taking into account
           the SSLContext's current TLS `minimum_version` and `maximum_version` values."""
    
    SSLContext.set_groups(groups: str) -> None:
        """Set the groups allowed for key agreement for sockets created with this context."""

    SSLSocket.group() -> str:
        """Return the group used for key agreement, after the TLS handshake completes."""

These methods are designed to directly mimic the existing methods for getting and setting ciphers suites. Prior to TLS 1.3, all of this could be done with just setting ciphers, but that's no longer the case.

This proposal provides a superset of the functionality requested in #109945, allowing not only multiple EC curves to be specified but also allowing other mechanisms like fixed field DHE and post-quantum algorithms added in OpenSSL 3.5. In fact, once the set_groups() method is available the existing set_ecdh_curve() method could be deprecated, as the methods it calls are available all the way to OpenSSL 1.1.1, which is now the minimum supported OpenSSL version for Python.

The group() and get_groups() methods require later versions of OpenSSL (3.2 and 3.5, respectively), but the code can check for this and raise a NotImplemented exception if the version of OpenSSL that Python is built against is too old to support them.

Links to previous discussion of this feature:

Previous discussion occurred in PR #119244, and it was suggested that it might be best to create a new issue and PR, since the previous request might not be monitored any more.

Linked PRs

  • gh-136306: Add support for SSL groups #136307
  • gh-136306: fix test_ssl.ContextTests.test_set_groups on FIPS builds #137405

Activity

Next
  1. ronf
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jul 4, 2025
  2. brianschubert
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-SSL
    on Jul 4, 2025
  3. ronf
    added 11 commits that reference this issue on Jul 4, 2025

    pythongh-136306: Initial cut at SSL groups support

    662d66e

    pythongh-136306: Address first round of comments

    187ff2e

    pythongh-136306: Add back indentation of example

    452bdec

    pythongh-136306: Handle another allocation failure in get_groups()

    9b4066b

    pythongh-136306: Address additional review comments

    a6ad433

    pythongh-136306: Fix method references in whatsnew entry.

    aecc96b

    pythongh-136306: Add missing documentation for SSLSocket.group()

    05c75a5

    pythongh-136306: Address additional review comments

    304c223

    pythongh-136306: Minor doc updates

    b516200

    pythongh-136306: Missed one

    e0fdd25

    pythongh-136306: Address additional review comments

    35a3ae0
  4. ronf
    added a commit that references this issue on Jul 19, 2025

    pythongh-136306: Regenerate clinic signature to fix missing end fo line

    5e626a6
  5. 3 remaining items

  6. picnixz commented on Aug 4, 2025

    @picnixz
    picnixz
    on Aug 4, 2025
    Member
    More actions

    I'm re-opening the issue because this broke the AMD64 CentOS9 FIPS Only Blake2 Builtin Hash 3.x which was working until now. I don't think the issue is with the PR itself, but rather that something is not supported due to the OpenSSL build configuration (outside Python's control).

  7. picnixz commented on Aug 4, 2025

    @picnixz
    picnixz
    on Aug 4, 2025
    Member
    More actions

    So the error is:

    ERROR: test_set_groups (test.test_ssl.ContextTests.test_set_groups)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.x.cstratak-CentOS9-fips-x86_64.no-builtin-hashes-except-blake2/build/Lib/test/test_ssl.py", line 967, in test_set_groups
        self.assertIsNone(ctx.set_groups('P-256:X25519'))
                          ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
    ssl.SSLError: unrecognized group (_ssl.c:3665)
    

    The OpenSSL version of this buildbot is configured as:

    fips.linux_crypto_fips_enabled: 1
    fips.openssl_fips_mode: 1
    
    ssl.OPENSSL_VERSION: OpenSSL 3.5.1 1 Jul 2025
    ssl.OPENSSL_VERSION_INFO: (3, 5, 0, 1, 0)
    
    ssl.SSLContext.maximum_version: 772
    ssl.SSLContext.minimum_version: 771
    ssl.SSLContext.options: 2186412112
    ssl.SSLContext.protocol: 16
    ssl.SSLContext.verify_mode: 2
    

    that is, for the options:

    <Options.OP_NO_COMPRESSION|OP_ENABLE_MIDDLEBOX_COMPAT|OP_CIPHER_SERVER_PREFERENCE|OP_NO_SSLv3|OP_ALL: 2186412112>
    

    Interestingly, the other FIPS buildbot that is working has another version:

    ssl.OPENSSL_VERSION: OpenSSL 1.1.1k  FIPS 25 Mar 2021
    ssl.OPENSSL_VERSION_INFO: (1, 1, 1, 11, 15)
    ssl.OP_ALL: 0x80000054
    ssl.OP_NO_TLSv1_1: 0x10000000
    
    ssl.SSLContext.maximum_version: 772
    ssl.SSLContext.minimum_version: 771
    ssl.SSLContext.options: 2186412116
    ssl.SSLContext.protocol: 16
    ssl.SSLContext.verify_mode: 2
    

    For the options, that is

    <Options.OP_LEGACY_SERVER_CONNECT|OP_NO_COMPRESSION|OP_ENABLE_MIDDLEBOX_COMPAT|OP_CIPHER_SERVER_PREFERENCE|OP_NO_SSLv3|OP_ALL: 2186412116>
    
  8. ronf commented on Aug 4, 2025

    @ronf
    ronf
    on Aug 4, 2025
    ContributorAuthor
    More actions

    Since this is a FIPS build, X25519 will not be available. However, P-256 should be available. To avoid getting an error here, we might need to add a '?' in front of X25519 in the test (e.g. 'P-256:?X25519'). Alternately, we could odd in a #if check for whether this is a FIPS compile if that's available, and request only 'P-256' in that case.

  9. picnixz commented on Aug 4, 2025

    @picnixz
    picnixz
    on Aug 4, 2025
    Member
    More actions

    Wait X25519 is not allowed? I thought that a recent draft allowed its usage. Anyway, to know whether the FIPS module is enabled, there is _hashlib.get_fips_mode(). So yes, let's skip the test if this is in FIPS mode.

    Or .. maybe it's a stupid idea but how about "P-256:P-256"? would it work actually?

  10. ronf commented on Aug 4, 2025

    @ronf
    ronf
    on Aug 4, 2025
    ContributorAuthor
    More actions

    FIPS recently allowed x25519mlkem768, but they haven't gone back and allowed plain X25519. Even if they did at some point in the future I'm not sure OpenSSL 1.1.1 would pick up those changes.

    My recommendation would be to add the '?' flag in front of x25519, which says to just ignore X25519 on OpenSSL versions/configurations that don't support it. The other option would be something like "P-256:P-384". While I expect 'P-256:P-256' would probably also work, I don't think we need to resort to that.

  11. picnixz commented on Aug 4, 2025

    @picnixz
    picnixz
    on Aug 4, 2025
    Member
    More actions

    Ok, let's just do the ? trick. Could you open a PR for that and add a comment indicating why we need it?

  12. ronf commented on Aug 5, 2025

    @ronf
    ronf
    on Aug 5, 2025
    ContributorAuthor
    More actions

    Sure - I'll try to get to that in the next day or two. In the meantime, only FIPS builds should be affected, and it should really only affect the unit tests. The resulting binary should still be completely usable.

  13. picnixz commented on Aug 5, 2025

    @picnixz
    picnixz
    on Aug 5, 2025
    Member
    More actions

    Yes that I agree. I have a few hours so I'll do it myself

  14. picnixz
    self-assigned this
    on Aug 5, 2025
  15. picnixz commented on Aug 5, 2025

    @picnixz
    picnixz
    on Aug 5, 2025
    Member
    More actions

    Ah actually, ignoring unknow groups is not possible before OpenSSL 3.3:

    Support for ignoring unknown groups in SSL_CTX_set1_groups_list() and SSL_set1_groups_list() was added in OpenSSL 3.3.

  16. picnixz
    added a commit that references this issue on Aug 5, 2025

    gh-136306: fix `test_ssl.ContextTests.test_set_groups` on FIPS builds (…

    0af7556
  17. picnixz
    closed this as completedon Aug 5, 2025
  18. picnixz commented on Aug 5, 2025

    @picnixz
    picnixz
    on Aug 5, 2025
    Member
    More actions

    Fixed in 0af7556.

  19. Agent-Hellboy
    added 2 commits that reference this issue on Aug 19, 2025

    pythongh-136306: Add support for getting and setting SSL groups (pyth…

    2f89abb

    pythongh-136306: fix `test_ssl.ContextTests.test_set_groups` on FIPS …

    fa8e03f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @picnixz
    picnixz

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.