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 — gh-137197: Add SSLContext.set_ciphersuites to set TLS 1.3 ciphers by ronf · Pull Request #137198 · python/cpython

Conversation

@ronf

@ronf ronf commented Jul 29, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This commit adds a new method SSLContext.set_ciphersuites which can be used to set TLS 1.3 cipher suites. It also updates the documentation, unit tests, and "what's new" text. A NEWS blurb will be added shortly.

  • Issue: Add support in SSL module for getting/setting TLS 1.3 cipher suites #137197

📚 Documentation preview 📚: https://cpython-previews--137198.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronf
ronf requested review from gpshead and picnixz as code owners July 29, 2025 05:07
@bedevere-app bedevere-app Bot added the awaiting review label Jul 29, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jul 29, 2025
Add support in SSL module for getting/setting TLS 1.3 cipher suites #137197
Closed
gpshead
gpshead reviewed Jul 29, 2025
View reviewed changes
Comment thread Modules/_ssl.c
{
int ret = SSL_CTX_set_cipher_list(self->ctx, cipherlist);
if (ret == 0) {
/* Clearing the error queue is necessary on some OpenSSL versions,

@gpshead gpshead Jul 29, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't remove this without understanding which OpenSSL versions it was referring to and whether they are still in use by CPython builds (1.1.x-ish API'd AWS-LC at a minimum, otherwise OpenSSL 3.0+).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ronf ronf Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clearing of the error queue is still happening here. I just took advantage of an existing helper function setSSLError to take care of this:

static PyObject *
_setSSLError (_sslmodulestate *state, const char *errstr, int errcode, const char *filename, int lineno)
{
    if (errstr == NULL)
        errcode = ERR_peek_last_error();
    else
        errcode = 0;
    fill_and_set_sslerror(state, NULL, state->PySSLErrorObject, errcode, errstr, lineno, errcode);
    ERR_clear_error();
    return NULL;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it that way and change it in a follow-up PR instead. Actually, the errcode parameter for _setSSLError is redundant as it's always overwritten.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Jul 29, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronf
ronf requested a review from AA-Turner as a code owner August 9, 2025 00:23
ronf and others added 4 commits August 8, 2025 18:00
@ronf
pythongh-137197: Add SSLContext.set_ciphersuites to set TLS 1.3 ciphers
5a1cc22
@blurb-it @ronf
📜🤖 Added by blurb_it.
09534fd
@ronf
pythongh-137197: Fix typo in documentation
6783fe6
@ronf
pythongh-137197: Update what's new text
d3375f1
Clarify when to use the original set_ciphers (TLS 1.2 and earlier)
vs. the new set_ciphersuites (TLS 1.3) methods and that both can
be used at once.
@ronf
ronf force-pushed the ssl-ciphersuite-support branch from f2cda88 to d3375f1 Compare August 9, 2025 01:00
picnixz
picnixz reviewed Aug 9, 2025
View reviewed changes
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronf
pythongh-137197: Address review comments
48e5164
@ronf

ronf commented Aug 9, 2025

Copy link
Copy Markdown
Contributor Author

I think all the remaining review comments should be addressed in 48e5164. Let me know if you'd like any other changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Aug 9, 2025
View reviewed changes
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronf added 2 commits August 9, 2025 13:23
@ronf
pythongh-137197: Rework test cases
11b760e
This commit reworks the set_ciphersuites() test cases, moving them into
their own class to avoid any changes to existing tests. It also makes
the cipher selection dynamic to avoid potentially trying to use a cipher
not available in some environments.
@ronf
pythongh-137197: Fix capitalization in docs
eaae575
@ronf

ronf commented Aug 16, 2025

Copy link
Copy Markdown
Contributor Author

@picnixz, any further changes required? The build failure appears to be something in the test runner, as the only thing changed in the last checkin was capitalization in the docs. Prior to that, all tests succeeded.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Aug 16, 2025

Copy link
Copy Markdown
Member

I'm not available before next week but I'll have a look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz self-assigned this Aug 16, 2025
@ronf

ronf commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

That'd be great - thanks!

I spent some time today working on adding methods to manage signature algorithms and will create a new issue & PR for those as soon as these changes are merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
picnixz self-requested a review August 18, 2025 10:36
picnixz
picnixz reviewed Aug 18, 2025
View reviewed changes
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/ssl.rst Outdated
ciphers yet, but :meth:`SSLContext.get_ciphers` returns them.
- TLS 1.3 uses a disjunct set of cipher suites. All AES-GCM and ChaCha20
cipher suites are enabled by default. To restrict which TLS1.3 ciphers
are allowed, the method :meth:`SSLContext.set_ciphersuites` should be

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity: I really hate that OpenSSL named it SSL_CTX_set_ciphersuites for TLS 1.3 and later, and SSL_CTX_set_cipher_list for TLS 1.2 and below. I hope that this won't be annoying to users.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ronf ronf Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised what they did here at first and I'm not a big fan about the naming chosen, but I can see why they didn't want to try and extend the existing command. It allows all kinds of partial matches on the five individual elements that make up a cipher suite in TLS 1.2 and earlier, plus other special keywords like LOW/MEDIUM/HIGH. All of that is gone with TLS 1.3, and the new function is much simpler and only supports an exact match against the very small number of cipher suites defined in TLS 1.3.

I don't really know why they didn't include "_list" in the name of the OpenSSL function, given that this seems to be the convention for other such calls that take a string argument.

The good news here is that things like post-quantum crypto are going to drive migration to TLS 1.3, and at some point setting TLS 1.2 cipher suites will no longer matter. At that point, the previous set_ciphers() can be deprecated and eventually removed, with only set_ciphersuites() remaining.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_ssl.c
{
int ret = SSL_CTX_set_cipher_list(self->ctx, cipherlist);
if (ret == 0) {
/* Clearing the error queue is necessary on some OpenSSL versions,

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it that way and change it in a follow-up PR instead. Actually, the errcode parameter for _setSSLError is redundant as it's always overwritten.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronf
pythongh-137197: Address review comments
e09017f
@ronf

ronf commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for your review! I think I've addressed this round of review comments, including reverting the change to _ssl__SSLContext_set_ciphers_impl for now. Let me know if anything else is needed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
picnixz self-requested a review August 22, 2025 08:11
@ronf

ronf commented Aug 28, 2025

Copy link
Copy Markdown
Contributor Author

Just checking in - are there any further changes you'd like me to make?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Aug 28, 2025
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nitpicks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2025-07-29-05-12-50.gh-issue-137197.bMK3sO.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_ssl.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronf
pythongh-137197: Address review comments
caf6675
picnixz
picnixz approved these changes Aug 29, 2025
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A final nitpick and we're good to go I think

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Aug 29, 2025
@ronf
pythongh-137197: Address last review comment
fe8791d
@ronf

ronf commented Aug 29, 2025

Copy link
Copy Markdown
Contributor Author

I've gone ahead and created issue #138252 in preparation for the next round of changes, to add support for getting and setting TLS signature algorithms. I have those changes ready, but will hold off until this change is merged before I submit the PR, to avoid any merge conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz approved these changes Aug 30, 2025
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to amend it directly and merge this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py
self.assertRaises(ssl.SSLEOFError, sslobj.read)


@unittest.skipUnless(has_tls_version('TLSv1_3'), "TLS 1.3 is not available")

@picnixz picnixz Aug 30, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: change the requires_tls_version decorator so that it works.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_ssl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ssl.py
min_version=ssl.TLSVersion.TLSv1_2,
max_version=ssl.TLSVersion.TLSv1_2) as s:
s.connect(self.server_addr)
self.assertEqual(s.cipher()[1], 'TLSv1.2')

@picnixz picnixz Aug 30, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is asserting that the default TLSv1_2 cipher suite is actually being used right? I'm fine with the current test but I'd like to fortify it (which I'll do) in the future where we have a ciphersuite for TLSv1.3 and a ciphersuite for TLSv1.2 and if we use min/max versions, then we're going to be using the TLSv1.2 ciphersuite we specified.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@picnixz
Apply suggestions from code review
4566478
@picnixz
picnixz enabled auto-merge (squash) August 30, 2025 09:12
@picnixz
picnixz merged commit bacb777 into python:main Aug 30, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Aug 30, 2025
@ronf
ronf deleted the ssl-ciphersuite-support branch August 30, 2025 15:57
@picnixz picnixz mentioned this pull request Sep 8, 2025
Improve usage of _setSSLError in _ssl.c #138634
Open
3 tasks
lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
@ronf @picnixz @lkollar
pythongh-137197: Add SSLContext.set_ciphersuites to set TLSv1.3 cip…
eeba494
…hers (python#137198)

Co-authored-by: Bénédikt Tran <[email protected]>
@ashm-dev ashm-dev mentioned this pull request Nov 1, 2026
gh-80665: Add TLS v1.3 cipher suite set function #31607
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead left review comments
@picnixz picnixz picnixz approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@picnixz picnixz

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@ronf @picnixz @gpshead
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.