mirror of
https://github.com/KumoCorp/kumomta.git
synced 2026-09-07 08:00:56 +00:00
This is not fully baked yet, but I want to checkpoint. refs: https://github.com/KumoCorp/kumomta/issues/16
113 lines
3.7 KiB
Rust
113 lines
3.7 KiB
Rust
use dns_resolver::DnsError;
|
|
use thiserror::Error;
|
|
|
|
/// DKIM error status
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
pub enum Status {
|
|
Permfail,
|
|
Tempfail,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Clone, Error)]
|
|
/// DKIM errors
|
|
pub enum DKIMError {
|
|
#[error("unsupported hash algorithm: {0}")]
|
|
UnsupportedHashAlgorithm(String),
|
|
#[error("unsupported canonicalization: {0}")]
|
|
UnsupportedCanonicalizationType(String),
|
|
#[error("signature syntax error: {0}")]
|
|
SignatureSyntaxError(String),
|
|
#[error("signature missing required tag ({0})")]
|
|
SignatureMissingRequiredTag(&'static str),
|
|
#[error("incompatible version")]
|
|
IncompatibleVersion,
|
|
#[error("domain mismatch")]
|
|
DomainMismatch,
|
|
#[error("From field not signed")]
|
|
FromFieldNotSigned,
|
|
#[error("signature expired")]
|
|
SignatureExpired,
|
|
#[error("unacceptable signature header")]
|
|
UnacceptableSignatureHeader,
|
|
#[error("unsupported query method")]
|
|
UnsupportedQueryMethod,
|
|
#[error("key unavailable: {0}")]
|
|
KeyUnavailable(String),
|
|
#[error("internal error: {0}")]
|
|
UnknownInternalError(String),
|
|
#[error("no key for signature")]
|
|
NoKeyForSignature,
|
|
#[error("key syntax error")]
|
|
KeySyntaxError,
|
|
#[error("key incompatible version")]
|
|
KeyIncompatibleVersion,
|
|
#[error("inappropriate key algorithm")]
|
|
InappropriateKeyAlgorithm,
|
|
#[error("signature did not verify")]
|
|
SignatureDidNotVerify,
|
|
#[error("body hash did not verify")]
|
|
BodyHashDidNotVerify,
|
|
#[error("malformed email body")]
|
|
MalformedBody,
|
|
#[error("failed sign: {0}")]
|
|
FailedToSign(String),
|
|
#[error("failed to build object: {0}")]
|
|
BuilderError(&'static str),
|
|
#[error("failed to serialize DKIM header: {0}")]
|
|
HeaderSerializeError(String),
|
|
#[error("failed to load private key: {0}")]
|
|
PrivateKeyLoadError(String),
|
|
#[error("failed to parse message: {0:#}")]
|
|
MailParsingError(#[from] mailparsing::MailParsingError),
|
|
#[error("Canonical CRLF line endings are required for correct signing and verification")]
|
|
CanonicalLineEndingsRequired,
|
|
#[error(transparent)]
|
|
Dns(#[from] DnsError),
|
|
#[error("ARC instance tag is invalid")]
|
|
InvalidARCInstance,
|
|
#[error("ARC Set Instance {0} has duplicate headers")]
|
|
DuplicateARCInstance(u8),
|
|
#[error("ARC Set Instance {0} has missing headers")]
|
|
MissingARCInstance(u8),
|
|
}
|
|
|
|
impl DKIMError {
|
|
pub fn status(self) -> Status {
|
|
use DKIMError::*;
|
|
match self {
|
|
SignatureSyntaxError(_)
|
|
| SignatureMissingRequiredTag(_)
|
|
| IncompatibleVersion
|
|
| DomainMismatch
|
|
| FromFieldNotSigned
|
|
| SignatureExpired
|
|
| UnacceptableSignatureHeader
|
|
| UnsupportedQueryMethod
|
|
| NoKeyForSignature
|
|
| KeySyntaxError
|
|
| KeyIncompatibleVersion
|
|
| InappropriateKeyAlgorithm
|
|
| SignatureDidNotVerify
|
|
| BodyHashDidNotVerify
|
|
| MalformedBody
|
|
| CanonicalLineEndingsRequired
|
|
| InvalidARCInstance
|
|
| DuplicateARCInstance(_)
|
|
| MissingARCInstance(_)
|
|
| MailParsingError(_)
|
|
| UnsupportedCanonicalizationType(_)
|
|
| UnsupportedHashAlgorithm(_) => Status::Permfail,
|
|
KeyUnavailable(_)
|
|
| UnknownInternalError(_)
|
|
| BuilderError(_)
|
|
| FailedToSign(_)
|
|
| PrivateKeyLoadError(_)
|
|
| HeaderSerializeError(_) => Status::Tempfail,
|
|
Dns(dns) => match dns {
|
|
DnsError::InvalidName(_) => Status::Permfail,
|
|
DnsError::ResolveFailed(_) => Status::Tempfail,
|
|
},
|
|
}
|
|
}
|
|
}
|