Support user-supplied DER certificates in the server example

This is the type we generate and cache by default, so it's weird not
to handle it.
This commit is contained in:
Benjamin Saunders
2019-01-17 22:20:48 -08:00
committed by Dirkjan Ochtman
parent 2b96ccee36
commit e73fadaa6f
+13 -5
View File
@@ -93,11 +93,19 @@ fn run(log: Logger, options: Opt) -> Result<()> {
server_config.use_stateless_retry(true);
}
if let (Some(ref key), Some(ref cert)) = (options.key, options.cert) {
let key = fs::read(key).context("failed to read private key")?;
let key = quinn::PrivateKey::from_pem(&key)?;
let cert_chain = fs::read(cert).context("failed to read certificate chain")?;
let cert_chain = quinn::CertificateChain::from_pem(&cert_chain)?;
if let (Some(ref key_path), Some(ref cert_path)) = (options.key, options.cert) {
let key = fs::read(key_path).context("failed to read private key")?;
let key = if key_path.extension().map_or(false, |x| x == "der") {
quinn::PrivateKey::from_der(&key)?
} else {
quinn::PrivateKey::from_pem(&key)?
};
let cert_chain = fs::read(cert_path).context("failed to read certificate chain")?;
let cert_chain = if cert_path.extension().map_or(false, |x| x == "der") {
quinn::CertificateChain::from_certs(quinn::Certificate::from_der(&cert_chain))
} else {
quinn::CertificateChain::from_pem(&cert_chain)?
};
server_config.set_certificate(cert_chain, key)?;
} else {
let dirs = directories::ProjectDirs::from("org", "quinn", "quinn-examples").unwrap();