Skip to content

Commit

Permalink
refactor: Refactor private key extraction in TLS server for legibility
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreCassagne committed Nov 14, 2023
1 parent b90ad06 commit 404a730
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rumqttd/src/server/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,18 @@ fn first_private_key_in_pemfile(key_path: &String) -> Result<PrivateKey, Error>
loop {
match rustls_pemfile::read_one(rd) {
Ok(maybe_inner) => match maybe_inner {
Some(item) => match item {
// If we find a private key, return it
Item::ECKey(key) | Item::RSAKey(key) | Item::PKCS8Key(key) => {
return Ok(PrivateKey(key))
}
// Otherwise, continue
_ => {}
},
None => {
error!("No private key found in {:?}", key_path);
return Err(Error::InvalidServerKey(key_path.clone()));
}
Some(Item::ECKey(key)) => return Ok(PrivateKey(key)),
Some(Item::RSAKey(key)) => return Ok(PrivateKey(key)),
Some(Item::PKCS8Key(key)) => return Ok(PrivateKey(key)),
Some(_) => {}
},
Err(err) => {
error!("Error reading key file: {:?}", err);
Expand Down

0 comments on commit 404a730

Please sign in to comment.