Skip to content

RUST-1083 Add openssl as an optional TLS provider #590

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 13 commits into from
Mar 18, 2022

Conversation

abr-egn
Copy link
Contributor

@abr-egn abr-egn commented Mar 8, 2022

RUST-1083

This adds the openssl-tls feature, which enables TLS connections via openssl rather than rustls. In service of that, I refactored the TLS-handling code into its own module which is conditionally renamed based on the feature flag, making conditional surface area minimal.

Unfortunately, for backwards compatibility rustls can't be made optional, so it's still linked in even when it's not used.

The evergreen auth tests have been updated to run against both TLS crates; in the process of doing that I discovered that the tests previously were ignoring the runtime variable, so I picked that up as well.


fn init_trust() {
static ONCE: Once = Once::new();
ONCE.call_once(openssl_probe::init_ssl_cert_env_vars);
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 turns out that openssl finds the local root certs via environment variables; openssl_probe knows where to look for various OSes and sets those appropriately if they're not already set.

Cargo.toml Outdated
os_info = { version = "3.0.1", default-features = false }
percent-encoding = "2.0.0"
rand = { version = "0.8.3", features = ["small_rng"] }
rustls-pemfile = "0.2.1"
rustls-pemfile = "0.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we revert this extra spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, done.

src/error.rs Outdated
/// Wrapper around [`openssl::ssl::Error`].
#[cfg(feature = "openssl-tls")]
#[error("{0}")]
OpenSSL(Arc<openssl::ssl::Error>),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be cautious about introducing types from pre-1.0 crates in our public API -- maybe we should implement this similarly to the way we implement our DnsResolve error type (i.e. wrap a to_string call on the error)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed. I folded this into the existing Authentication error type rather than introduce a new one.

@abr-egn abr-egn marked this pull request as draft March 8, 2022 19:29
@abr-egn
Copy link
Contributor Author

abr-egn commented Mar 8, 2022

Please hold off for a bit - looks like I need to figure out how to install openssl on windows.

@abr-egn abr-egn force-pushed the RUST-1083/openssl-tls branch 2 times, most recently from c87ad16 to b720535 Compare March 11, 2022 20:17
@abr-egn abr-egn marked this pull request as ready for review March 11, 2022 20:24
@abr-egn
Copy link
Contributor Author

abr-egn commented Mar 11, 2022

Okay, good to go.

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

looks good! just have one question and one comment on error types

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

code LGTM, just need some docs updates

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

LGTM!

@abr-egn abr-egn force-pushed the RUST-1083/openssl-tls branch from 3fd7c8e to 623483a Compare March 18, 2022 16:54
@abr-egn abr-egn merged commit beee61e into mongodb:master Mar 18, 2022
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