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-107361: strengthen default SSL context flags by woodruffw · Pull Request #112389 · python/cpython

Conversation

@woodruffw

@woodruffw woodruffw commented Nov 25, 2023 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

See #107361: this adds VERIFY_X509_STRICT to make the default SSL context perform stricter (per RFC 5280) validation, as well as VERIFY_X509_PARTIAL_CHAIN to enforce more standards-compliant path-building behavior.

As part of this changeset, I had to tweak make_ssl_certs.py slightly to emit 5280-conforming CA certs. This changeset includes the regenerated certificates after that change.

CC @sethmlarson

  • Issue: ssl.create_default_context(): add VERIFY_X509_STRICT and VERIFY_X509_PARTIAL_CHAIN to the default verify_flags #107361

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

Sorry, something went wrong.

Uh oh!

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

thoughtsunificator reacted with thumbs down emoji
All reactions
  • 👎 1 reaction
@woodruffw
pythongh-107361: strengthen default SSL context flags
f0e262e
See python#107361: this adds `VERIFY_X509_STRICT` to make the default
SSL context perform stricter (per RFC 5280) validation, as well
as `VERIFY_X509_PARTIAL_CHAIN` to enforce more standards-compliant
path-building behavior.

As part of this changeset, I had to tweak `make_ssl_certs.py`
slightly to emit 5280-conforming CA certs. This changeset includes
the regenerated certificates after that change.
@bedevere-app bedevere-app Bot added the awaiting review label Nov 25, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Nov 25, 2023
ssl.create_default_context(): add VERIFY_X509_STRICT and VERIFY_X509_PARTIAL_CHAIN to the default verify_flags #107361
Closed
woodruffw added 2 commits November 24, 2023 23:47
@woodruffw
add news entry
4782048
@woodruffw
ssl: expand comment
732b953
@sethmlarson sethmlarson added the type-security A security issue label Nov 25, 2023
@gpshead
gpshead requested review from gpshead and sethmlarson November 29, 2023 02:17
@gpshead gpshead self-assigned this Nov 29, 2023
gpshead
gpshead approved these changes Nov 29, 2023
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Nov 29, 2023
malemburg
malemburg requested changes Nov 29, 2023
View reviewed changes
Comment thread Doc/library/ssl.rst Resolved

Uh oh!

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

Comment thread Misc/NEWS.d/next/Library/2023-11-24-23-40-00.gh-issue-107361.v54gh46.rst Resolved

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting merge labels Nov 29, 2023
@bedevere-app

bedevere-app Bot commented Nov 29, 2023

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

All reactions

Sorry, something went wrong.

Uh oh!

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

@pitrou

pitrou commented Nov 29, 2023

Copy link
Copy Markdown
Member

Side note: perhaps we mark all PEM files as generated?

All reactions

Sorry, something went wrong.

Uh oh!

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

woodruffw added 4 commits November 29, 2023 10:12
@woodruffw
ssl.rst: further explain new X509 flags
15c0313
Signed-off-by: William Woodruff <[email protected]>
@woodruffw
whatsnew: add ssl.create_default_context changes
2aceb81
Signed-off-by: William Woodruff <[email protected]>
@woodruffw
gitattributes: mark certdata as generated
eb2c6e4
Signed-off-by: William Woodruff <[email protected]>
@woodruffw
gitattributes: avoid {} glob syntax
668803c
Signed-off-by: William Woodruff <[email protected]>
@woodruffw

woodruffw commented Nov 29, 2023

Copy link
Copy Markdown
Contributor Author

Side note: perhaps we mark all PEM files as generated?

Done: I've marked certdata/*.{pem,0} as generated (the .0 files should also really be .pem I think -- I can do some cleanup there in a follow-up PR, if there's interest).

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner
vstinner reviewed Nov 29, 2023
View reviewed changes
Comment thread Doc/whatsnew/3.13.rst Resolved

Uh oh!

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

@vstinner

vstinner commented Nov 30, 2023

Copy link
Copy Markdown
Member

In practice, this should have no effect on >99% of users: most root programs use 5280 as their baseline, and the Web PKI's CABF rules are also built on 5280.

Your PR required to regenerate all PEM test certificates. Does it mean that they belong to the 1% of affected users?

thoughtsunificator and Rawk reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@woodruffw

woodruffw commented Nov 30, 2023

Copy link
Copy Markdown
Contributor Author

Your PR required to regenerate all PEM test certificates. Does it mean that they belong to the 1% of affected users?

I made the numbers up for emphasis, but I'll stand by this having no effect on the vast majority of users: the vast majority use case is the Web PKI, which is significantly stricter than even VERIFY_X509_STRICT. The fact that the PEMs had to be regenerated is more a testament to how lax OpenSSL is by default than any actual common practice 🙂

Or put another way: most users are not manually generating certs with openssl req or, if they are, they're massaging them into RFC 5280 compliance because other ecosystems (like Go, Java, and OSes/major software) are much more strict.

Additional datapoints:

  • The MS root program is at least as strict as these changes: https://learn.microsoft.com/en-us/security/trusted-root/program-requirements
  • The Java root program specifies RFC 5280, making it at least as strict: https://www.oracle.com/java/technologies/javase/carootcertsprogram.html
  • Same with Adobe: https://helpx.adobe.com/acrobat/kb/approved-trust-list2.html

(I picked these semi-arbitrarily from https://pkic.org/ltl/)

pitrou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

sethmlarson
sethmlarson reviewed Dec 1, 2023
View reviewed changes

@sethmlarson sethmlarson left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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 ++ on the partial chain changes, my comments below apply to VERIFY_X509_STRICT:

Since OpenSSL will likely be the way folks are generating certificates and like you said, OpenSSL allows you to do things that isn't acceptable for Web PKI, is there any value in providing guidance on how one does generate a certificate with OpenSSL that works with VERIFY_X509_STRICT?

Also since we're recommending folks down a new code path to restore old behavior, should we create a new test which exercises that code path and verifies that "bad" certificates would be accepted?

What about non-Web PKI, does this change have any affect for certificates in that domain? I am less versed for this, so am relying a bit on others' experience.

Sorry, something went wrong.

Uh oh!

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

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@pitrou

pitrou commented Dec 1, 2023

Copy link
Copy Markdown
Member

Since OpenSSL will likely be the way folks are generating certificates

Is that still the case? Aren't most users relying on something like Let's Encrypt nowadays (at least for Web certificates, but also perhaps e-mail)?

is there any value in providing guidance on how one does generate a certificate with OpenSSL that works with VERIFY_X509_STRICT?

I don't think writing an OpenSSL command line tutorial is really a responsibility for CPython maintainers.

woodruffw reacted with thumbs up emoji controlrepo reacted with thumbs down emoji
All reactions
  • 👍 1 reaction
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

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

@woodruffw

woodruffw commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

Since OpenSSL will likely be the way folks are generating certificates and like you said, OpenSSL allows you to do things that isn't acceptable for Web PKI, is there any value in providing guidance on how one does generate a certificate with OpenSSL that works with VERIFY_X509_STRICT?

To clarify: I think most users won't be using OpenSSL to generate certs -- I think the majority will be getting their certs from a CA service (like Let's Encrypt), with a very small minority doing bespoke things. Putting an OpenSSL example in the docs might cause additional confusion, and IMO won't be too helpful anyways (since the context here is verification, in which case the user might not have any control over the certs they're being presented with).

What about non-Web PKI, does this change have any affect for certificates in that domain? I am less versed for this, so am relying a bit on others' experience

Nope, this should be wholly compatible with those -- "strict" validation for OpenSSL means "approximate RFC 5280," and the Web PKI profiles are a superset of RFC 5280 🙂

In other words: all public web certificates should be compatible with these changes.

pitrou and gpshead reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@malemburg

malemburg commented Dec 1, 2023

Copy link
Copy Markdown
Member

