Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-107361: strengthen default SSL context flags#112389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
f0e262e4782048732b95315c03132aceb81eb2c6e4668803cda318a64ae44d1792383af1b59edc8a7bb5f6c3af3ff087fbe46a672fe42d9a1a3e037cef69502c7b14eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -38,7 +38,7 @@ | ||
| ssl = import_helper.import_module("ssl") | ||
| import _ssl | ||
| from ssl importPurpose,TLSVersion, _TLSContentType, _TLSMessageType, _TLSAlertType | ||
| Py_DEBUG_WIN32 = support.Py_DEBUG and sys.platform == 'win32' | ||
| @@ -128,6 +128,13 @@ def data_file(*name): | ||
| SIGNED_CERTFILE_ECC = data_file("keycertecc.pem") | ||
| SIGNED_CERTFILE_ECC_HOSTNAME = 'localhost-ecc' | ||
| # A custom testcase, extracted from `rfc5280::aki::leaf-missing-aki` in x509-limbo: | ||
| # The leaf (server) certificate has no AKI, which is forbidden under RFC 5280. | ||
| # See: https://x509-limbo.com/testcases/rfc5280/#rfc5280akileaf-missing-aki | ||
| LEAF_MISSING_AKI_CERTFILE = data_file("leaf-missing-aki.keycert.pem") | ||
| LEAF_MISSING_AKI_CERTFILE_HOSTNAME = "example.com" | ||
| LEAF_MISSING_AKI_CA = data_file("leaf-missing-aki.ca.pem") | ||
| # Same certificate as pycacert.pem, but without extra text in file | ||
| SIGNING_CA = data_file("capath", "ceff1710.0") | ||
| # cert with all kinds of subject alt names | ||
| @@ -2949,6 +2956,36 @@ def test_ecc_cert(self): | ||
| cipher = s.cipher()[0].split('-') | ||
| self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA')) | ||
| def test_verify_strict(self): | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @sethmlarson This test provides a backstop check on | ||
| # verification fails by default, since the server cert is non-conforming | ||
| client_context = ssl.create_default_context() | ||
| client_context.load_verify_locations(LEAF_MISSING_AKI_CA) | ||
| hostname = LEAF_MISSING_AKI_CERTFILE_HOSTNAME | ||
| server_context = ssl.create_default_context(purpose=Purpose.CLIENT_AUTH) | ||
| server_context.load_cert_chain(LEAF_MISSING_AKI_CERTFILE) | ||
| server = ThreadedEchoServer(context=server_context, chatty=True) | ||
| with server: | ||
| with client_context.wrap_socket(socket.socket(), | ||
| server_hostname=hostname) as s: | ||
| with self.assertRaises(ssl.SSLCertVerificationError): | ||
| s.connect((HOST, server.port)) | ||
| # explicitly disabling VERIFY_X509_STRICT allows it to succeed | ||
| client_context = ssl.create_default_context() | ||
| client_context.load_verify_locations(LEAF_MISSING_AKI_CA) | ||
| client_context.verify_flags &= ~ssl.VERIFY_X509_STRICT | ||
| server_context = ssl.create_default_context(purpose=Purpose.CLIENT_AUTH) | ||
| server_context.load_cert_chain(LEAF_MISSING_AKI_CERTFILE) | ||
| server = ThreadedEchoServer(context=server_context, chatty=True) | ||
| with server: | ||
| with client_context.wrap_socket(socket.socket(), | ||
| server_hostname=hostname) as s: | ||
| s.connect((HOST, server.port)) | ||
| cert = s.getpeercert() | ||
| self.assertTrue(cert, "Can't get peer certificate.") | ||
| def test_dual_rsa_ecc(self): | ||
| client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
| client_context.load_verify_locations(SIGNING_CA) | ||