diff --git a/ylong_http_client/src/util/c_openssl/ffi/ssl.rs b/ylong_http_client/src/util/c_openssl/ffi/ssl.rs index 3af302050d38a020f7e56abcdb9919b743933caf..c8f435812c9b4fa9a7309b5bdcd24286d3080e9d 100644 --- a/ylong_http_client/src/util/c_openssl/ffi/ssl.rs +++ b/ylong_http_client/src/util/c_openssl/ffi/ssl.rs @@ -149,8 +149,12 @@ extern "C" { /// by the peer, if any. pub(crate) fn SSL_get_verify_result(ssl: *const SSL) -> c_long; + #[cfg(feature = "c_openssl_3_0")] pub(crate) fn SSL_get1_peer_certificate(ssl: *const SSL) -> *mut C_X509; + #[cfg(feature = "c_openssl_1_1")] + pub(crate) fn SSL_get_peer_certificate(ssl: *const SSL) -> *mut C_X509; + pub(crate) fn SSL_set_bio(ssl: *mut SSL, rbio: *mut BIO, wbio: *mut BIO); pub(crate) fn SSL_get_rbio(ssl: *const SSL) -> *mut BIO; diff --git a/ylong_http_client/src/util/c_openssl/ssl/stream.rs b/ylong_http_client/src/util/c_openssl/ssl/stream.rs index d4def286dda5bdd2780d93dff4b835869e3fc04b..6008401e56a9e4cab84f695fd11450f67857d359 100644 --- a/ylong_http_client/src/util/c_openssl/ssl/stream.rs +++ b/ylong_http_client/src/util/c_openssl/ssl/stream.rs @@ -29,7 +29,7 @@ use crate::util::base64::encode; use crate::util::c_openssl::bio::BioMethod; use crate::util::c_openssl::error::VerifyError; use crate::util::c_openssl::error::VerifyKind::PubKeyPinning; -use crate::util::c_openssl::ffi::ssl::{SSL_get1_peer_certificate, SSL}; +use crate::util::c_openssl::ffi::ssl::SSL; use crate::util::c_openssl::ffi::x509::{i2d_X509_PUBKEY, X509_free, X509_get_X509_PUBKEY}; use crate::util::c_openssl::verify::sha256_digest; @@ -254,7 +254,21 @@ pub(crate) enum ShutdownResult { // TODO The SSLError thrown here is meaningless and has no information. fn verify_server_cert(ssl: *const SSL, pinned_key: &str) -> Result<(), SslError> { - let certificate = unsafe { SSL_get1_peer_certificate(ssl) }; + #[cfg(feature = "c_openssl_3_0")] + use crate::util::c_openssl::ffi::ssl::SSL_get1_peer_certificate; + #[cfg(feature = "c_openssl_1_1")] + use crate::util::c_openssl::ffi::ssl::SSL_get_peer_certificate; + + let certificate = unsafe { + #[cfg(feature = "c_openssl_3_0")] + { + SSL_get1_peer_certificate(ssl) + } + #[cfg(feature = "c_openssl_1_1")] + { + SSL_get_peer_certificate(ssl) + } + }; if certificate.is_null() { return Err(SslError { code: SslErrorCode::SSL,