forked from rwf2/Rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simpler impl of dynamically swapping tls creds
closes rwf2#2363
- Loading branch information
Showing
6 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::{io, sync::Arc}; | ||
|
||
use rustls::{server::ClientHello, sign::{any_supported_type, CertifiedKey}}; | ||
|
||
use crate::tls::Config; | ||
use crate::tls::util::{load_certs, load_private_key}; | ||
|
||
pub(crate) struct CertResolver(Arc<CertifiedKey>); | ||
impl CertResolver { | ||
pub fn new<R>(config: &mut Config<R>) -> Result<Self, std::io::Error> | ||
where R: io::BufRead, | ||
{ | ||
let certs = load_certs(&mut config.cert_chain)?; | ||
let private_key = load_private_key(&mut config.private_key)?; | ||
let key = any_supported_type(&private_key) | ||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("bad TLS config: {}", e)))?; | ||
|
||
Ok(Self(Arc::new(CertifiedKey::new(certs, key)))) | ||
} | ||
} | ||
|
||
impl rustls::server::ResolvesServerCert for CertResolver { | ||
fn resolve(&self, _client_hello: ClientHello<'_>) -> Option<Arc<CertifiedKey>> { | ||
Some(self.0.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters