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

use rustls-webpki instead of linkerd/webpki #2465

Merged
merged 5 commits into from
Sep 11, 2023
Merged
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
16 changes: 13 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1408,11 +1408,11 @@ dependencies = [
"linkerd-tls-test-util",
"ring",
"rustls-pemfile",
"rustls-webpki",
"thiserror",
"tokio",
"tokio-rustls",
"tracing",
"webpki",
]

[[package]]
Expand Down Expand Up @@ -2462,6 +2462,15 @@ dependencies = [
"base64",
]

[[package]]
name = "rustls-webpki"
version = "0.101.5"
source = "git+https://github.com/cpu/webpki?rev=702d57f444e3f7d743277524e832a2363290ec4d#702d57f444e3f7d743277524e832a2363290ec4d"
dependencies = [
"ring",
"untrusted",
]

[[package]]
name = "rustversion"
version = "1.0.11"
Expand Down Expand Up @@ -3149,8 +3158,9 @@ dependencies = [

[[package]]
name = "webpki"
version = "0.22.0"
source = "git+https://github.com/linkerd/webpki?branch=cert-dns-names-0.22#a26def03ec88d3b69542ccd2f0073369ecedc4f9"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e"
dependencies = [
"ring",
"untrusted",
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ debug = false
lto = true

[patch.crates-io]
webpki = { git = "https://github.com/linkerd/webpki", branch = "cert-dns-names-0.22" }
# remove this patch when https://github.com/rustls/webpki/pull/170 is published!
rustls-webpki = { git = "https://github.com/cpu/webpki", rev = "702d57f444e3f7d743277524e832a2363290ec4d" }
7 changes: 3 additions & 4 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ skip-tree = [
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]

[sources.allow-org]
github = [
"linkerd",
allow-git = [
# remove this when https://github.com/rustls/webpki/pull/170 is published!
"https://github.com/cpu/webpki",
]
2 changes: 1 addition & 1 deletion linkerd/meshtls/rustls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ linkerd-tls = { path = "../../tls" }
linkerd-tls-test-util = { path = "../../tls/test-util", optional = true }
ring = { version = "0.16", features = ["std"] }
rustls-pemfile = "1.0"
rustls-webpki = { version = "0.101.5", features = [ "std"] }
thiserror = "1"
tokio = { version = "1", features = ["macros", "rt", "sync"] }
tokio-rustls = { version = "0.23", features = ["dangerous_configuration"] }
tracing = "0.1"
webpki = "0.22"

[dev-dependencies]
linkerd-tls-test-util = { path = "../../tls/test-util" }
10 changes: 6 additions & 4 deletions linkerd/meshtls/rustls/src/creds/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ impl rustls::server::ResolvesServerCert for CertResolver {
hello: rustls::server::ClientHello<'_>,
) -> Option<Arc<rustls::sign::CertifiedKey>> {
let server_name = match hello.server_name() {
Some(name) => webpki::DnsNameRef::try_from_ascii_str(name)
.expect("server name must be a valid server name"),

Some(name) => {
let name = webpki::DnsNameRef::try_from_ascii_str(name)
.expect("server name must be a valid server name");
webpki::SubjectNameRef::DnsName(name)
}
None => {
debug!("no SNI -> no certificate");
return None;
Expand All @@ -251,7 +253,7 @@ impl rustls::server::ResolvesServerCert for CertResolver {
// Verify that our certificate is valid for the given SNI name.
let c = self.0.cert.first()?;
if let Err(error) = webpki::EndEntityCert::try_from(c.as_ref())
.and_then(|c| c.verify_is_valid_for_dns_name(server_name))
.and_then(|c| c.verify_is_valid_for_subject_name(server_name))
{
debug!(%error, "Local certificate is not valid for SNI");
return None;
Expand Down
17 changes: 6 additions & 11 deletions linkerd/meshtls/rustls/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,13 @@ fn client_identity<I>(tls: &tokio_rustls::server::TlsStream<I>) -> Option<Client
let certs = session.peer_certificates()?;
let c = certs.first().map(Certificate::as_ref)?;
let end_cert = webpki::EndEntityCert::try_from(c).ok()?;
let dns_names = end_cert.dns_names().ok()?;

match dns_names.first()? {
webpki::GeneralDnsNameRef::DnsName(n) => {
let s: &str = (*n).into();
s.parse().ok().map(ClientId)
}
webpki::GeneralDnsNameRef::Wildcard(_) => {
// Wildcards can perhaps be handled in a future path...
None
}
let name: &str = end_cert.dns_names().ok()?.next().map(Into::into)?;
if name == "*" {
// Wildcards can perhaps be handled in a future path...
return None;
}

name.parse().ok().map(ClientId)
}

// === impl ServerIo ===
Expand Down