These are the checks that OpenSSL applies when VERIFY_X509_STRICT is set: https://www.openssl.org/docs/man3.0/man1/openssl-verification-options.html#x509_strict (search for -x509_strict in case the link doesn't take you there directly)

These checks all make sense for certs generated with a trusted CA, e.g. Let's Encrypt.

The other common use case is having self-signed certs (e.g. for intranet/VPC devices). Those will already fail to verify with the current standard settings, since self-signed certs are rejected by OpenSSL's verify. You have to use the ssl._create_unverified_context() or a custom one to the same effect for those.

Note: The POP/FTP/IMAP and SMTP modules use the unverified context, since intranet/VPC mail and FTP servers will often not use certs created by a trusted CA for various reasons or they are referenced using IP addresses, which don't work with certs at all.

All reactions

Sorry, something went wrong.

Uh oh!

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

malemburg
malemburg approved these changes Dec 1, 2023
View reviewed changes
@gpshead gpshead added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 6, 2024
@bedevere-bot

bedevere-bot commented Mar 6, 2024

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @gpshead for commit cef6950 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 6, 2024
gpshead
gpshead approved these changes Mar 6, 2024
View reviewed changes

@gpshead gpshead 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.

LGTM - I'm just running a round of buildbot tests to look for any surprises before merging.

Sorry, something went wrong.

Uh oh!

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

woodruffw reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@woodruffw
Merge remote-tracking branch 'upstream/main' into default-ssl-verify-…
2c7b14e
…flags

