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

backport #2465 and #2470 to v2.203 #2471

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

[[package]]
Expand Down Expand Up @@ -2434,6 +2434,16 @@ dependencies = [
"base64",
]

[[package]]
name = "rustls-webpki"
version = "0.101.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45a27e3b59326c16e23d30aeb7a36a24cc0d29e71d68ff611cdfb4a01d013bed"
dependencies = [
"ring",
"untrusted",
]

[[package]]
name = "rustversion"
version = "1.0.11"
Expand Down Expand Up @@ -3114,8 +3124,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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ debug = false
lto = true

[patch.crates-io]
webpki = { git = "https://github.com/linkerd/webpki", branch = "cert-dns-names-0.22" }
boring = { git = "https://github.com/cloudflare/boring" }
tokio-boring = { git = "https://github.com/cloudflare/boring" }
7 changes: 2 additions & 5 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ skip-tree = [
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = ["https://github.com/cloudflare/boring.git"]

[sources.allow-org]
github = [
"linkerd",
allow-git = [
"https://github.com/cloudflare/boring.git",
]
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