class

Beryl::Certificates::ChainVerification

Inherits Reference < Object

Verifies a certificate chain: builds a path from the leaf through the presented intermediates to a trust anchor and checks every rule of RFC 5280 §6 and the web PKI profile along it.

verification = Beryl::Certificates::ChainVerification.new(Beryl::Certificates::TrustStore.mozilla)
path = verification.verify(leaf, intermediates, identity: Beryl::Certificates::ServiceIdentity.new("example.com"))
# => [leaf, intermediate, root], or raises VerificationFailed

Path building is depth first, trust anchors before intermediates, and candidates whose subject key identifier matches the child's authority key identifier before the others. Issuers are found by name: a leaf or intermediate without an authority key identifier (common under private CAs for PostgreSQL and MySQL) is matched to the certificates named as its issuer, each tried by signature, as Go's crypto/x509 and OpenSSL do. A candidate that fails any check is backed out of and the next one tried, so a chain that also offers an expired or cross-signed intermediate still finds its good path. Cycles are refused. The search is bounded by Limits.

Every certificate on the path must satisfy (the profile that rustls- webpki, Go and x509-limbo apply):

  • version 3; no unknown critical extension; the authority and subject key identifiers, authority information access and policy constraints marked as RFC 5280 requires; a non-empty issuer; below the anchor, a serial number that is positive and at most 20 bytes (some Mozilla roots have a serial number of 0);
  • inside its validity period at the validation time (anchors included);
  • a key Beryl verifies with (RSA of 2,048 to 8,192 bits, P-256, P-384, Ed25519) and, for every certificate below an anchor, a signature by its issuer in one of the algorithms listed in SignatureAlgorithm.

Issuers (intermediates and anchors): basic constraints present, critical and with cA set; keyCertSign when key usage is present; a non-empty subject; path length constraints met, self-issued intermediates not counted; well-formed name constraints, applied to every certificate below them except self-issued intermediates. Intermediates also need a subject key identifier and, when they carry extended key usage, the purpose asked for. An anchor needs no subject key identifier (Mozilla's TWCA Global Root CA has none) and may not carry extended key usage; its authority key identifier, when present, must hold only a key identifier, equal to its subject key identifier when the anchor is self-issued.

The leaf: not a CA, no keyCertSign, no name constraints, and extended key usage either absent or non-critical, without anyExtendedKeyUsage and with the purpose asked for. A server leaf needs a subject alternative name (critical exactly when the subject is empty). A common name is not matched against the reference identity (RFC 9525 §6.1), but it must be well formed: an IP address in canonical form, ASCII only, and an exact copy of a dNSName entry when it holds an A-label or equals one apart from letter case (CA/Browser Forum baseline requirements §7.1.4.3).

Constructors

new(trust_store : TrustStore, *, limits : Limits = Limits.new)
Source

Instance methods

limits
Source
trust_store
Source
verify(leaf : Certificate, list_of_intermediates : Array(Certificate) = [] of Certificate, *, identity : ServiceIdentity | Nil = nil, purpose : Purpose = Purpose::ServerAuthentication, time : Time = Time.utc, required_key_usage : KeyUsage = KeyUsage::None, list_of_revocation_lists : Array(CertificateRevocationList) = [] of CertificateRevocationList, largest_intermediate_count : Int32 | Nil = nil) : Array(Certificate)

Verifies leaf through list_of_intermediates to an anchor of the trust store and returns the path, leaf first and anchor last. Raises VerificationFailed naming the reason.

  • identity: the name the leaf must carry (checked when given).
  • purpose: the extended key usage asked for.
  • time: the validation time.
  • required_key_usage: bits the leaf's key usage must have when it carries the extension (for TLS 1.3, KeyUsage::DigitalSignature).
  • list_of_revocation_lists: CRLs to apply (see CertificateRevocationList).
  • largest_intermediate_count: a caller's own bound on the intermediates of the path, self-issued ones not counted.
Source

Nested types