gh-109945: Enable spec of multiple curves/groups for TLS by planetf1 · Pull Request #119244 · python/cpython · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/ssl.rst
20 changes: 19 additions & 1 deletion Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,11 +1375,29 @@ def test_set_ecdh_curve(self):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.set_ecdh_curve("prime256v1")
ctx.set_ecdh_curve(b"prime256v1")
# Only OpenSSL 3 and above supported for multiple curves
if (IS_OPENSSL_3_0_0 >= 3):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IS_OPENSSL_3_0_0 is a boolean, meaning this branch will always fail?

ctx.set_ecdh_curve("prime256v1:brainpoolP384r1")
ctx.set_ecdh_curve(b"prime256v1:brainpoolP384r1")
self.assertRaises(TypeError, ctx.set_ecdh_curve)
self.assertRaises(TypeError, ctx.set_ecdh_curve, None)
self.assertRaises(ValueError, ctx.set_ecdh_curve, "foo")
self.assertRaises(ValueError, ctx.set_ecdh_curve, b"foo")

# Multiple bad curves should cause error for any OpenSSL version
self.assertRaises(ValueError, ctx.set_ecdh_curve, "foo:bar")
self.assertRaises(ValueError, ctx.set_ecdh_curve, b"foo:bar")
self.assertRaises(ValueError, ctx.set_ecdh_curve, "prime256v1:bar")
self.assertRaises(ValueError, ctx.set_ecdh_curve, b"prime256v1:bar")
self.assertRaises(ValueError, ctx.set_ecdh_curve, "foo:prime256v1")
self.assertRaises(ValueError, ctx.set_ecdh_curve, b"foo:prime256v1")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, ":")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's up with the commented out test cases? are these not valuable? it seems like a set of edge cases worth covering to define behavior on unusual inputs.

#self.assertRaises(ValueError, ctx.set_ecdh_curve, b":")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, "::")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, b"::")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, "prime256v1:")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, b"prime256v1:")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, ":prime256v1")
#self.assertRaises(ValueError, ctx.set_ecdh_curve, b":prime256v1")
def test_sni_callback(self):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds support for multiple curves to be specified in SSLContext.set_ecdh_curve() for OpenSSL 3.0 and above by setting curve_name to a colon separated list of curves. This allows multiple curves to be passed on a TLS client hello.
11 changes: 7 additions & 4 deletions Modules/_ssl.c