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 43f4b1badc4150c468cb61b5faa3641101ff1bce..d4def286dda5bdd2780d93dff4b835869e3fc04b 100644 --- a/ylong_http_client/src/util/c_openssl/ssl/stream.rs +++ b/ylong_http_client/src/util/c_openssl/ssl/stream.rs @@ -258,10 +258,7 @@ fn verify_server_cert(ssl: *const SSL, pinned_key: &str) -> Result<(), SslError> if certificate.is_null() { return Err(SslError { code: SslErrorCode::SSL, - internal: Some(InternalError::User(VerifyError::from_msg( - PubKeyPinning, - "Failed to get the peer certificate.", - ))), + internal: Some(InternalError::Ssl(ErrorStack::get())), }); } @@ -270,10 +267,7 @@ fn verify_server_cert(ssl: *const SSL, pinned_key: &str) -> Result<(), SslError> unsafe { X509_free(certificate) }; return Err(SslError { code: SslErrorCode::SSL, - internal: Some(InternalError::User(VerifyError::from_msg( - PubKeyPinning, - "Failed to get the length of the peer public key.", - ))), + internal: Some(InternalError::Ssl(ErrorStack::get())), }); } let key = vec![0u8; size_1 as usize]; @@ -283,10 +277,7 @@ fn verify_server_cert(ssl: *const SSL, pinned_key: &str) -> Result<(), SslError> unsafe { X509_free(certificate) }; return Err(SslError { code: SslErrorCode::SSL, - internal: Some(InternalError::User(VerifyError::from_msg( - PubKeyPinning, - "Failed to read the peer public key.", - ))), + internal: Some(InternalError::Ssl(ErrorStack::get())), }); } diff --git a/ylong_http_client/src/util/c_openssl/verify/pinning.rs b/ylong_http_client/src/util/c_openssl/verify/pinning.rs index 7c6851b6dc5e46f0bc4a19a8b9825f02bbded84e..916704fa67c15716d39bd6511eaf496df21435e9 100644 --- a/ylong_http_client/src/util/c_openssl/verify/pinning.rs +++ b/ylong_http_client/src/util/c_openssl/verify/pinning.rs @@ -16,8 +16,7 @@ use std::collections::HashMap; use libc::c_int; use ylong_http::request::uri::Uri; -use crate::util::c_openssl::error::VerifyError; -use crate::util::c_openssl::error::VerifyKind::PubKeyPinning; +use crate::util::c_openssl::error::ErrorStack; use crate::util::c_openssl::ffi::x509::{ EVP_DigestFinal_ex, EVP_DigestInit, EVP_DigestUpdate, EVP_MD_CTX_free, EVP_MD_CTX_new, EVP_sha256, @@ -179,10 +178,7 @@ pub(crate) unsafe fn sha256_digest( if md_ctx.is_null() { return Err(SslError { code: SslErrorCode::SSL, - internal: Some(InternalError::User(VerifyError::from_msg( - PubKeyPinning, - "Failed to allocates a digest context.", - ))), + internal: Some(InternalError::Ssl(ErrorStack::get())), }); } let init = EVP_DigestInit(md_ctx, EVP_sha256()); @@ -190,10 +186,7 @@ pub(crate) unsafe fn sha256_digest( EVP_MD_CTX_free(md_ctx); return Err(SslError { code: SslErrorCode::SSL, - internal: Some(InternalError::User(VerifyError::from_msg( - PubKeyPinning, - "Failed to set up digest context.", - ))), + internal: Some(InternalError::Ssl(ErrorStack::get())), }); } EVP_DigestUpdate(md_ctx, pub_key.as_ptr(), len); diff --git a/ylong_http_client/tests/sdv_async_https_pinning.rs b/ylong_http_client/tests/sdv_async_https_pinning.rs index dcf8547cf347eb3db8680d8410bfb02ee65315df..794b6ede16e737edd47592da83cf62cb6a871099 100644 --- a/ylong_http_client/tests/sdv_async_https_pinning.rs +++ b/ylong_http_client/tests/sdv_async_https_pinning.rs @@ -280,7 +280,7 @@ fn sdv_client_public_key_pinning_error() { assert_eq!( format!("{:?}", response.expect("response is not an error")), - "HttpClientError { ErrorKind: Connect, Cause: Custom { kind: Other, error: SslError {\ + "HttpClientError { ErrorKind: Connect, Cause: Custom { kind: Other, error: SslError { \ code: SslErrorCode(1), internal: Some(User(VerifyError { ErrorKind: PubKeyPinning, \ Cause: Pinned public key verification failed. })) } } }" );