ssl: pass test_ssl with the rustls backend (#8502) · RustPython/RustPython@24bd3b3 · GitHub
Skip to content

Commit 24bd3b3

Browse files
authored
ssl: pass test_ssl with the rustls backend (#8502)
* Fix rustls test_ssl compatibility Assisted-by: OpenAI Codex:GPT-5 * Keep urllib3 compatible SSL version prefix Assisted-by: OpenAI Codex:GPT-5
1 parent d64cc2c commit 24bd3b3

3 files changed

Lines changed: 109 additions & 23 deletions

File tree

crates/stdlib/src/ssl.rs

Lines changed: 9 additions & 7 deletions

crates/stdlib/src/ssl/cert.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ pub(super) fn is_ca_certificate(cert_der: &[u8]) -> bool {
287287
return ext.value.ca;
288288
}
289289

290-
// No Basic Constraints extension -> NOT a CA certificate
291-
// (matches OpenSSL X509_check_ca() behavior)
292-
false
290+
// X509_check_ca() also retains OpenSSL's legacy trust-anchor rule: a
291+
// self-issued X.509v1 certificate has no extensions at all, but is still
292+
// classified as a CA. CPython's test CA at capath/4e1295a3.0 exercises
293+
// precisely this case.
294+
cert.version().0 == 0 && cert.subject() == cert.issuer()
293295
}
294296

295297
/// Convert an X509Name to Python nested tuple format for SSL certificate dicts
@@ -867,26 +869,36 @@ impl ServerCertVerifier for NoVerifier {
867869

868870
fn verify_tls12_signature(
869871
&self,
870-
_message: &[u8],
871-
_cert: &CertificateDer<'_>,
872-
_dss: &DigitallySignedStruct,
872+
message: &[u8],
873+
cert: &CertificateDer<'_>,
874+
dss: &DigitallySignedStruct,
873875
) -> Result<HandshakeSignatureValid, rustls::Error> {
874-
// Accept all signatures without verification
875-
Ok(HandshakeSignatureValid::assertion())
876+
rustls::crypto::verify_tls12_signature(
877+
message,
878+
cert,
879+
dss,
880+
&CryptoExt::get_provider().signature_verification_algorithms,
881+
)
876882
}
877883

878884
fn verify_tls13_signature(
879885
&self,
880-
_message: &[u8],
881-
_cert: &CertificateDer<'_>,
882-
_dss: &DigitallySignedStruct,
886+
message: &[u8],
887+
cert: &CertificateDer<'_>,
888+
dss: &DigitallySignedStruct,
883889
) -> Result<HandshakeSignatureValid, rustls::Error> {
884-
// Accept all signatures without verification
885-
Ok(HandshakeSignatureValid::assertion())
890+
rustls::crypto::verify_tls13_signature(
891+
message,
892+
cert,
893+
dss,
894+
&CryptoExt::get_provider().signature_verification_algorithms,
895+
)
886896
}
887897

888898
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
889-
ALL_SIGNATURE_SCHEMES.to_vec()
899+
CryptoExt::get_provider()
900+
.signature_verification_algorithms
901+
.supported_schemes()
890902
}
891903
}
892904

crates/vm/src/stdlib/_thread.rs

Lines changed: 74 additions & 2 deletions

0 commit comments

Comments
 (0)