| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -263,7 +263,9 @@ def utc_offset(): #NOTE: ignore issues like #1647654 | |
|
|
||
| def test_wrap_socket(sock, *, | ||
| cert_reqs=ssl.CERT_NONE, ca_certs=None, | ||
| ciphers=None, certfile=None, keyfile=None, | ||
| ciphers=None, ciphersuites=None, | ||
| min_version=None, max_version=None, | ||
| certfile=None, keyfile=None, | ||
| **kwargs): | ||
| if not kwargs.get("server_side"): | ||
| kwargs["server_hostname"] = SIGNED_CERTFILE_HOSTNAME | ||
| Expand All | @@ -280,6 +282,12 @@ def test_wrap_socket(sock, *, | |
| context.load_cert_chain(certfile, keyfile) | ||
| if ciphers is not None: | ||
| context.set_ciphers(ciphers) | ||
| if ciphersuites is not None: | ||
| context.set_ciphersuites(ciphersuites) | ||
| if min_version is not None: | ||
| context.minimum_version = min_version | ||
| if max_version is not None: | ||
| context.maximum_version = max_version | ||
| return context.wrap_socket(sock, **kwargs) | ||
|
|
||
|
|
||
| Expand Down Expand Up | @@ -2238,6 +2246,68 @@ def test_transport_eof(self): | |
| self.assertRaises(ssl.SSLEOFError, sslobj.read) | ||
|
|
||
|
|
||
| @unittest.skipUnless(has_tls_version('TLSv1_3'), "TLS 1.3 is not available") | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityNote to myself: change the requires_tls_version decorator so that it works.
Sorry, something went wrong.
All reactions
|
||
| class SimpleBackgroundTestsTLS_1_3(unittest.TestCase): | ||
| """Tests that connect to a simple server running in the background.""" | ||
|
|
||
| def setUp(self): | ||
| server_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
| ciphers = [cipher['name'] for cipher in server_ctx.get_ciphers() | ||
| if cipher['protocol'] == 'TLSv1.3'] | ||
|
|
||
| if not ciphers: | ||
| self.skipTest("No cipher supports TLSv1.3") | ||
|
|
||
| self.matching_cipher = ciphers[0] | ||
| # Some tests need at least two ciphers, and are responsible | ||
| # to skip themselves if matching_cipher == mismatched_cipher. | ||
| self.mismatched_cipher = ciphers[-1] | ||
|
|
||
| server_ctx.set_ciphersuites(self.matching_cipher) | ||
| server_ctx.load_cert_chain(SIGNED_CERTFILE) | ||
| server = ThreadedEchoServer(context=server_ctx) | ||
| self.enterContext(server) | ||
| self.server_addr = (HOST, server.port) | ||
|
|
||
| def test_ciphersuites(self): | ||
| # Test unrecognized TLS 1.3 cipher suite name | ||
| with ( | ||
| socket.socket(socket.AF_INET) as sock, | ||
| self.assertRaisesRegex(ssl.SSLError, | ||
| "No cipher suite can be selected") | ||
| ): | ||
| test_wrap_socket(sock, cert_reqs=ssl.CERT_NONE, | ||
| ciphersuites="XXX", | ||
| min_version=ssl.TLSVersion.TLSv1_3) | ||
|
|
||
| # Test successful TLS 1.3 handshake | ||
| with test_wrap_socket(socket.socket(socket.AF_INET), | ||
| cert_reqs=ssl.CERT_NONE, | ||
| ciphersuites=self.matching_cipher, | ||
| min_version=ssl.TLSVersion.TLSv1_3) as s: | ||
| s.connect(self.server_addr) | ||
| self.assertEqual(s.cipher()[0], self.matching_cipher) | ||
|
|
||
| def test_ciphersuite_downgrade(self): | ||
| with test_wrap_socket(socket.socket(socket.AF_INET), | ||
| cert_reqs=ssl.CERT_NONE, | ||
| ciphersuites=self.matching_cipher, | ||
| 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') | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis 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.
All reactions
|
||
|
|
||
| def test_ciphersuite_mismatch(self): | ||
| if self.matching_cipher == self.mismatched_cipher: | ||
| self.skipTest("Multiple TLS 1.3 ciphers are not available") | ||
|
Comment thread
picnixz marked this conversation as resolved.
|
||
|
|
||
| with test_wrap_socket(socket.socket(socket.AF_INET), | ||
| cert_reqs=ssl.CERT_NONE, | ||
| ciphersuites=self.mismatched_cipher, | ||
| min_version=ssl.TLSVersion.TLSv1_3) as s: | ||
| self.assertRaises(ssl.SSLError, s.connect, self.server_addr) | ||
|
|
||
|
|
||
| @support.requires_resource('network') | ||
| class NetworkedTests(unittest.TestCase): | ||
|
|
||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| :class:`~ssl.SSLContext` objects can now set TLS 1.3 cipher suites | ||
| via :meth:`~ssl.SSLContext.set_ciphersuites`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.