-
Notifications
You must be signed in to change notification settings - Fork 81
Closed
Description
Summary
rustls-webpki's EndEntityCert::dns_names iterator returns an error when called on a certificate generated using cloudflare/cfssl and converted from PEM to DER using the openssl command-line tool. Meanwhile, Go's crypto/x509 package successfully parses the DNS names.
Both crypto/x509 and rustls-webpki do successfully validate these certificates.
Details
rustls-webpkiversions: This issue occurs with both v0.101.4 and v0.102.0-alpha-1 ofrustls-webpki.- Presence or lack of a common name: This issue occurs when a certificate is generated with or without a common name field, although v0.102.0-alpha.1 emits a different error when there is no common name (
TrailingData(CommonNameOuter)rather thanBadDer).
Reproduction
I've written a reproduction for this issue in https://github.com/hawkw/rustls-webpki-repro. The reproduction includes:
- a Rust program that attempts to read the cert's DNS names using
rustls-webpkiv0.101.4 and v0.102.0-alpha.1 - a Go program that does the same thing using the Go
crypto/x509package - the certificates themselves
- a Bash script for generating the certificates.
I'm not really a TLS or ASN.1 expert, so please let me know if there's any additional information I can provide. Thanks!
Go program output
The Go program included in the repro emits the following output:
$ go run repro
=== Path: testdata/no-cn-test-ca1/crt.der===
--- go crypto/x509 ---
Verified valid for no-cn.test.com
Subject:
NotBefore: 2023-09-06 17:21:00 +0000 UTC
NotAfter: 2033-09-03 17:21:00 +0000 UTC
printing DNS names...
DNSNames[0]: no-cn.test.com
=== Path: testdata/cn-test-ca1/crt.der===
--- go crypto/x509 ---
Verified valid for cn.test.com
Subject: CN=cn.test.com
NotBefore: 2023-09-06 17:21:00 +0000 UTC
NotAfter: 2033-09-03 17:21:00 +0000 UTC
printing DNS names...
DNSNames[0]: cn.test.com
Rust repro output
The Rust repro emits the following output:
$ cargo run
Compiling rustls-webpki-repro v0.1.0 (/home/eliza/Code/rustls-webpki-repro)
Finished dev [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/rustls-webpki-repro`
=== Path: testdata/no-cn-test-ca1/crt.der ===
--- rustls-webpki v0.101.4 ---
Verified valid for no-cn.test.com
printing DNS names...
Error: BadDer
--- rustls-webpki v0.102.0-alpha.1 ---
Verified valid for no-cn.test.com
printing DNS names...
Error: TrailingData(CommonNameOuter)
=== Path: testdata/cn-test-ca1/crt.der ===
--- rustls-webpki v0.101.4 ---
Verified valid for cn.test.com
printing DNS names...
Error: BadDer
--- rustls-webpki v0.102.0-alpha.1 ---
Verified valid for cn.test.com
printing DNS names...
Error: BadDer
Expected output
I would expect the Rust program to instead output something more similar to the Go program, like:
$ cargo run
Compiling rustls-webpki-repro v0.1.0 (/home/eliza/Code/rustls-webpki-repro)
Finished dev [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/rustls-webpki-repro`
=== Path: testdata/no-cn-test-ca1/crt.der ===
--- rustls-webpki v0.101.4 ---
Verified valid for no-cn.test.com
printing DNS names...
dns_names[0]: no-cn.test.com
--- rustls-webpki v0.102.0-alpha.1 ---
Verified valid for no-cn.test.com
printing DNS names...
dns_names[0]: no-cn.test.com
=== Path: testdata/cn-test-ca1/crt.der ===
--- rustls-webpki v0.101.4 ---
Verified valid for cn.test.com
printing DNS names...
dns_names[0]: cn.test.com
--- rustls-webpki v0.102.0-alpha.1 ---
Verified valid for cn.test.com
printing DNS names...
dns_names[0]: cn.test.comReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels