class

Beryl::Certificates::Certificate

Inherits Reference < Object

An X.509 certificate (RFC 5280 §4.1), read from DER.

certificate = Beryl::Certificates::Certificate.new(der_bytes)
certificate.subject.to_s      # => "CN=example.com"
certificate.list_of_dns_names # => ["example.com"]
certificate.not_after         # => 2027-01-01 00:00:00 UTC

Reading checks the whole structure strictly (DER, every field of the signed part, the contents of every extension Beryl knows, no extension twice, the signature algorithm equal inside and outside the signed part) and raises MalformedCertificate on any violation. Whether the certificate may be used for anything is the job of ChainVerification.

Constants

LIST_OF_UNDERSTOOD_EXTENSIONS = [ObjectIdentifiers::BASIC_CONSTRAINTS, ObjectIdentifiers::KEY_USAGE, ObjectIdentifiers::EXTENDED_KEY_USAGE, ObjectIdentifiers::SUBJECT_ALTERNATIVE_NAME, ObjectIdentifiers::NAME_CONSTRAINTS, ObjectIdentifiers::AUTHORITY_KEY_IDENTIFIER, ObjectIdentifiers::SUBJECT_KEY_IDENTIFIER, ObjectIdentifiers::CERTIFICATE_POLICIES, ObjectIdentifiers::POLICY_CONSTRAINTS, ObjectIdentifiers::AUTHORITY_INFORMATION_ACCESS]

The extension identifiers Beryl reads and acts on, or knows to be safe to accept when marked critical: a critical extension outside this set makes the certificate unusable (RFC 5280 §4.2).

Constructors

new(encoded : Bytes, *, limits : DER::Limits = DER::Limits.new)

Reads the DER certificate in encoded. Raises MalformedCertificate.

Source

Class methods

list_from_pem(text : String) : Array(Certificate)

Reads every CERTIFICATE block of the PEM text.

Source

Instance methods

==(other : Certificate) : Bool
Source
authority_information_access_count

The number of access descriptions in the authority information access extension, or nil without one.

Source
authority_key_identifier
Source
basic_constraints
Source
certificate_authority?

Returns whether basic constraints mark this a CA certificate.

Source
encoded

The whole certificate encoding.

Source
extension(identifier : DER::ObjectIdentifier) : Extension | Nil

The extension with identifier, or nil.

Source
has_unknown_critical_extension?

Returns whether an extension marked critical is outside LIST_OF_UNDERSTOOD_EXTENSIONS.

Source
hash(hasher)

See Object#hash(hasher)

Source
inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Source
issuer
Source
key_usage
Source
list_of_dns_names

The DNS names among the subject alternative names, as text.

Source
list_of_extended_key_usages
Source
list_of_extensions
Source
list_of_ip_addresses

The IP addresses among the subject alternative names, as bytes.

Source
list_of_subject_alternative_names
Source
name_constraints
Source
not_after
Source
not_before
Source
policy_constraints
Source
self_issued?

Returns whether the subject and issuer names are the same (RFC 5280 §6.1: a self-issued certificate).

Source
serial_number

The serial number's two's-complement contents.

Source
signature
Source
signature_algorithm
Source
signed_by?(issuer_key : VerificationKey) : Bool

Returns whether issuer_key verifies this certificate's signature.

Source
subject
Source
subject_key_identifier
Source
subject_public_key_info
Source
to_be_signed

The signed part (TBSCertificate), the bytes the signature covers.

Source
to_pem
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
valid_at?(time : Time) : Bool

Returns whether time is within notBefore and notAfter, both inclusive (RFC 5280 §4.1.2.5). Fractions of a second in time are dropped first, since certificate times have whole seconds.

Source
version

1, 2 or 3.

Source

Nested types