|
@@ -16,171 +16,235 @@
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-use std::{sync::Arc, time::SystemTime};
|
|
|
|
|
|
|
+use std::sync::Arc;
|
|
|
|
|
|
|
|
-use async_rustls::{
|
|
|
|
|
- rustls,
|
|
|
|
|
|
|
+use futures_rustls::{
|
|
|
rustls::{
|
|
rustls::{
|
|
|
- client::{ServerCertVerified, ServerCertVerifier},
|
|
|
|
|
- kx_group::X25519,
|
|
|
|
|
- server::{ClientCertVerified, ClientCertVerifier},
|
|
|
|
|
|
|
+ self,
|
|
|
|
|
+ client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
|
|
|
|
|
+ pki_types::{CertificateDer, PrivateKeyDer, ServerName, UnixTime},
|
|
|
|
|
+ server::danger::{ClientCertVerified, ClientCertVerifier},
|
|
|
version::TLS13,
|
|
version::TLS13,
|
|
|
- Certificate, ClientConfig, DistinguishedName, ServerConfig, ServerName,
|
|
|
|
|
|
|
+ ClientConfig, DigitallySignedStruct, DistinguishedName, ServerConfig, SignatureScheme,
|
|
|
},
|
|
},
|
|
|
TlsAcceptor, TlsConnector, TlsStream,
|
|
TlsAcceptor, TlsConnector, TlsStream,
|
|
|
};
|
|
};
|
|
|
use log::error;
|
|
use log::error;
|
|
|
use rustls_pemfile::pkcs8_private_keys;
|
|
use rustls_pemfile::pkcs8_private_keys;
|
|
|
use x509_parser::{
|
|
use x509_parser::{
|
|
|
- extensions::{GeneralName, ParsedExtension},
|
|
|
|
|
parse_x509_certificate,
|
|
parse_x509_certificate,
|
|
|
- prelude::{FromDer, X509Certificate},
|
|
|
|
|
- x509::SubjectPublicKeyInfo,
|
|
|
|
|
|
|
+ prelude::{GeneralName, ParsedExtension, X509Certificate},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-use crate::{util::encoding::base32, Result};
|
|
|
|
|
-
|
|
|
|
|
-const CIPHER_SUITE: &str = "TLS13_CHACHA20_POLY1305_SHA256";
|
|
|
|
|
-
|
|
|
|
|
-fn cipher_suite() -> rustls::SupportedCipherSuite {
|
|
|
|
|
- for suite in rustls::ALL_CIPHER_SUITES {
|
|
|
|
|
- let sname = format!("{:?}", suite.suite()).to_lowercase();
|
|
|
|
|
-
|
|
|
|
|
- if sname == CIPHER_SUITE.to_string().to_lowercase() {
|
|
|
|
|
- return *suite
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+use crate::Result;
|
|
|
|
|
|
|
|
- unreachable!()
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/// Validate that the altName pubkey is the same as the certificate's pubkey.
|
|
|
|
|
-/// Returns `ed25519_compact::PublicKey` on success.
|
|
|
|
|
-fn validate_pubkey(
|
|
|
|
|
- cert: &X509Certificate,
|
|
|
|
|
-) -> std::result::Result<ed25519_compact::PublicKey, rustls::Error> {
|
|
|
|
|
- // We keep a public key in the altName, so we need to grab it.
|
|
|
|
|
- // We compare that the actual public key of the certificate is
|
|
|
|
|
- // the same as that one, and then we return it.
|
|
|
|
|
- // The actual verification functions handle signature verification.
|
|
|
|
|
|
|
+/// Validate certificate DNSName.
|
|
|
|
|
+fn validate_dnsname(cert: &X509Certificate) -> std::result::Result<(), rustls::Error> {
|
|
|
#[rustfmt::skip]
|
|
#[rustfmt::skip]
|
|
|
- let oid = x509_parser::oid_registry::asn1_rs::oid!(2.5.29.17);
|
|
|
|
|
|
|
+ let oid = x509_parser::oid_registry::asn1_rs::oid!(2.5.29.17);
|
|
|
let Ok(Some(extension)) = cert.get_extension_unique(&oid) else {
|
|
let Ok(Some(extension)) = cert.get_extension_unique(&oid) else {
|
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // Crufty AF
|
|
|
|
|
- // (ノಠ益ಠ)ノ彡┻━┻
|
|
|
|
|
- let pubkey_bytes = match extension.parsed_extension() {
|
|
|
|
|
|
|
+ let dns_name = match extension.parsed_extension() {
|
|
|
ParsedExtension::SubjectAlternativeName(altname) => {
|
|
ParsedExtension::SubjectAlternativeName(altname) => {
|
|
|
if altname.general_names.len() != 1 {
|
|
if altname.general_names.len() != 1 {
|
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
match altname.general_names[0] {
|
|
match altname.general_names[0] {
|
|
|
- GeneralName::DNSName(a) => base32::decode(a),
|
|
|
|
|
|
|
+ GeneralName::DNSName(dns_name) => dns_name,
|
|
|
_ => return Err(rustls::CertificateError::BadEncoding.into()),
|
|
_ => return Err(rustls::CertificateError::BadEncoding.into()),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- _ => return Err(rustls::CertificateError::BadEncoding.into()),
|
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
- let Some(pubkey_bytes) = pubkey_bytes else {
|
|
|
|
|
- return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- if pubkey_bytes.len() != 32 {
|
|
|
|
|
- return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let pubkey = ed25519_compact::PublicKey::new(pubkey_bytes.try_into().unwrap());
|
|
|
|
|
- let pubkey_der = pubkey.to_der();
|
|
|
|
|
-
|
|
|
|
|
- let Ok((_, parsed_pubkey)) = SubjectPublicKeyInfo::from_der(&pubkey_der) else {
|
|
|
|
|
- return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let Ok(parsed_name_pubkey) = parsed_pubkey.parsed() else {
|
|
|
|
|
- return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
|
|
+ _ => return Err(rustls::CertificateError::BadEncoding.into()),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- let Ok(parsed_cert_pubkey) = cert.public_key().parsed() else {
|
|
|
|
|
|
|
+ if dns_name != "dark.fi" {
|
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- if parsed_name_pubkey != parsed_cert_pubkey {
|
|
|
|
|
- return Err(rustls::CertificateError::BadSignature.into())
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Ok(pubkey)
|
|
|
|
|
|
|
+ Ok(())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(Debug)]
|
|
|
struct ServerCertificateVerifier;
|
|
struct ServerCertificateVerifier;
|
|
|
impl ServerCertVerifier for ServerCertificateVerifier {
|
|
impl ServerCertVerifier for ServerCertificateVerifier {
|
|
|
|
|
+ fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
|
|
|
|
|
+ vec![SignatureScheme::ED25519]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fn verify_server_cert(
|
|
fn verify_server_cert(
|
|
|
&self,
|
|
&self,
|
|
|
- end_entity: &Certificate,
|
|
|
|
|
- _intermediates: &[Certificate],
|
|
|
|
|
|
|
+ end_entity: &CertificateDer,
|
|
|
|
|
+ _intermediates: &[CertificateDer],
|
|
|
_server_name: &ServerName,
|
|
_server_name: &ServerName,
|
|
|
- _scrs: &mut dyn Iterator<Item = &[u8]>,
|
|
|
|
|
_ocsp_response: &[u8],
|
|
_ocsp_response: &[u8],
|
|
|
- _now: SystemTime,
|
|
|
|
|
|
|
+ _now: UnixTime,
|
|
|
) -> std::result::Result<ServerCertVerified, rustls::Error> {
|
|
) -> std::result::Result<ServerCertVerified, rustls::Error> {
|
|
|
- // Parse the actual end_entity certificate
|
|
|
|
|
- let Ok((_, cert)) = parse_x509_certificate(&end_entity.0) else {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed parsing server TLS certificate");
|
|
|
|
|
|
|
+ // Read the DER-encoded certificate into a buffer
|
|
|
|
|
+ let mut buf = Vec::with_capacity(end_entity.len());
|
|
|
|
|
+ for byte in end_entity.iter() {
|
|
|
|
|
+ buf.push(*byte);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Parse the certificate
|
|
|
|
|
+ let Ok((_, cert)) = parse_x509_certificate(&buf) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_server_cert", "[net::tls] Failed parsing server TLS certificate");
|
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // Validate that the pubkey in altNames matches the certificate pubkey.
|
|
|
|
|
- if let Err(e) = validate_pubkey(&cert) {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed verifying server certificate signature: {}", e);
|
|
|
|
|
- return Err(e)
|
|
|
|
|
|
|
+ // Validate DNSName
|
|
|
|
|
+ validate_dnsname(&cert)?;
|
|
|
|
|
+
|
|
|
|
|
+ Ok(ServerCertVerified::assertion())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn verify_tls12_signature(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ _message: &[u8],
|
|
|
|
|
+ _cert: &CertificateDer,
|
|
|
|
|
+ _dss: &DigitallySignedStruct,
|
|
|
|
|
+ ) -> std::result::Result<HandshakeSignatureValid, rustls::Error> {
|
|
|
|
|
+ unreachable!()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn verify_tls13_signature(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ message: &[u8],
|
|
|
|
|
+ cert: &CertificateDer,
|
|
|
|
|
+ dss: &DigitallySignedStruct,
|
|
|
|
|
+ ) -> std::result::Result<HandshakeSignatureValid, rustls::Error> {
|
|
|
|
|
+ // Verify we're using the correct signature scheme
|
|
|
|
|
+ if dss.scheme != SignatureScheme::ED25519 {
|
|
|
|
|
+ return Err(rustls::CertificateError::BadSignature.into())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Read the DER-encoded certificate into a buffer
|
|
|
|
|
+ let mut buf = Vec::with_capacity(cert.len());
|
|
|
|
|
+ for byte in cert.iter() {
|
|
|
|
|
+ buf.push(*byte);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Verify the signature. By passing `None` it should use the certificate
|
|
|
|
|
- // pubkey, but we also verified that it matches the one in altNames above.
|
|
|
|
|
- if let Err(e) = cert.verify_signature(None) {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed verifying server certificate signature: {}", e);
|
|
|
|
|
|
|
+ // Parse the certificate and extract the public key
|
|
|
|
|
+ let Ok((_, cert)) = parse_x509_certificate(&buf) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed parsing server TLS certificate");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let Ok(public_key) = ed25519_compact::PublicKey::from_der(cert.public_key().raw) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed parsing server public key");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // Verify the signature
|
|
|
|
|
+ let Ok(signature) = ed25519_compact::Signature::from_slice(dss.signature()) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed verifying server signature");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadSignature.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if let Err(e) = public_key.verify(message, &signature) {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed verifying server signature: {}", e);
|
|
|
return Err(rustls::CertificateError::BadSignature.into())
|
|
return Err(rustls::CertificateError::BadSignature.into())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Ok(ServerCertVerified::assertion())
|
|
|
|
|
|
|
+ Ok(HandshakeSignatureValid::assertion())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(Debug)]
|
|
|
struct ClientCertificateVerifier;
|
|
struct ClientCertificateVerifier;
|
|
|
impl ClientCertVerifier for ClientCertificateVerifier {
|
|
impl ClientCertVerifier for ClientCertificateVerifier {
|
|
|
- fn client_auth_root_subjects(&self) -> &[DistinguishedName] {
|
|
|
|
|
|
|
+ fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
|
|
|
|
|
+ vec![SignatureScheme::ED25519]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn client_auth_mandatory(&self) -> bool {
|
|
|
|
|
+ true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn offer_client_auth(&self) -> bool {
|
|
|
|
|
+ true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn root_hint_subjects(&self) -> &[DistinguishedName] {
|
|
|
&[]
|
|
&[]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn verify_client_cert(
|
|
fn verify_client_cert(
|
|
|
&self,
|
|
&self,
|
|
|
- end_entity: &Certificate,
|
|
|
|
|
- _intermediates: &[Certificate],
|
|
|
|
|
- _now: SystemTime,
|
|
|
|
|
|
|
+ end_entity: &CertificateDer,
|
|
|
|
|
+ _intermediates: &[CertificateDer],
|
|
|
|
|
+ _now: UnixTime,
|
|
|
) -> std::result::Result<ClientCertVerified, rustls::Error> {
|
|
) -> std::result::Result<ClientCertVerified, rustls::Error> {
|
|
|
- // Parse the actual end_entity certificate
|
|
|
|
|
- let Ok((_, cert)) = parse_x509_certificate(&end_entity.0) else {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed parsing client TLS certificate");
|
|
|
|
|
|
|
+ // Read the DER-encoded certificate into a buffer
|
|
|
|
|
+ let mut cert = Vec::with_capacity(end_entity.len());
|
|
|
|
|
+ for byte in end_entity.iter() {
|
|
|
|
|
+ cert.push(*byte);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Parse the certificate
|
|
|
|
|
+ let Ok((_, cert)) = parse_x509_certificate(&cert) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_server_cert", "[net::tls] Failed parsing server TLS certificate");
|
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // Validate that the pubkey in altNames matches the certificate pubkey.
|
|
|
|
|
- if let Err(e) = validate_pubkey(&cert) {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed verifying client certificate signature: {}", e);
|
|
|
|
|
- return Err(e)
|
|
|
|
|
|
|
+ // Validate DNSName
|
|
|
|
|
+ validate_dnsname(&cert)?;
|
|
|
|
|
+
|
|
|
|
|
+ Ok(ClientCertVerified::assertion())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn verify_tls12_signature(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ _message: &[u8],
|
|
|
|
|
+ _cert: &CertificateDer,
|
|
|
|
|
+ _dss: &DigitallySignedStruct,
|
|
|
|
|
+ ) -> std::result::Result<HandshakeSignatureValid, rustls::Error> {
|
|
|
|
|
+ unreachable!()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn verify_tls13_signature(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ message: &[u8],
|
|
|
|
|
+ cert: &CertificateDer,
|
|
|
|
|
+ dss: &DigitallySignedStruct,
|
|
|
|
|
+ ) -> std::result::Result<HandshakeSignatureValid, rustls::Error> {
|
|
|
|
|
+ // Verify we're using the correct signature scheme
|
|
|
|
|
+ if dss.scheme != SignatureScheme::ED25519 {
|
|
|
|
|
+ return Err(rustls::CertificateError::BadSignature.into())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Read the DER-encoded certificate into a buffer
|
|
|
|
|
+ let mut buf = Vec::with_capacity(cert.len());
|
|
|
|
|
+ for byte in cert.iter() {
|
|
|
|
|
+ buf.push(*byte);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Verify the signature. By passing `None` it should use the certificate
|
|
|
|
|
- // pubkey, but we also verified that it matches the one in altNames above.
|
|
|
|
|
- if let Err(e) = cert.verify_signature(None) {
|
|
|
|
|
- error!(target: "net::tls", "[net::tls] Failed verifying client certificate signature: {}", e);
|
|
|
|
|
|
|
+ // Parse the certificate and extract the public key
|
|
|
|
|
+ let Ok((_, cert)) = parse_x509_certificate(&buf) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed parsing server TLS certificate");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let Ok(public_key) = ed25519_compact::PublicKey::from_der(cert.public_key().raw) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed parsing server public key");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadEncoding.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // Verify the signature
|
|
|
|
|
+ let Ok(signature) = ed25519_compact::Signature::from_slice(dss.signature()) else {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed verifying server signature");
|
|
|
|
|
+ return Err(rustls::CertificateError::BadSignature.into())
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if let Err(e) = public_key.verify(message, &signature) {
|
|
|
|
|
+ error!(target: "net::tls::verify_tls13_signature", "[net::tls] Failed verifying server signature: {}", e);
|
|
|
return Err(rustls::CertificateError::BadSignature.into())
|
|
return Err(rustls::CertificateError::BadSignature.into())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Ok(ClientCertVerified::assertion())
|
|
|
|
|
|
|
+ Ok(HandshakeSignatureValid::assertion())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -192,19 +256,16 @@ pub struct TlsUpgrade {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl TlsUpgrade {
|
|
impl TlsUpgrade {
|
|
|
- pub fn new() -> Self {
|
|
|
|
|
- // On each instantiation, generate a new keypair and certificate.
|
|
|
|
|
- let keypair = ed25519_compact::KeyPair::generate();
|
|
|
|
|
- let keypair_pem = keypair.to_pem();
|
|
|
|
|
- let mut binding = keypair_pem.as_bytes();
|
|
|
|
|
- let secret_key = pkcs8_private_keys(&mut binding).next().unwrap().unwrap();
|
|
|
|
|
- let secret_key = rustls::PrivateKey(secret_key.secret_pkcs8_der().to_vec());
|
|
|
|
|
-
|
|
|
|
|
- let altnames = vec![base32::encode(false, keypair.pk.as_slice())];
|
|
|
|
|
|
|
+ pub async fn new() -> Self {
|
|
|
|
|
+ // On each instantiation, generate a new keypair and certificate
|
|
|
|
|
+ let keypair_pem = ed25519_compact::KeyPair::generate().to_pem();
|
|
|
|
|
+ let secret_key = pkcs8_private_keys(&mut keypair_pem.as_bytes()).next().unwrap().unwrap();
|
|
|
|
|
+ let secret_key = PrivateKeyDer::Pkcs8(secret_key);
|
|
|
|
|
|
|
|
- let mut cert_params = rcgen::CertificateParams::new(altnames);
|
|
|
|
|
|
|
+ let mut cert_params = rcgen::CertificateParams::new(&[]);
|
|
|
cert_params.alg = &rcgen::PKCS_ED25519;
|
|
cert_params.alg = &rcgen::PKCS_ED25519;
|
|
|
cert_params.key_pair = Some(rcgen::KeyPair::from_pem(&keypair_pem).unwrap());
|
|
cert_params.key_pair = Some(rcgen::KeyPair::from_pem(&keypair_pem).unwrap());
|
|
|
|
|
+ cert_params.subject_alt_names = vec![rcgen::SanType::DnsName("dark.fi".to_string())];
|
|
|
cert_params.extended_key_usages = vec![
|
|
cert_params.extended_key_usages = vec![
|
|
|
rcgen::ExtendedKeyUsagePurpose::ClientAuth,
|
|
rcgen::ExtendedKeyUsagePurpose::ClientAuth,
|
|
|
rcgen::ExtendedKeyUsagePurpose::ServerAuth,
|
|
rcgen::ExtendedKeyUsagePurpose::ServerAuth,
|
|
@@ -212,29 +273,23 @@ impl TlsUpgrade {
|
|
|
|
|
|
|
|
let certificate = rcgen::Certificate::from_params(cert_params).unwrap();
|
|
let certificate = rcgen::Certificate::from_params(cert_params).unwrap();
|
|
|
let certificate = certificate.serialize_der().unwrap();
|
|
let certificate = certificate.serialize_der().unwrap();
|
|
|
- let certificate = rustls::Certificate(certificate);
|
|
|
|
|
|
|
|
|
|
|
|
+ // Server-side config
|
|
|
let client_cert_verifier = Arc::new(ClientCertificateVerifier {});
|
|
let client_cert_verifier = Arc::new(ClientCertificateVerifier {});
|
|
|
let server_config = Arc::new(
|
|
let server_config = Arc::new(
|
|
|
- ServerConfig::builder()
|
|
|
|
|
- .with_cipher_suites(&[cipher_suite()])
|
|
|
|
|
- .with_kx_groups(&[&X25519])
|
|
|
|
|
- .with_protocol_versions(&[&TLS13])
|
|
|
|
|
- .unwrap()
|
|
|
|
|
|
|
+ ServerConfig::builder_with_protocol_versions(&[&TLS13])
|
|
|
.with_client_cert_verifier(client_cert_verifier)
|
|
.with_client_cert_verifier(client_cert_verifier)
|
|
|
- .with_single_cert(vec![certificate.clone()], secret_key.clone())
|
|
|
|
|
|
|
+ .with_single_cert(vec![certificate.clone().into()], secret_key.clone_key())
|
|
|
.unwrap(),
|
|
.unwrap(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ // Client-side config
|
|
|
let server_cert_verifier = Arc::new(ServerCertificateVerifier {});
|
|
let server_cert_verifier = Arc::new(ServerCertificateVerifier {});
|
|
|
let client_config = Arc::new(
|
|
let client_config = Arc::new(
|
|
|
- ClientConfig::builder()
|
|
|
|
|
- .with_cipher_suites(&[cipher_suite()])
|
|
|
|
|
- .with_kx_groups(&[&X25519])
|
|
|
|
|
- .with_protocol_versions(&[&TLS13])
|
|
|
|
|
- .unwrap()
|
|
|
|
|
|
|
+ ClientConfig::builder_with_protocol_versions(&[&TLS13])
|
|
|
|
|
+ .dangerous()
|
|
|
.with_custom_certificate_verifier(server_cert_verifier)
|
|
.with_custom_certificate_verifier(server_cert_verifier)
|
|
|
- .with_client_auth_cert(vec![certificate], secret_key)
|
|
|
|
|
|
|
+ .with_client_auth_cert(vec![certificate.into()], secret_key)
|
|
|
.unwrap(),
|
|
.unwrap(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -251,7 +306,8 @@ impl TlsUpgrade {
|
|
|
Ok(TlsStream::Client(stream))
|
|
Ok(TlsStream::Client(stream))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // FIXME: Try to find a transparent way for this instead of implementing separately for all
|
|
|
|
|
|
|
+ // TODO: Try to find a transparent way for this instead of implementing
|
|
|
|
|
+ // the function separately for every transport type.
|
|
|
#[cfg(feature = "p2p-tcp")]
|
|
#[cfg(feature = "p2p-tcp")]
|
|
|
pub async fn upgrade_listener_tcp_tls(
|
|
pub async fn upgrade_listener_tcp_tls(
|
|
|
self,
|
|
self,
|
|
@@ -260,9 +316,3 @@ impl TlsUpgrade {
|
|
|
Ok((TlsAcceptor::from(self.server_config), listener))
|
|
Ok((TlsAcceptor::from(self.server_config), listener))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-impl Default for TlsUpgrade {
|
|
|
|
|
- fn default() -> Self {
|
|
|
|
|
- Self::new()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|