aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/tls_util.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-07-06 10:58:32 +0200
committerAlex Auvolat <alex@adnab.me>2021-07-06 11:16:01 +0200
commitfa394dcd271a1cfeaa061dc58f2d33f492603e37 (patch)
tree828ab50e4b9c2e630b825c1d0a9ba3a892baee03 /src/rpc/tls_util.rs
parent30a7dee920c7da9da1f1e99851c99e3b1241bef4 (diff)
downloadgarage-fa394dcd271a1cfeaa061dc58f2d33f492603e37.tar.gz
garage-fa394dcd271a1cfeaa061dc58f2d33f492603e37.zip
Support pkcs8 private keys (allowing for ed25519 to be used for rpc)
Diffstat (limited to 'src/rpc/tls_util.rs')
-rw-r--r--src/rpc/tls_util.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/rpc/tls_util.rs b/src/rpc/tls_util.rs
index 36ea7bf3..8189f93b 100644
--- a/src/rpc/tls_util.rs
+++ b/src/rpc/tls_util.rs
@@ -38,15 +38,16 @@ pub fn load_certs(filename: &str) -> Result<Vec<rustls::Certificate>, Error> {
}
pub fn load_private_key(filename: &str) -> Result<rustls::PrivateKey, Error> {
- let keyfile = fs::File::open(&filename)?;
- let mut reader = io::BufReader::new(keyfile);
+ let keydata = fs::read_to_string(filename)?;
- let keys = pemfile::rsa_private_keys(&mut reader).map_err(|_| {
- Error::Message(format!(
- "Could not decode private key from file: {}",
- filename
- ))
- })?;
+ let mut buf1 = keydata.as_bytes();
+ let rsa_keys = pemfile::rsa_private_keys(&mut buf1).unwrap_or_default();
+
+ let mut buf2 = keydata.as_bytes();
+ let pkcs8_keys = pemfile::pkcs8_private_keys(&mut buf2).unwrap_or_default();
+
+ let mut keys = rsa_keys;
+ keys.extend(pkcs8_keys.into_iter());
if keys.len() != 1 {
return Err(Error::Message(format!(