-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
gh-109945: Enable spec of multiple curves/groups for TLS #119244
base: main
Are you sure you want to change the base?
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
FYI am aware of the test failure. Will be working on update for that. (apologies for delay) + arranging CLA. |
|
The test failure occurs within test_set_ecdh_curve which tests a follows: This raises two issues a) If the change in this PR is to be included, the unit tests should be updated to also include lists of curves - no problem More relevant is b) The current tests assert that an exception is raised if an invalid curve is specified (which is not in the initial code) There are a few ways of handling this
Not being very familiar with the code I'm interested in feedback as to what the most appropriate way of handling this would be? Is the additional complexity of the first option the most appropriate & desirable? |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
1 similar comment
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
0a9c417
to
07c0a4a
Compare
|
The current PR proposal builds cleanly. However is an area that needs discussion Previously an invalid (no NID) curve would result in a value exception, whilst any other kind of SSL error would not, though it would set the ssl error. This passed tests cleanly. Since we now can have multiple curves, one option is to simple call the underlying SSL function to set the curves. This makes it difficult to distinguish between the two cases, meaning that the code returns a valueerror in both cases (for invalid curves) In working through this, I also noticed that the thread sanitizer checks FAIL when _setSSLError() is called. Before this code change we still did call this, just in less cases, and via a code path that the unix tests didn't check. With the code change the new code (minus the most recent commit) would set this on every exception (as above). My conclusion is that this function isn't thread safe? So is that a more general bug that needs investigation? For now the _setSSLError() is removed, however I think it should be reinstated once understood. |
|
Rebased. Would very much appreciate any review comments . Thanks! |
|
Aware of one doc validation error from my news blurb 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. /home/runner/work/cpython/cpython/build/NEWS:70: WARNING: py:func reference target not found: warnings.filterswarnings |
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
| 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, ":") |
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.
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.
|
FYI - I'm looping in @sethmlarson for additional eyeballs on whether or not they think this makes sense given it is a |
|
Going to also ping @woodruffw and @jvdprng since they're working on an adjacent project. |
| @@ -4399,8 +4400,10 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name) | |||
| SSL_CTX_set_tmp_ecdh(self->ctx, key); | |||
| EC_KEY_free(key); | |||
| #else | |||
| if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) { | |||
| _setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__); | |||
| int res = SSL_CTX_set1_groups_list(self->ctx, PyBytes_AS_STRING(name_bytes)); | |||
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.
SSL_CTX_set1_groups_list also supports another syntax, adding a ? before the curve name makes it "optional", quoting the docs:
If a group name is preceded with the ? character, it will be ignored if an implementation is missing.
This isn't tested in our test suite, it would be useful to test that so future contributors know that syntax exists.
| @@ -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): | |||
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.
IS_OPENSSL_3_0_0 is a boolean, meaning this branch will always fail?
| @@ -1769,6 +1769,10 @@ to speed up repeated connections from the same clients. | |||
| a well-known elliptic curve, for example ``prime256v1`` for a widely | |||
| supported curve. | |||
|
|
|||
| For OpenSSL 3.0 and above *curve_name* parameter can be a colon separated | |||
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.
This will need a "new in version 3.14" admonition.
Thank you for the ping! I'd like to understand the motivation a little better here: is the current cipher suite configuration insufficient? And is there a reason why |
This API is for configuring the curves to offer during ECDH key exchange, not the ciphers. |
Whoops! That makes more sense, although I'm still curious about the intended application here -- IME it's not common for user-level TLS APIs (with the notable exception of OpenSSL) to expose curve selection as a configurable parameter, instead preferring to keep that as a implementation detail of negotiation (with the assumption that the TLS implementation either ensures a baseline level of security or the user configures a higher level "security margin" setting that influences the curve selection.) TL;DR: My basic concern is that this exposes an API that's uncommon among TLS APIs, is a low level option that is typically only influenced by higher level APIs, and is a potential footgun. But one could easily argue that many of OpenSSL's APIs are footguns and thus there is ample precedent for exposing this 🙂 |
|
Quick update - thanks for the review comments - apologies for the delay: just back from a few week's vacation, so will work through & respond specifically. Appreciated. |
Co-authored-by: Martin Schmatz
This change makes it possible to allow multiple groups to be specified in a colon separated string. See issues for more detail
The implementation choice is to modify the existing function rather than introduce a new one.
Changes:
Current Status:
Addressed:
Note to reviewers:
Lib/lib2to3/which I presume should not be checked in