Skip to content

Commit cd04d7a

Browse files
authored
use rustls-webpki instead of linkerd/webpki (#2465)
This commit changes the `linkerd-meshtls-rustls` crate to use the upstream `rustls-webpki` crate, maintained by Rustls, rather than our fork of `briansmith/webpki` from GitHub. Since `rustls-webpki` includes the change which was the initial motivation for the `linkerd/webpki` fork (rustls/webpki#42), we can now depend on upstream. Currently, we must take a Git dependency on `rustls-webpki`, since a release including a fix for an issue (rustls/webpki#167) which prevents `rustls-webpki` from parsing our test certificates has not yet been published. Once v0.101.5 of `rustls-webpki` is published (PR see rustls/webpki#170), we can remove the Git dep. For now, I've updated `cargo-deny` to allow the Git dependency.
1 parent 426120a commit cd04d7a

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

Cargo.lock

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,11 +1408,11 @@ dependencies = [
14081408
"linkerd-tls-test-util",
14091409
"ring",
14101410
"rustls-pemfile",
1411+
"rustls-webpki",
14111412
"thiserror",
14121413
"tokio",
14131414
"tokio-rustls",
14141415
"tracing",
1415-
"webpki",
14161416
]
14171417

14181418
[[package]]
@@ -2462,6 +2462,15 @@ dependencies = [
24622462
"base64",
24632463
]
24642464

2465+
[[package]]
2466+
name = "rustls-webpki"
2467+
version = "0.101.5"
2468+
source = "git+https://github.com/cpu/webpki?rev=702d57f444e3f7d743277524e832a2363290ec4d#702d57f444e3f7d743277524e832a2363290ec4d"
2469+
dependencies = [
2470+
"ring",
2471+
"untrusted",
2472+
]
2473+
24652474
[[package]]
24662475
name = "rustversion"
24672476
version = "1.0.11"
@@ -3149,8 +3158,9 @@ dependencies = [
31493158

31503159
[[package]]
31513160
name = "webpki"
3152-
version = "0.22.0"
3153-
source = "git+https://github.com/linkerd/webpki?branch=cert-dns-names-0.22#a26def03ec88d3b69542ccd2f0073369ecedc4f9"
3161+
version = "0.22.1"
3162+
source = "registry+https://github.com/rust-lang/crates.io-index"
3163+
checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e"
31543164
dependencies = [
31553165
"ring",
31563166
"untrusted",

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ debug = false
8282
lto = true
8383

8484
[patch.crates-io]
85-
webpki = { git = "https://github.com/linkerd/webpki", branch = "cert-dns-names-0.22" }
85+
# remove this patch when https://github.com/rustls/webpki/pull/170 is published!
86+
rustls-webpki = { git = "https://github.com/cpu/webpki", rev = "702d57f444e3f7d743277524e832a2363290ec4d" }

deny.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ skip-tree = [
7272
unknown-registry = "deny"
7373
unknown-git = "deny"
7474
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
75-
76-
[sources.allow-org]
77-
github = [
78-
"linkerd",
75+
allow-git = [
76+
# remove this when https://github.com/rustls/webpki/pull/170 is published!
77+
"https://github.com/cpu/webpki",
7978
]

linkerd/meshtls/rustls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ linkerd-tls = { path = "../../tls" }
1919
linkerd-tls-test-util = { path = "../../tls/test-util", optional = true }
2020
ring = { version = "0.16", features = ["std"] }
2121
rustls-pemfile = "1.0"
22+
rustls-webpki = { version = "0.101.5", features = [ "std"] }
2223
thiserror = "1"
2324
tokio = { version = "1", features = ["macros", "rt", "sync"] }
2425
tokio-rustls = { version = "0.23", features = ["dangerous_configuration"] }
2526
tracing = "0.1"
26-
webpki = "0.22"
2727

2828
[dev-dependencies]
2929
linkerd-tls-test-util = { path = "../../tls/test-util" }

linkerd/meshtls/rustls/src/creds/store.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ impl rustls::server::ResolvesServerCert for CertResolver {
239239
hello: rustls::server::ClientHello<'_>,
240240
) -> Option<Arc<rustls::sign::CertifiedKey>> {
241241
let server_name = match hello.server_name() {
242-
Some(name) => webpki::DnsNameRef::try_from_ascii_str(name)
243-
.expect("server name must be a valid server name"),
244-
242+
Some(name) => {
243+
let name = webpki::DnsNameRef::try_from_ascii_str(name)
244+
.expect("server name must be a valid server name");
245+
webpki::SubjectNameRef::DnsName(name)
246+
}
245247
None => {
246248
debug!("no SNI -> no certificate");
247249
return None;
@@ -251,7 +253,7 @@ impl rustls::server::ResolvesServerCert for CertResolver {
251253
// Verify that our certificate is valid for the given SNI name.
252254
let c = self.0.cert.first()?;
253255
if let Err(error) = webpki::EndEntityCert::try_from(c.as_ref())
254-
.and_then(|c| c.verify_is_valid_for_dns_name(server_name))
256+
.and_then(|c| c.verify_is_valid_for_subject_name(server_name))
255257
{
256258
debug!(%error, "Local certificate is not valid for SNI");
257259
return None;

linkerd/meshtls/rustls/src/server.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,13 @@ fn client_identity<I>(tls: &tokio_rustls::server::TlsStream<I>) -> Option<Client
130130
let certs = session.peer_certificates()?;
131131
let c = certs.first().map(Certificate::as_ref)?;
132132
let end_cert = webpki::EndEntityCert::try_from(c).ok()?;
133-
let dns_names = end_cert.dns_names().ok()?;
134-
135-
match dns_names.first()? {
136-
webpki::GeneralDnsNameRef::DnsName(n) => {
137-
let s: &str = (*n).into();
138-
s.parse().ok().map(ClientId)
139-
}
140-
webpki::GeneralDnsNameRef::Wildcard(_) => {
141-
// Wildcards can perhaps be handled in a future path...
142-
None
143-
}
133+
let name: &str = end_cert.dns_names().ok()?.next().map(Into::into)?;
134+
if name == "*" {
135+
// Wildcards can perhaps be handled in a future path...
136+
return None;
144137
}
138+
139+
name.parse().ok().map(ClientId)
145140
}
146141

147142
// === impl ServerIo ===

0 commit comments

Comments
 (0)