-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e8850b
commit 5103588
Showing
8 changed files
with
88 additions
and
38 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{fmt::Debug, sync::Arc}; | ||
|
||
use rustls::{ | ||
server::{ClientHello, ResolvesServerCert as ResolvesServerCertRustls}, | ||
sign::CertifiedKey, | ||
}; | ||
|
||
// Custom ResolvesServerCert trait that takes ClientHello by reference. | ||
// It's needed because Rustls' ResolvesServerCert consumes ClientHello | ||
pub trait ResolvesServerCert: Debug + Send + Sync { | ||
fn resolve(&self, client_hello: &ClientHello) -> Option<Arc<CertifiedKey>>; | ||
} | ||
|
||
// Combines several certificate resolvers into one | ||
// Only one Rustls-compatible resolver can be used (acme) since it takes ClientHello by value | ||
#[derive(Debug, derive_new::new)] | ||
pub struct AggregatingResolver { | ||
acme: Option<Arc<dyn ResolvesServerCertRustls>>, | ||
resolvers: Vec<Arc<dyn ResolvesServerCert>>, | ||
} | ||
|
||
// Implement certificate resolving for Rustls | ||
impl ResolvesServerCertRustls for AggregatingResolver { | ||
fn resolve(&self, ch: ClientHello) -> Option<Arc<CertifiedKey>> { | ||
// Iterate over our resolvers to find matching cert if any | ||
let cert = self.resolvers.iter().find_map(|x| x.resolve(&ch)); | ||
if let Some(v) = cert { | ||
return Some(v); | ||
} | ||
|
||
// Otherwise try the ACME resolver with Rustls trait that consumes ClientHello | ||
self.acme.as_ref().and_then(|x| x.resolve(ch)) | ||
} | ||
} |