forked from lavina/lavina
1
0
Fork 0

fix tls key parsing usage

This commit is contained in:
Nikita Vilunov 2023-08-05 00:38:56 +02:00
parent 70b12c9a0d
commit c39928799d
1 changed files with 6 additions and 4 deletions

View File

@ -11,7 +11,7 @@ use futures_util::future::join_all;
use prometheus::Registry as MetricsRegistry; use prometheus::Registry as MetricsRegistry;
use quick_xml::events::{BytesDecl, Event}; use quick_xml::events::{BytesDecl, Event};
use quick_xml::{NsReader, Writer}; 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 serde::Deserialize;
use tokio::io::{AsyncBufRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter}; use tokio::io::{AsyncBufRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter};
use tokio::net::{TcpListener, TcpStream}; 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(&mut SyncBufReader::new(File::open(config.cert)?))?;
let certs = certs.into_iter().map(Certificate).collect::<Vec<_>>(); let certs = certs.into_iter().map(Certificate).collect::<Vec<_>>();
let keys = rsa_private_keys(&mut SyncBufReader::new(File::open(config.key)?))?; let key = match read_one(&mut SyncBufReader::new(File::open(config.key)?))? {
let keys = keys.into_iter().map(PrivateKey).collect::<Vec<_>>(); Some(PemItem::ECKey(k) | PemItem::PKCS8Key(k) | PemItem::RSAKey(k)) => PrivateKey(k),
_ => panic!("no keys in file"),
};
let loaded_config = Arc::new(LoadedConfig { let loaded_config = Arc::new(LoadedConfig {
cert: certs.into_iter().next().expect("no certs in file"), 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?; let listener = TcpListener::bind(config.listen_on).await?;