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

Enforce https for native-tls backend #2316

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions rust-runtime/aws-smithy-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,18 @@ pub mod conns {
/// Return a default HTTPS connector backed by the `hyper_tls` crate.
///
/// It requires a minimum TLS version of 1.2.
/// It allows you to connect to both `http` and `https` URLs.
/// It allows only https connections.
/// To enable http connections, call `https_only(false)` on the retured NativeTls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// To enable http connections, call `https_only(false)` on the retured NativeTls.
/// To enable http connections, call `https_only(false)` on the retured `NativeTls`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also:

  • Typo retured -> returned
  • Suggestion https_only(false) -> .https_only(false)

pub fn native_tls() -> NativeTls {
let mut tls = hyper_tls::native_tls::TlsConnector::builder();
let tls = tls
.min_protocol_version(Some(hyper_tls::native_tls::Protocol::Tlsv12))
.build()
.unwrap_or_else(|e| panic!("Error while creating TLS connector: {}", e));
let http = hyper::client::HttpConnector::new();
hyper_tls::HttpsConnector::from((http, tls.into()))
let mut https = hyper_tls::HttpsConnector::from((http, tls.into()));
https.https_only(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we'd want the same change in HTTP_NATIVE_ROOTS as well, a few lines above.

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking about that, but the hyper_rustls::HttpsConnector doesn't seem to provide a way for customers to also allow http. So the original concern is still valid here.

Copy link
Contributor

@LukeMathWalker LukeMathWalker Feb 6, 2023

Choose a reason for hiding this comment

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

I'd be quite wary of having diverging behaviour on something like this between the two TLS backends we support - that can turn out to be quite surprising for users.

Copy link
Author

Choose a reason for hiding this comment

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

If you think that consistency is (more) important in this case, then this PR can be scrapped.

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion here is to apply the change to both backends, rather than to native-tls only.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it looks like we would need a breaking change for this, either returning the builder from fn https() or taking an argument for allow_http: bool on it, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Made a PR for this in hyper-rustls here.

Copy link
Contributor

@LukeMathWalker LukeMathWalker Feb 7, 2023

Choose a reason for hiding this comment

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

rustls uses a type-state builder, which requires configuration to be supplied in a specific order.
The "step" that you are currently in bleeds through the type signature as well.
Returning a partially configured rustls HTTPS connector doesn't look like an option - we need to provide one set of configuration with good defaults and then explain in the documentation section how they could configure it otherwise (linking to rustls' own docs).

https
}

#[cfg(feature = "native-tls")]
Expand Down