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(tls): Add rustls-platform-verifier support #1974

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tls = ["dep:rustls-pemfile", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "toki
tls-roots = ["tls-native-roots"] # Deprecated. Please use `tls-native-roots` instead.
tls-native-roots = ["tls", "channel", "dep:rustls-native-certs"]
tls-webpki-roots = ["tls", "channel", "dep:webpki-roots"]
tls-platform-verifier = ["tls", "channel", "dep:rustls-platform-verifier"]
router = ["dep:axum", "dep:tower", "tower?/util"]
server = [
"router",
Expand Down Expand Up @@ -90,6 +91,7 @@ axum = {version = "0.7", default-features = false, optional = true}
# rustls
rustls-pemfile = { version = "2.0", optional = true }
rustls-native-certs = { version = "0.8", optional = true }
rustls-platform-verifier = { version = "0.3", optional = true }
tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "tls12", "ring"], optional = true }
webpki-roots = { version = "0.26", optional = true }

Expand Down
4 changes: 4 additions & 0 deletions tonic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
//! [`rustls-native-certs`] crate. Not enabled by default.
//! - `tls-webpki-roots`: Add the standard trust roots from the [`webpki-roots`] crate to
//! `rustls`-based gRPC clients. Not enabled by default.
//! - `tls-platform-verifier`: Uses the operating system’s certificate facilities to verify
//! the validity of TLS certificates using the [`rustls-platform-verifier`] crate. Not
//! enabled by default.
//! - `prost`: Enables the [`prost`] based gRPC [`Codec`] implementation. Enabled by default.
//! - `gzip`: Enables compressing requests, responses, and streams. Depends on [`flate2`].
//! Not enabled by default.
Expand Down Expand Up @@ -80,6 +83,7 @@
//! [`transport`]: transport/index.html
//! [`rustls-native-certs`]: https://docs.rs/rustls-native-certs
//! [`webpki-roots`]: https://docs.rs/webpki-roots
//! [`rustls-platform-verifier`]: https://docs.rs/rustls-platform-verifier
//! [`flate2`]: https://docs.rs/flate2
//! [`zstd`]: https://docs.rs/zstd

Expand Down
9 changes: 9 additions & 0 deletions tonic/src/transport/channel/service/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@
add_certs_from_pem(&mut Cursor::new(cert), &mut roots)?;
}

#[cfg(feature = "tls-platform-verifier")]
let builder = builder
.dangerous()
.with_custom_certificate_verifier(Arc::new(
rustls_platform_verifier::Verifier::new_with_extra_roots(roots.roots),

Check failure on line 65 in tonic/src/transport/channel/service/tls.rs

View workflow job for this annotation

GitHub Actions / check (macOS-latest)

no function or associated item named `new_with_extra_roots` found for struct `Verifier` in the current scope

Check failure on line 65 in tonic/src/transport/channel/service/tls.rs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

no function or associated item named `new_with_extra_roots` found for struct `Verifier` in the current scope
));

#[cfg(not(feature = "tls-platform-verifier"))]
let builder = builder.with_root_certificates(roots);

let mut config = match identity {
Some(identity) => {
let (client_cert, client_key) = load_identity(identity)?;
Expand Down
Loading