From c39928799d1b43d5a6da9414ab5c531f027cf758 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Sat, 5 Aug 2023 00:38:56 +0200 Subject: [PATCH] fix tls key parsing usage --- src/projections/xmpp/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/projections/xmpp/mod.rs b/src/projections/xmpp/mod.rs index 5524a8d..a02ceca 100644 --- a/src/projections/xmpp/mod.rs +++ b/src/projections/xmpp/mod.rs @@ -11,7 +11,7 @@ use futures_util::future::join_all; use prometheus::Registry as MetricsRegistry; use quick_xml::events::{BytesDecl, Event}; use quick_xml::{NsReader, Writer}; -use rustls_pemfile::{certs, rsa_private_keys}; +use rustls_pemfile::{certs, read_one, Item as PemItem}; use serde::Deserialize; use tokio::io::{AsyncBufRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter}; use tokio::net::{TcpListener, TcpStream}; @@ -64,12 +64,14 @@ pub async fn launch( let certs = certs(&mut SyncBufReader::new(File::open(config.cert)?))?; let certs = certs.into_iter().map(Certificate).collect::>(); - let keys = rsa_private_keys(&mut SyncBufReader::new(File::open(config.key)?))?; - let keys = keys.into_iter().map(PrivateKey).collect::>(); + let key = match read_one(&mut SyncBufReader::new(File::open(config.key)?))? { + Some(PemItem::ECKey(k) | PemItem::PKCS8Key(k) | PemItem::RSAKey(k)) => PrivateKey(k), + _ => panic!("no keys in file"), + }; let loaded_config = Arc::new(LoadedConfig { cert: certs.into_iter().next().expect("no certs in file"), - key: keys.into_iter().next().expect("no keys in file"), + key, }); let listener = TcpListener::bind(config.listen_on).await?;