Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit a6a4252

Browse files
committed
Only the first TLS certificate is used rather than the full chain (#3)
1 parent 527202b commit a6a4252

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/config/certificate.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl ResolvesServerCert for CertificateResolver {
5151
}
5252

5353
impl Config {
54-
pub fn rustls_certificate(&self, cert_id: &str) -> super::Result<Certificate> {
55-
certs(&mut Cursor::new(self.file_contents((
54+
pub fn rustls_certificate(&self, cert_id: &str) -> super::Result<Vec<Certificate>> {
55+
let certs = certs(&mut Cursor::new(self.file_contents((
5656
"certificate",
5757
cert_id,
5858
"cert",
@@ -62,8 +62,15 @@ impl Config {
6262
})?
6363
.into_iter()
6464
.map(Certificate)
65-
.next()
66-
.ok_or_else(|| format!("No certificates found in \"certificate.{cert_id}.cert\"."))
65+
.collect::<Vec<_>>();
66+
67+
if !certs.is_empty() {
68+
Ok(certs)
69+
} else {
70+
Err(format!(
71+
"No certificates found in \"certificate.{cert_id}.cert\"."
72+
))
73+
}
6774
}
6875

6976
pub fn rustls_private_key(&self, cert_id: &str) -> super::Result<PrivateKey> {

src/config/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Config {
116116
value,
117117
match self.value((prefix, "certificate")) {
118118
Some(sni_cert_id) if sni_cert_id != cert_id => CertifiedKey {
119-
cert: vec![self.rustls_certificate(sni_cert_id)?],
119+
cert: self.rustls_certificate(sni_cert_id)?,
120120
key: any_supported_type(&self.rustls_private_key(sni_cert_id)?)
121121
.map_err(|err| {
122122
format!(
@@ -127,7 +127,7 @@ impl Config {
127127
sct_list: None,
128128
},
129129
_ => CertifiedKey {
130-
cert: vec![cert.clone()],
130+
cert: cert.clone(),
131131
key:
132132
any_supported_type(&pki).map_err(|err| {
133133
format!(
@@ -147,7 +147,7 @@ impl Config {
147147

148148
// Add default certificate
149149
let default_cert = Some(Arc::new(CertifiedKey {
150-
cert: vec![cert],
150+
cert,
151151
key: any_supported_type(&pki)
152152
.map_err(|err| format!("Failed to sign certificate id {cert_id:?}: {err}"))?,
153153
ocsp: None,

0 commit comments

Comments
 (0)