Certbot v0.5.1 Certbot.Certificate View Source

The module provides utility functions to deal with the serial and validity timestamps of a certificate as well as being a struct to store certificate/keys

Link to this section Summary

Functions

Build struct to store a certificate in der format and its private key

Get hexadecimal serial number of the certicate

Get integer serial number of the certicate

Get DateTime of the date the certificate was given out

Get DateTime of the date the certificate will be valid until

Link to this section Types

Link to this type

t()

View Source
t() :: %Certbot.Certificate{cert: binary(), key: {atom(), binary()}}

Link to this section Functions

Link to this function

build(cert, arg)

View Source
build(binary(), {:ECPrivateKey, binary()} | {:RSAPrivateKey, binary()}) ::
  Certbot.Certificate.t()

Build struct to store a certificate in der format and its private key

For example, to generate a

    cert_file = File.read!("priv/cert/selfsigned.pem")
    key_file = File.read!("priv/cert/selfsigned_key.pem")

    [certificate] = :public_key.pem_decode(cert_file)
    cert = :public_key.pem_entry_decode(certificate)
    cert = :public_key.der_encode(:Certificate, cert)

    [key] = :public_key.pem_decode(key_file)
    key = :public_key.pem_entry_decode(key)
    der_key = :public_key.der_encode(:RSAPrivateKey, key)

    Certbot.Certificate.build(cert, {:RSAPrivateKey, der_key})

Get hexadecimal serial number of the certicate

This is what is visible when inspecting a certificate in the browser

Example

iex> Certbot.Certificate.hex_serial(build_certificate())
"FC100FFC200BF62F"

Get integer serial number of the certicate

iex> Certbot.Certificate.serial(build_certificate())
18163034872729040431

Get DateTime of the date the certificate was given out

Example

iex> Certbot.Certificate.valid_from(build_certificate())
~U[2019-07-09 00:00:00Z]
Link to this function

valid_until(certificate)

View Source
valid_until(Certbot.Certificate.t()) :: DateTime.t()

Get DateTime of the date the certificate will be valid until

Example

iex> Certbot.Certificate.valid_until(build_certificate())
~U[2020-07-09 00:00:00Z]