Signed-off-by: William Woodruff <[email protected]>
@gpshead
gpshead merged commit 0876b92 into python:main Mar 6, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 6, 2024
@woodruffw
woodruffw deleted the default-ssl-verify-flags branch March 6, 2024 21:47
@illia-v illia-v mentioned this pull request Mar 21, 2024
Investigate CI failures with Python 3.13.0a5 urllib3/urllib3#3366
Closed
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
@woodruffw @vstinner @adorilson
pythongh-107361: strengthen default SSL context flags (python#112389)
5917bb2
This adds `VERIFY_X509_STRICT` to make the default
SSL context perform stricter (per RFC 5280) validation, as well
as `VERIFY_X509_PARTIAL_CHAIN` to enforce more standards-compliant
path-building behavior.

As part of this changeset, I had to tweak `make_ssl_certs.py`
slightly to emit 5280-conforming CA certs. This changeset includes
the regenerated certificates after that change.

Signed-off-by: William Woodruff <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@illia-v illia-v mentioned this pull request Mar 27, 2024
Add AKI to child CA certificates python-trio/trustme#642
Merged
@sethmlarson

sethmlarson commented Mar 27, 2024

Copy link
Copy Markdown
Contributor

@woodruffw Looks like this change breaks trustme generated certificates, see python-trio/trustme#642

All reactions

Sorry, something went wrong.

Uh oh!

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

@woodruffw

woodruffw commented Mar 27, 2024

Copy link
Copy Markdown
Contributor Author

@woodruffw Looks like this change breaks trustme generated certificates, see python-trio/trustme#642

Thanks for sharing! Looking now.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 28, 2024

Copy link
Copy Markdown
Member

@woodruffw Looks like this change breaks trustme generated certificates, see python-trio/trustme#642

If an application is affected by these changes, they can "just" disable the two options, no?

Using ctx.verify_flags &= ~(ssl.VERIFY_X509_STRICT | ssl.VERIFY_X509_PARTIAL_CHAIN):

$ ./python
Python 3.13.0a5+ (heads/main:b44898299a2, Mar 28 2024, 09:01:21) [GCC 13.2.1 20240316 (Red Hat 13.2.1-7)] on linux
>>> import ssl

>>> ctx=ssl.create_default_context()
>>> ctx.verify_flags & ssl.VERIFY_X509_STRICT
<VerifyFlags.VERIFY_X509_STRICT: 32>
>>> ctx.verify_flags & ssl.VERIFY_X509_PARTIAL_CHAIN
<VerifyFlags.VERIFY_X509_PARTIAL_CHAIN: 524288>

>>> ctx.verify_flags &= ~(ssl.VERIFY_X509_STRICT | ssl.VERIFY_X509_PARTIAL_CHAIN)
>>> ctx.verify_flags & ssl.VERIFY_X509_STRICT
<VerifyFlags.VERIFY_DEFAULT: 0>
>>> ctx.verify_flags & ssl.VERIFY_X509_PARTIAL_CHAIN
<VerifyFlags.VERIFY_DEFAULT: 0>
gpshead and nuclearpidgeon reacted with thumbs up emoji thoughtsunificator and timonwong reacted with thumbs down emoji
All reactions
  • 👍 2 reactions
  • 👎 2 reactions

Sorry, something went wrong.

Uh oh!

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

@woodruffw

woodruffw commented Mar 28, 2024

Copy link
Copy Markdown
Contributor Author

If an application is affected by these changes, they can "just" disable the two options, no?

Yep, correct. I think the above is also generating certs, so they wanted to get it right more generally, so that each Python downstream consumer doesn't have to also download the strict option.

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
@woodruffw @vstinner @diegorusso
pythongh-107361: strengthen default SSL context flags (python#112389)
2221ad4
This adds `VERIFY_X509_STRICT` to make the default
SSL context perform stricter (per RFC 5280) validation, as well
as `VERIFY_X509_PARTIAL_CHAIN` to enforce more standards-compliant
path-building behavior.

As part of this changeset, I had to tweak `make_ssl_certs.py`
slightly to emit 5280-conforming CA certs. This changeset includes
the regenerated certificates after that change.

Signed-off-by: William Woodruff <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@jpbede jpbede mentioned this pull request Jan 6, 2025
SSLCertVerificationError with private CA since HA 2024.12.0 home-assistant/core#133506
Closed
@jvanasco jvanasco mentioned this pull request May 12, 2025
Testing: Certificates incompatible with urllib3 2.4.0 and Python 3.13 crate/crate-python#708
Closed
@jnoordsij jnoordsij mentioned this pull request May 19, 2025
Add additional extensions to generated ssl certs docker-library/docker#536
Merged
@thoughtsunificator

This comment was marked as abuse.

Sign in to view
This was referenced Aug 27, 2025
Python 3.13: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1032) #138193
Closed
verify_flag VERIFY_X509_STRICT: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1032) openssl/openssl#28391
Closed
@candrews candrews mentioned this pull request Oct 15, 2025
MITM proxy: Certificate verify failed due to Missing Authority Key Identifier valfirst/browserup-proxy#561
Closed
@nuclearpidgeon nuclearpidgeon mentioned this pull request Nov 24, 2025
Python 3.13: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1032) urllib3/urllib3#3665
Closed
@robnagler robnagler mentioned this pull request Dec 31, 2025
py 3.13 sirepo_jupyter issues radiasoft/rsconf#603
Closed
@shaanmajid shaanmajid mentioned this pull request Feb 4, 2026
REQUESTS_CA_BUNDLE not honored by UV astral-sh/uv#17853
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 9, 2026
Update .pre-commit-config.yaml Bigdaddy1990/jackery_solarvault#151
Closed
6 tasks
This was referenced Jul 2, 2026
[Bug] API integration will not load and fails to get SSL cert after new HA Core Update 2026.7.0 SecKatie/ha-wyzeapi#870
Closed
[BUG] integration fails with HAOS 18.1 because SSL root cert is not trusted. romedtino/simple-wyze-vac#107
Closed
@FpunktBpunkt FpunktBpunkt mentioned this pull request Oct 9, 2026
How to import mail server's root certificate to use starttls/tls knrdl/acme-ca-server#312
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@gpshead gpshead gpshead approved these changes
@malemburg malemburg malemburg approved these changes
@sethmlarson sethmlarson sethmlarson approved these changes

Uh oh!

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

Assignees

@gpshead gpshead

Labels

type-security A security issue

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.

8 participants

@woodruffw @pitrou @vstinner @malemburg @sethmlarson @bedevere-bot @thoughtsunificator @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.