Countersign.Seal.Cert (Countersign v0.1.0)

Copy Markdown View Source

The seal's certificates and keys: a self-signed X.509 certificate for an Ed25519 or SLH-DSA key, what the seal reads from one, and their PEM form.

A private key's PEM is PKCS #8 (PRIVATE KEY): for Ed25519 the private key is wrapped as RFC 8410 7 says (an OCTET STRING holding the 32-byte key), for SLH-DSA it is the raw key in the OCTET STRING (RFC 9909 6). The certificate's subject public key and signature carry the same algorithm's OID, with parameters absent.

Summary

Types

What parse/1 reads from a certificate.

Functions

A certificate's PEM.

The {cert_der, private_key} pair a certificate PEM and a PKCS #8 key PEM hold, as Countersign.Seal.seal/3 takes it, checked to be of the same algorithm: {:error, :bad_certificate | :bad_key | :alg_mismatch} otherwise. Whether the key matches the certificate is seal/3's check.

A private key's PKCS #8 PEM.

What the seal needs from a certificate, or :error for one it cannot read.

A self-signed certificate for a fresh key of alg, valid for years from now: {cert_der, private_key}. subject is the common name; :org adds an organization.

Types

info()

@type info() :: %{
  alg: Countersign.Seal.alg(),
  public_key: binary(),
  subject: String.t(),
  issuer_der: binary(),
  serial_der: binary(),
  der: binary()
}

What parse/1 reads from a certificate.

Functions

cert_pem(der)

@spec cert_pem(binary()) :: String.t()

A certificate's PEM.

from_pem(cert_pem, key_pem)

@spec from_pem(String.t(), String.t()) ::
  {:ok, {Countersign.Seal.alg(), {binary(), binary()}}}
  | {:error, :bad_certificate | :bad_key | :alg_mismatch}

The {cert_der, private_key} pair a certificate PEM and a PKCS #8 key PEM hold, as Countersign.Seal.seal/3 takes it, checked to be of the same algorithm: {:error, :bad_certificate | :bad_key | :alg_mismatch} otherwise. Whether the key matches the certificate is seal/3's check.

key_pem(alg, private)

@spec key_pem(Countersign.Seal.alg(), binary()) :: String.t()

A private key's PKCS #8 PEM.

parse(der)

@spec parse(binary()) :: {:ok, info()} | :error

What the seal needs from a certificate, or :error for one it cannot read.

self_signed(alg, subject, opts \\ [])

@spec self_signed(Countersign.Seal.alg(), String.t(), keyword()) ::
  {binary(), binary()}

A self-signed certificate for a fresh key of alg, valid for years from now: {cert_der, private_key}. subject is the common name; :org adds an organization.