MCPcopy Index your code
hub / github.com/RustPython/RustPython / rustls_cert_error_to_verify_info

Function rustls_cert_error_to_verify_info

crates/stdlib/src/ssl/compat.rs:169–210  ·  view source on GitHub ↗

Convert rustls CertificateError to X509 verification code and message Maps rustls certificate errors to OpenSSL X509_V_ERR_* codes for compatibility. Returns (verify_code, verify_message) tuple.

(cert_err: &rustls::CertificateError)

Source from the content-addressed store, hash-verified

167/// Maps rustls certificate errors to OpenSSL X509_V_ERR_* codes for compatibility.
168/// Returns (verify_code, verify_message) tuple.
169fn rustls_cert_error_to_verify_info(cert_err: &rustls::CertificateError) -> (i32, &'static str) {
170 use rustls::CertificateError;
171
172 match cert_err {
173 CertificateError::UnknownIssuer => (
174 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY,
175 "unable to get local issuer certificate",
176 ),
177 CertificateError::Expired => (X509_V_ERR_CERT_HAS_EXPIRED, "certificate has expired"),
178 CertificateError::NotValidYet => (
179 X509_V_ERR_CERT_NOT_YET_VALID,
180 "certificate is not yet valid",
181 ),
182 CertificateError::Revoked => (X509_V_ERR_CERT_REVOKED, "certificate revoked"),
183 CertificateError::UnknownRevocationStatus => (
184 X509_V_ERR_UNABLE_TO_GET_CRL,
185 "unable to get certificate CRL",
186 ),
187 CertificateError::InvalidPurpose => (
188 X509_V_ERR_INVALID_PURPOSE,
189 "unsupported certificate purpose",
190 ),
191 CertificateError::Other(other_err) => {
192 // Check if this is a hostname mismatch error from our verify_hostname function
193 let err_msg = format!("{other_err:?}");
194 if err_msg.contains("Hostname mismatch") || err_msg.contains("not valid for") {
195 (
196 X509_V_ERR_HOSTNAME_MISMATCH,
197 "Hostname mismatch, certificate is not valid for",
198 )
199 } else if err_msg.contains("IP address mismatch") {
200 (
201 X509_V_ERR_IP_ADDRESS_MISMATCH,
202 "IP address mismatch, certificate is not valid for",
203 )
204 } else {
205 (X509_V_ERR_UNSPECIFIED, "certificate verification failed")
206 }
207 }
208 _ => (X509_V_ERR_UNSPECIFIED, "certificate verification failed"),
209 }
210}
211
212/// Create SSLCertVerificationError with proper attributes
213///

Callers 1

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected