-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port link-tls to tokio and bump workspace rustls to 0.22.2
- Loading branch information
1 parent
bdbac9d
commit fb208f6
Showing
8 changed files
with
240 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use alloc::vec::Vec; | ||
use rustls::{ | ||
client::{ | ||
danger::{ServerCertVerified, ServerCertVerifier}, | ||
verify_server_cert_signed_by_trust_anchor, | ||
}, | ||
crypto::{verify_tls12_signature, verify_tls13_signature}, | ||
pki_types::{CertificateDer, ServerName, UnixTime}, | ||
server::ParsedCertificate, | ||
RootCertStore, | ||
}; | ||
use webpki::ALL_VERIFICATION_ALGS; | ||
|
||
impl ServerCertVerifier for WebPkiVerifierAnyServerName { | ||
/// Will verify the certificate is valid in the following ways: | ||
/// - Signed by a trusted `RootCertStore` CA | ||
/// - Not Expired | ||
fn verify_server_cert( | ||
&self, | ||
end_entity: &CertificateDer<'_>, | ||
intermediates: &[CertificateDer<'_>], | ||
_server_name: &ServerName<'_>, | ||
_ocsp_response: &[u8], | ||
now: UnixTime, | ||
) -> Result<ServerCertVerified, rustls::Error> { | ||
let cert = ParsedCertificate::try_from(end_entity)?; | ||
verify_server_cert_signed_by_trust_anchor( | ||
&cert, | ||
&self.roots, | ||
intermediates, | ||
now, | ||
ALL_VERIFICATION_ALGS, | ||
)?; | ||
Ok(ServerCertVerified::assertion()) | ||
} | ||
|
||
fn verify_tls12_signature( | ||
&self, | ||
message: &[u8], | ||
cert: &CertificateDer<'_>, | ||
dss: &rustls::DigitallySignedStruct, | ||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> { | ||
verify_tls12_signature( | ||
message, | ||
cert, | ||
dss, | ||
&rustls::crypto::ring::default_provider().signature_verification_algorithms, | ||
) | ||
} | ||
|
||
fn verify_tls13_signature( | ||
&self, | ||
message: &[u8], | ||
cert: &CertificateDer<'_>, | ||
dss: &rustls::DigitallySignedStruct, | ||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> { | ||
verify_tls13_signature( | ||
message, | ||
cert, | ||
dss, | ||
&rustls::crypto::ring::default_provider().signature_verification_algorithms, | ||
) | ||
} | ||
|
||
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> { | ||
rustls::crypto::ring::default_provider() | ||
.signature_verification_algorithms | ||
.supported_schemes() | ||
} | ||
} | ||
|
||
/// `ServerCertVerifier` that verifies that the server is signed by a trusted root, but allows any serverName | ||
/// see the trait impl for more information. | ||
#[derive(Debug)] | ||
pub struct WebPkiVerifierAnyServerName { | ||
roots: RootCertStore, | ||
} | ||
|
||
#[allow(unreachable_pub)] | ||
impl WebPkiVerifierAnyServerName { | ||
/// Constructs a new `WebPkiVerifierAnyServerName`. | ||
/// | ||
/// `roots` is the set of trust anchors to trust for issuing server certs. | ||
pub fn new(roots: RootCertStore) -> Self { | ||
Self { roots } | ||
} | ||
} |
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
Oops, something went wrong.