module

Beryl::Certificates

X.509 certificates and certificate path validation, written in Crystal.

The calls on this module use the choices Beryl recommends: the pinned Mozilla root set, the current time and the serverAuth purpose.

chain = Beryl::Certificates.read_pem_chain(File.read("chain.pem"))
Beryl::Certificates.verify_server_chain(chain, hostname: "example.com") # => the verified path, or raises
key = Beryl::Certificates.read_private_key(File.read("server.key"))

ChainVerification takes another trust store (TrustStore.system, TrustStore.from_pem), a validation time, a client purpose, CRLs and limits. See docs/certificates.md for the profile it enforces and the test suites behind it.

Constants

Log = ::Log.for(self)

Class methods

read_pem_chain(text : String) : Array(Certificate)

Reads every certificate of the PEM text, in order (the leaf first, as TLS servers and chain.pem files hold them).

Source
read_private_key(text : String) : SigningKey

Reads the first private key in the PEM text (PKCS #8, SEC 1 or PKCS #1).

Source
verify_server_chain(chain : Array(Certificate), *, hostname : String, trust_store : TrustStore = TrustStore.mozilla) : Array(Certificate)

Verifies chain (the leaf first, then the intermediates in any order) for a TLS server named hostname (a DNS name or an IP address), against the Mozilla root set at the current time. Returns the verified path, leaf first, or raises VerificationFailed.

Source

Nested types