Skip to content

Commit 09bb213

Browse files
committed
expect exactly 1 server cert/key
not a bundle of them in the file(s)
1 parent 17989e1 commit 09bb213

File tree

1 file changed

+9
-8
lines changed
  • crates/standalone/src/subcommands

1 file changed

+9
-8
lines changed

crates/standalone/src/subcommands/start.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ async fn load_certs(file_path: &Path) -> anyhow::Result<Vec<CertificateDer<'stat
120120
let certs: Vec<CertificateDer<'static>> = rustls_pemfile::certs(&mut std::io::Cursor::new(data))
121121
.collect::<Result<Vec<_>, _>>()
122122
.map_err(|e| anyhow::anyhow!("Failed to parse certificates from {}: {:?}", file_path.display(), e))?;
123-
if certs.is_empty() {
124-
return Err(anyhow::anyhow!("No certificates found in file {}", file_path.display()));
123+
match certs.len() {
124+
0 => Err(anyhow::anyhow!("No certificates found in file {}", file_path.display())),
125+
1 => Ok(certs),
126+
_ => Err(anyhow::anyhow!("Multiple certificates found in file {}; only one certificate is expected.", file_path.display())),
125127
}
126-
Ok(certs)
127128
}
128129

129130
/// Loads a private key from a PEM file.
@@ -132,11 +133,11 @@ async fn load_private_key(file_path: &Path) -> anyhow::Result<PrivateKeyDer<'sta
132133
let keys: Vec<PrivatePkcs8KeyDer<'static>> = rustls_pemfile::pkcs8_private_keys(&mut std::io::Cursor::new(data))
133134
.collect::<Result<Vec<_>, _>>()
134135
.map_err(|e| anyhow::anyhow!("Failed to parse private keys from {}: {:?}", file_path.display(), e))?;
135-
let key = keys
136-
.into_iter()
137-
.next()
138-
.ok_or_else(|| anyhow::anyhow!("No private key found in file {}", file_path.display()))?;
139-
Ok(PrivateKeyDer::Pkcs8(key))
136+
match keys.len() {
137+
0 => Err(anyhow::anyhow!("No private key found in file {}", file_path.display())),
138+
1 => Ok(PrivateKeyDer::Pkcs8(keys.into_iter().next().unwrap())),
139+
_ => Err(anyhow::anyhow!("Multiple private keys found in file {}; only one private key is expected.", file_path.display())),
140+
}
140141
}
141142

142143
/// Creates a custom CryptoProvider with specific cipher suites.

0 commit comments

Comments
 (0)