Skip to content
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

feat(s2n-tls-hyper): Add support for negotiating HTTP/2 #4924

Merged
merged 9 commits into from
Dec 10, 2024

Conversation

goatgoose
Copy link
Contributor

@goatgoose goatgoose commented Nov 21, 2024

Description of changes:

Currently s2n-tls-hyper can only negotiate HTTP/1. This PR adds support for HTTP/2.

HTTP/2 is negotiated at the TLS level, via the ALPN extension. After the hyper client completes the TLS handshake, the negotiated ALPN value is checked. If HTTP/2 was negotiated, HTTP/2 is enabled in hyper by updating the returned Connected struct.

Call-outs:

I currently attempt to always negotiate HTTP/2 by just always sending HTTP/2 in the ALPN. This means that ALPN values manually set on the config will be ignored. I think this is fine though, since it seems like s2n-tls-hyper should be the one deciding which ALPN values to send. We can also later add a way to configure the ALPN in s2n-tls-hyper, if we need a way to opt-out of HTTP/2 or something.

Testing:

  • Added a test that successfully negotiates HTTP/2.
  • Added a test that makes sure the ALPN extension is properly overridden by s2n-tls-hyper.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@goatgoose goatgoose force-pushed the hyper-http2 branch 3 times, most recently from 8bd2b37 to 552530e Compare November 21, 2024 20:50
@goatgoose goatgoose force-pushed the hyper-http2 branch 2 times, most recently from 9139ddf to fcf21c3 Compare November 21, 2024 21:33
@goatgoose goatgoose marked this pull request as ready for review November 21, 2024 21:57
@goatgoose goatgoose force-pushed the hyper-http2 branch 2 times, most recently from 8ec55f2 to 65aeac2 Compare November 22, 2024 02:34
@goatgoose goatgoose requested a review from lrstewart November 25, 2024 17:28
bindings/rust/s2n-tls-hyper/Cargo.toml Outdated Show resolved Hide resolved
bindings/rust/s2n-tls-hyper/src/connector.rs Outdated Show resolved Hide resolved
match conn.application_protocol() {
// Inform hyper that HTTP/2 was negotiated in the ALPN.
Some(b"h2") => connected.negotiated_h2(),
_ => connected,
Copy link
Contributor Author

@goatgoose goatgoose Dec 3, 2024

Choose a reason for hiding this comment

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

Ideally we could assert that the negotiated application protocol was something we expected here. However, we can't return an error since this function doesn't return an error. We could panic, however misbehaved servers could technically return whatever ALPN value they want, whether or not the client attempted to negotiate it. So panicking here seems wrong, since it's outside of the user's control. It seemed better to just attempt HTTP/1 if an unexpected protocol was negotiated.

Comment on lines +133 to +136
// https://datatracker.ietf.org/doc/html/rfc7301#section-3.2
// In the event that the server supports no
// protocols that the client advertises, then the server SHALL respond
// with a fatal "no_application_protocol" alert.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@goatgoose goatgoose enabled auto-merge (squash) December 10, 2024 17:40
@goatgoose goatgoose merged commit 0fef0f5 into aws:main Dec 10, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants