ddn.crypto.x509.chain

X.509 Certificate Chain Validation (RFC 5280).

Provides functions for building and validating certificate chains, including signature verification, validity period checks, and extension validation.

Types 4

Result of certificate chain validation.

VALIDChain is valid
EXPIREDCertificate has expired
NOT_YET_VALIDCertificate is not yet valid
SIGNATURE_INVALIDSignature verification failed
NO_TRUSTED_ROOTNo trusted root found
NOT_A_CACertificate is not a CA but issued other certificates
PATH_LENGTH_EXCEEDEDPath length constraint exceeded
KEY_USAGE_INVALIDRequired key usage missing
INVALID_CHAINChain is empty or malformed
UNSUPPORTED_ALGORITHMUnknown or unsupported signature algorithm
UNRECOGNIZED_CRITICAL_EXTENSIONCritical extension not recognized

Options for certificate chain validation.

Fields
long validationTimeThe time to use for validity checks (Unix timestamp). If 0, validation is skipped.
bool verifySignaturesWhether to verify signatures in the chain.
bool checkKeyUsageWhether to check key usage extensions.
bool checkBasicConstraintsWhether to check basic constraints.
bool checkCriticalExtensionsWhether to check for unrecognized critical extensions.
string requiredPurposePurpose OID to check in Extended Key Usage (null to skip).

Detailed result of certificate chain validation.

Fields
ValidationResult resultThe overall validation result
string errorMessageHuman-readable error message (if validation failed)
int failingCertIndexIndex of the certificate that caused the failure (-1 if N/A)
X509Certificate[] chainThe validated certificate chain (from end-entity to root)

A collection of trusted root certificates.

The trust store is used during chain validation to determine whether a certificate chain terminates at a trusted root.

Methods
void addTrustedRoot(X509Certificate cert)Adds a trusted root certificate.
void addTrustedRoots(X509Certificate[] certs)Adds multiple trusted root certificates.
void loadFromPem(string pem)Loads trusted roots from PEM data containing multiple certificates.
X509Certificate findIssuer(X509Certificate cert)Finds a trusted root that issued the given certificate.
X509Certificate findTrustedRoot(X509Certificate cert)Finds the stored trusted root matching a presented certificate.
bool isTrusted(X509Certificate cert)Checks if a certificate is in the trust store.
size_t length() @property constReturns the number of trusted roots.
Constructors
this()Creates an empty trust store.

Functions 4

fnValidationReport validateChain(X509Certificate[] chain, TrustStore trustStore, ValidationOptions options = ValidationOptions.init)Validates a certificate chain against a trust store.
fnbool verifySignature(X509Certificate cert, X509Certificate issuer)Verifies that a certificate was signed by the given issuer.
fnbool verifySignatureWithKey(X509Certificate cert, PublicKey publicKey)Verifies a certificate's signature using a public key.
fnbool verifyHostname(X509Certificate cert, string hostname) @safeVerifies that a certificate is valid for the given hostname.