Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multiple key types #902

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dropshot/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,20 @@ impl TryFrom<&ConfigTls> for rustls::ServerConfig {
.map_err(|err| {
io_error(format!("failed to load certificate: {err}"))
})?;
let keys = rustls_pemfile::pkcs8_private_keys(&mut key_reader)
.collect::<Result<Vec<_>, _>>()
let keys = rustls_pemfile::private_key(&mut key_reader)
//.collect::<Result<Vec<_>, _>>()
Comment on lines +521 to +522
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustls_pemfile::private_key docs say "Yields the first PEM section describing a private key (of any type), or an error if a problem occurs while trying to read PEM sections."

Github isn't letting me make this suggestion for the full span, but from 521-529 I'd suggest doing:

        let private_key = rustls_pemfile::private_key(&mut key_reader)
            .map_err(|err| {
                io_error(format!("failed to load private key: {err}"))
            })?
            .ok_or_else(|| io_error("no private key found".into()))?;

.map_err(|err| {
io_error(format!("failed to load private key: {err}"))
})?;
let mut keys_iter = keys.into_iter();
let (Some(private_key), None) = (keys_iter.next(), keys_iter.next())
else {
return Err(io_error("expected a single private key".into()));
return Err(io_error("expected a single private key".to_owned()));
};

let mut cfg = rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(certs, private_key.into())
.with_single_cert(certs, private_key)
.expect("bad certificate/key");
cfg.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
Ok(cfg)
Expand Down