-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136306: Add support for SSL groups #136307
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
662d66e
9acb2c3
03072c4
187ff2e
452bdec
9b4066b
a6ad433
aecc96b
05c75a5
304c223
b516200
e0fdd25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ | |
PROTOCOLS = sorted(ssl._PROTOCOL_NAMES) | ||
HOST = socket_helper.HOST | ||
IS_OPENSSL_3_0_0 = ssl.OPENSSL_VERSION_INFO >= (3, 0, 0) | ||
CAN_GET_SELECTED_OPENSSL_GROUP = ssl.OPENSSL_VERSION_INFO >= (3, 2) | ||
CAN_GET_AVAILABLE_OPENSSL_GROUPS = ssl.OPENSSL_VERSION_INFO >= (3, 5) | ||
PY_SSL_DEFAULT_CIPHERS = sysconfig.get_config_var('PY_SSL_DEFAULT_CIPHERS') | ||
|
||
PROTOCOL_TO_TLS_VERSION = {} | ||
|
@@ -960,6 +962,26 @@ def test_get_ciphers(self): | |
len(intersection), 2, f"\ngot: {sorted(names)}\nexpected: {sorted(expected)}" | ||
) | ||
|
||
def test_set_groups(self): | ||
ctx = ssl.create_default_context() | ||
|
||
# Test valid group list | ||
self.assertIsNone(ctx.set_groups('P-256:X25519')) | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Test invalid group list | ||
self.assertRaises(ssl.SSLError, ctx.set_groups, 'P-256:xxx') | ||
|
||
@unittest.skipUnless(CAN_GET_AVAILABLE_OPENSSL_GROUPS, | ||
"OpenSSL version doesn't support getting groups") | ||
def test_get_groups(self): | ||
ctx = ssl.create_default_context() | ||
|
||
# P-256 isn't an IANA name, so it shouldn't be returned by default | ||
self.assertNotIn('P-256', ctx.get_groups()) | ||
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. Is there a default group that is known to always be returned? 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. The set of returned versions varies depending on the OpenSSL version. However, with the default of |
||
|
||
# Aliases like P-256 sbould be returned when include_aliases is set | ||
self.assertIn('P-256', ctx.get_groups(include_aliases=True)) | ||
|
||
def test_options(self): | ||
# Test default SSLContext options | ||
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
|
@@ -2701,6 +2723,8 @@ def server_params_test(client_context, server_context, indata=b"FOO\n", | |
'session_reused': s.session_reused, | ||
'session': s.session, | ||
}) | ||
if CAN_GET_SELECTED_OPENSSL_GROUP: | ||
stats.update({'group': s.group()}) | ||
s.close() | ||
stats['server_alpn_protocols'] = server.selected_alpn_protocols | ||
stats['server_shared_ciphers'] = server.shared_ciphers | ||
|
@@ -4126,6 +4150,38 @@ def test_ecdh_curve(self): | |
chatty=True, connectionchatty=True, | ||
sni_name=hostname) | ||
|
||
def test_groups(self): | ||
# server secp384r1, client auto | ||
client_context, server_context, hostname = testing_context() | ||
|
||
server_context.set_groups("secp384r1") | ||
server_context.minimum_version = ssl.TLSVersion.TLSv1_3 | ||
stats = server_params_test(client_context, server_context, | ||
chatty=True, connectionchatty=True, | ||
sni_name=hostname) | ||
if CAN_GET_SELECTED_OPENSSL_GROUP: | ||
self.assertEqual(stats['group'], "secp384r1") | ||
|
||
# server auto, client secp384r1 | ||
client_context, server_context, hostname = testing_context() | ||
client_context.set_groups("secp384r1") | ||
server_context.minimum_version = ssl.TLSVersion.TLSv1_3 | ||
stats = server_params_test(client_context, server_context, | ||
chatty=True, connectionchatty=True, | ||
sni_name=hostname) | ||
if CAN_GET_SELECTED_OPENSSL_GROUP: | ||
self.assertEqual(stats['group'], "secp384r1") | ||
|
||
# server / client curve mismatch | ||
client_context, server_context, hostname = testing_context() | ||
client_context.set_groups("prime256v1") | ||
server_context.set_groups("secp384r1") | ||
server_context.minimum_version = ssl.TLSVersion.TLSv1_3 | ||
with self.assertRaises(ssl.SSLError): | ||
server_params_test(client_context, server_context, | ||
chatty=True, connectionchatty=True, | ||
sni_name=hostname) | ||
|
||
def test_selected_alpn_protocol(self): | ||
# selected_alpn_protocol() is None unless ALPN is used. | ||
client_context, server_context, hostname = testing_context() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
:mod:`ssl` can now get and set groups used for key agreement. | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.