Skip to content

gh-117784: Only reference PHA functions ifndef SSL_VERIFY_POST_HANDSHAKE #117785

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

Merged
merged 6 commits into from
Jul 1, 2024

Conversation

WillChilds-Klein
Copy link
Contributor

@WillChilds-Klein WillChilds-Klein commented Apr 11, 2024

Notes

AWS-LC recently defined a new configuration macro OPENSSL_NO_TLS_PHA to signal lack of support for TLSv1.3 post-handshake authentication. Other cryptography libraries may find this useful. We then adjust Modules/_ssl.c to detect this macro, guarding usages of PHA-related functions. We also update two PSK tests to generate client/server contexts with test_ssl.py's conventional testing_context() utility.

This pull request implements Issue #117784.

@arhadthedev arhadthedev added type-feature A feature request or enhancement extension-modules C modules in the Modules dir topic-SSL and removed type-feature A feature request or enhancement extension-modules C modules in the Modules dir labels Apr 12, 2024
@WillChilds-Klein WillChilds-Klein changed the title gh-117784: Only reference PHA functions ifndef OPENSSL_NO_PHA gh-117784: Only reference PHA functions ifndef OPENSSL_NO_TLS_PHA Apr 17, 2024
@WillChilds-Klein
Copy link
Contributor Author

My apologies on the force-push in this draft. I inadvertently rebased latest from upstream main. No significant commit history was lost; I'll refrain from rebasing main again on this PR.

@WillChilds-Klein WillChilds-Klein marked this pull request as ready for review April 19, 2024 17:36
@WillChilds-Klein
Copy link
Contributor Author

Hi @encukou and @gpshead, do you have any thoughts on this PR?

@encukou
Copy link
Member

encukou commented Jun 21, 2024

I'm not a SSL expert, but I'm concerned about relying on an OPENSSL_* macro that doesn't come from the OpenSSL project. Not sure if we have any precedent for that -- it looks like the other OpenSSL-only things use #ifdef with macros that OpenSSL defines.

Does AWS-LC still define SSL_VERIFY_POST_HANDSHAKE?

@WillChilds-Klein WillChilds-Klein changed the title gh-117784: Only reference PHA functions ifndef OPENSSL_NO_TLS_PHA gh-117784: Only reference PHA functions ifndef SSL_VERIFY_POST_HANDSHAKE Jun 26, 2024
WillChilds-Klein added a commit to aws/aws-lc that referenced this pull request Jun 26, 2024
PR #1526 introduced the `OPENSSL_NO_TLS_PHA` directive mostly for the
purposes of AWS-LC's compatibility with CPython, but in [cpython PR
#117785](python/cpython#117785) @encukou points
out that detecting the absence of OpenSSL's own
`SSL_VERIFY_POST_HANDSHAKE` directive is sufficient. This change removes
AWS-LC's `OPENSSL_NO_TLS_PHA` directive in favor of detecting absence of
`SSL_VERIFY_POST_HANDSHAKE`.
@WillChilds-Klein
Copy link
Contributor Author

Good call @encukou. Neither AWS-LC nor BoringSSL define SSL_VERIFY_POST_HANDSHAKE, so lack of that macro can be used to detect lack of PHA support. I've updated AWS-LC's CI and this PR accordingly.

@@ -4364,14 +4364,14 @@ def test_session_handling(self):
def test_psk(self):
psk = bytes.fromhex('deadbeef')

client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client_context, server_context, _ = testing_context()
Copy link
Member

@encukou encukou Jun 27, 2024

Choose a reason for hiding this comment

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

Is this change needed?
Not being an OpenSSL expert, I'd rather avoid having to review it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's required for this test to pass when built against AWS-LC, but I'll remove it to conform to your guidance here:

IMO we could get to the point where you can get CPython to compile with AWS-LC without special-casing it (i.e. no Py_OPENSSL_IS_AWSLC), but relevant test cases still fail.
You’ll still need a patch, but a more focused one.

Modules/_ssl.c Outdated
@@ -187,6 +187,11 @@ extern const SSL_METHOD *TLSv1_2_method(void);
#endif


#if !defined(SSL_VERIFY_POST_HANDSHAKE) || !defined(TLS1_3_VERSION) || defined(OPENSSL_NO_TLS1_3)
#define PY_SSL_NO_POST_HS_AUTH
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a positive name: it is always used with ! later and double negatives are harder to read.

Perhaps PySSL_HAVE_POST_HS_AUTH

@@ -3576,7 +3582,7 @@ set_maximum_version(PySSLContext *self, PyObject *arg, void *c)
return set_min_max_proto_version(self, arg, 1);
}

#ifdef TLS1_3_VERSION
#if defined(TLS1_3_VERSION) && !defined(OPENSSL_NO_TLS1_3)
Copy link
Member

Choose a reason for hiding this comment

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

Are tickets used only for post-handshake authentication? From the docs it looks like a separate TLSv1.3 feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, tickets are used for session resumption and are unrelated to post-handshake authentication. I believe get_num_tickets pertains to a post-handshake message added in TLSv1.3. SSL_CTX_get_num_tickets's docs indicate as much.

This change just updates that guard to honor OpenSSL's OPENSSL_NO_TLS1_3 as other parts of _ssl.c already do.

@WillChilds-Klein WillChilds-Klein requested a review from encukou June 28, 2024 22:17
@encukou encukou merged commit 56a3ce2 into python:main Jul 1, 2024
38 checks passed
@WillChilds-Klein WillChilds-Klein deleted the detect-no-pha branch July 1, 2024 15:32
@WillChilds-Klein
Copy link
Contributor Author

Thank you @encukou! Would it be possible to backport this to 3.13? I see that 3.12 is currently in "bugfix", so I assume this patch isn't applicable to <= 3.12.

WillChilds-Klein added a commit to WillChilds-Klein/aws-lc that referenced this pull request Jul 1, 2024
As of [CPython PR #117785][1], CPython can now build against AWS-LC
without any source code modifications. The only patches we still require
are to configure the build and work around ([expected][2]) test
failures.

[1]: python/cpython#117785
[2]: https://discuss.python.org/t/support-building-ssl-and-hashlib-modules-against-aws-lc/44505/4
WillChilds-Klein added a commit to aws/aws-lc that referenced this pull request Jul 1, 2024
 [CPython PR #117785][1], CPython can now build against AWS-LC
without any source code modifications. The only patches we still require
are to configure the build and work around ([expected][2]) test
failures.

[1]: python/cpython#117785
[2]:
https://discuss.python.org/t/support-building-ssl-and-hashlib-modules-against-aws-lc/44505/4
Akasurde pushed a commit to Akasurde/cpython that referenced this pull request Jul 3, 2024
…HANDSHAKE (pythonGH-117785)

With this change, builds with OpenSSL forks that don't have this functionalty
(like AWS-LC or BoringSSL) will require less patching.
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…HANDSHAKE (pythonGH-117785)

With this change, builds with OpenSSL forks that don't have this functionalty
(like AWS-LC or BoringSSL) will require less patching.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…HANDSHAKE (pythonGH-117785)

With this change, builds with OpenSSL forks that don't have this functionalty
(like AWS-LC or BoringSSL) will require less patching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants