Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: sync with upstream Rustls error changes #471

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::sync::Arc;
use crate::ffi_panic_boundary;
use libc::{c_char, c_uint, size_t};
use rustls::server::VerifierBuilderError;
use rustls::{CertRevocationListError, CertificateError, Error, InvalidMessage};
use rustls::{
CertRevocationListError, CertificateError, EncryptedClientHelloError, Error, InconsistentKeys,
InvalidMessage,
};

/// A return value for a function that may return either success (0) or a
/// non-zero value representing an error.
Expand Down Expand Up @@ -97,7 +100,8 @@ u32_enum_builder! {
CertInvalidPurpose => 7129,
CertApplicationVerificationFailure => 7130,
CertOtherError => 7131,
CertUnknownRevocationStatus => 7154, // Last added.
CertUnknownRevocationStatus => 7154,
CertExpiredRevocationList => 7156, // Last added.

// From InvalidMessage, with fields that get flattened.
// https://docs.rs/rustls/0.21.0/rustls/enum.Error.html#variant.InvalidMessage
Expand All @@ -122,6 +126,7 @@ u32_enum_builder! {
MessageUnsupportedCurveType => 7151,
MessageUnsupportedKeyExchangeAlgorithm => 7152,
MessageInvalidOther => 7153,
MessageCertificatePayloadTooLarge => 7155,

// From Error, with fields that get dropped.
PeerIncompatibleError => 7107,
Expand Down Expand Up @@ -190,7 +195,16 @@ u32_enum_builder! {
CertRevocationListUnsupportedRevocationReason => 7410,

// From ClientCertVerifierBuilderError, with fields that get flattened.
ClientCertVerifierBuilderNoRootAnchors => 7500
ClientCertVerifierBuilderNoRootAnchors => 7500,

// From InconsistentKeys, with fields that get flattened.
InconsistentKeysKeysMismatch => 7600,
InconsistentKeysUnknown => 7601,

// From InvalidEncryptedClientHello, with fields that get flattened.
InvalidEncryptedClientHelloInvalidConfigList => 7700,
InvalidEncryptedClientHelloNoCompatibleConfig => 7701,
InvalidEncryptedClientHelloSniRequired => 7702
}
}

Expand Down Expand Up @@ -267,6 +281,7 @@ pub(crate) fn cert_result_to_error(result: rustls_result) -> Error {
CertApplicationVerificationFailure => {
InvalidCertificate(CertificateError::ApplicationVerificationFailure)
}
CertExpiredRevocationList => InvalidCertificate(CertificateError::ExpiredRevocationList),
CertOtherError => InvalidCertificate(CertificateError::Other(OtherError(Arc::from(
Box::from(""),
)))),
Expand Down Expand Up @@ -319,6 +334,7 @@ pub(crate) fn map_error(input: Error) -> rustls_result {

Error::InvalidMessage(e) => match e {
InvalidMessage::HandshakePayloadTooLarge => MessageHandshakePayloadTooLarge,
InvalidMessage::CertificatePayloadTooLarge => MessageCertificatePayloadTooLarge,
InvalidMessage::InvalidCcs => MessageInvalidCcs,
InvalidMessage::InvalidContentType => MessageInvalidContentType,
InvalidMessage::InvalidCertificateStatusType => MessageInvalidCertStatusType,
Expand Down Expand Up @@ -356,6 +372,7 @@ pub(crate) fn map_error(input: Error) -> rustls_result {
CertificateError::UnhandledCriticalExtension => CertUnhandledCriticalExtension,
CertificateError::UnknownIssuer => CertUnknownIssuer,
CertificateError::UnknownRevocationStatus => CertUnknownRevocationStatus,
CertificateError::ExpiredRevocationList => CertExpiredRevocationList,
CertificateError::BadSignature => CertBadSignature,
CertificateError::NotValidForName => CertNotValidForName,
CertificateError::InvalidPurpose => CertInvalidPurpose,
Expand Down Expand Up @@ -406,6 +423,9 @@ pub(crate) fn map_error(input: Error) -> rustls_result {

Error::InvalidCertRevocationList(e) => map_crl_error(e),

Error::InconsistentKeys(InconsistentKeys::KeyMismatch) => InconsistentKeysKeysMismatch,
Error::InconsistentKeys(InconsistentKeys::Unknown) => InconsistentKeysUnknown,

_ => General,
}
}
Expand Down Expand Up @@ -521,6 +541,9 @@ impl Display for rustls_result {
CertUnknownRevocationStatus => {
Error::InvalidCertificate(CertificateError::UnknownRevocationStatus).fmt(f)
}
CertExpiredRevocationList => {
Error::InvalidCertificate(CertificateError::ExpiredRevocationList).fmt(f)
}
CertOtherError => write!(f, "unknown certificate error"),

// These variants correspond to a rustls::Error variant with a field,
Expand All @@ -532,6 +555,9 @@ impl Display for rustls_result {
MessageHandshakePayloadTooLarge => {
Error::InvalidMessage(InvalidMessage::HandshakePayloadTooLarge).fmt(f)
}
MessageCertificatePayloadTooLarge => {
Error::InvalidMessage(InvalidMessage::CertificatePayloadTooLarge).fmt(f)
}
MessageInvalidContentType => {
Error::InvalidMessage(InvalidMessage::InvalidContentType).fmt(f)
}
Expand Down Expand Up @@ -688,6 +714,23 @@ impl Display for rustls_result {
.fmt(f),

ClientCertVerifierBuilderNoRootAnchors => write!(f, "no root trust anchors provided"),

InconsistentKeysKeysMismatch => {
Error::InconsistentKeys(InconsistentKeys::KeyMismatch).fmt(f)
}
InconsistentKeysUnknown => Error::InconsistentKeys(InconsistentKeys::Unknown).fmt(f),

InvalidEncryptedClientHelloInvalidConfigList => {
Error::InvalidEncryptedClientHello(EncryptedClientHelloError::InvalidConfigList)
.fmt(f)
}
InvalidEncryptedClientHelloNoCompatibleConfig => {
Error::InvalidEncryptedClientHello(EncryptedClientHelloError::NoCompatibleConfig)
.fmt(f)
}
InvalidEncryptedClientHelloSniRequired => {
Error::InvalidEncryptedClientHello(EncryptedClientHelloError::SniRequired).fmt(f)
}
}
}
}
7 changes: 7 additions & 0 deletions src/rustls.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum rustls_result {
RUSTLS_RESULT_CERT_APPLICATION_VERIFICATION_FAILURE = 7130,
RUSTLS_RESULT_CERT_OTHER_ERROR = 7131,
RUSTLS_RESULT_CERT_UNKNOWN_REVOCATION_STATUS = 7154,
RUSTLS_RESULT_CERT_EXPIRED_REVOCATION_LIST = 7156,
RUSTLS_RESULT_MESSAGE_HANDSHAKE_PAYLOAD_TOO_LARGE = 7133,
RUSTLS_RESULT_MESSAGE_INVALID_CCS = 7134,
RUSTLS_RESULT_MESSAGE_INVALID_CONTENT_TYPE = 7135,
Expand All @@ -69,6 +70,7 @@ enum rustls_result {
RUSTLS_RESULT_MESSAGE_UNSUPPORTED_CURVE_TYPE = 7151,
RUSTLS_RESULT_MESSAGE_UNSUPPORTED_KEY_EXCHANGE_ALGORITHM = 7152,
RUSTLS_RESULT_MESSAGE_INVALID_OTHER = 7153,
RUSTLS_RESULT_MESSAGE_CERTIFICATE_PAYLOAD_TOO_LARGE = 7155,
RUSTLS_RESULT_PEER_INCOMPATIBLE_ERROR = 7107,
RUSTLS_RESULT_PEER_MISBEHAVED_ERROR = 7108,
RUSTLS_RESULT_INAPPROPRIATE_MESSAGE = 7109,
Expand Down Expand Up @@ -121,6 +123,11 @@ enum rustls_result {
RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_INDIRECT_CRL = 7409,
RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_REVOCATION_REASON = 7410,
RUSTLS_RESULT_CLIENT_CERT_VERIFIER_BUILDER_NO_ROOT_ANCHORS = 7500,
RUSTLS_RESULT_INCONSISTENT_KEYS_KEYS_MISMATCH = 7600,
RUSTLS_RESULT_INCONSISTENT_KEYS_UNKNOWN = 7601,
RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_INVALID_CONFIG_LIST = 7700,
RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_NO_COMPATIBLE_CONFIG = 7701,
RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_SNI_REQUIRED = 7702,
};
typedef uint32_t rustls_result;

Expand Down