Kantoor. Vault
(Kantoor v1.0.0)
Encryption at rest for the secrets Kantoor keeps itself: the signing
secret of each Karta endpoint it registered, and the address of each subscribed
calendar (Kantoor.Feeds), which is a secret in its own right. AES-256-GCM through :crypto, a
fresh random 96-bit IV for every value, the same scheme as Karta's vault.
Configuration (application environment, read from the environment by
config/runtime.exs):
KANTOOR_VAULT_KEY: the active key, base64 of 32 bytes (openssl rand -base64 32);KANTOOR_VAULT_KEY_ID(defaultv1): the label new values carry;KANTOOR_VAULT_RETIRED_KEYS:id:base64pairs separated by commas, keys that can still decrypt old values after a rotation.
A stored value is
<<1, byte_size(key_id), key_id, iv::12, tag::16, ciphertext>>The version, the key id and a context string are authenticated, so a value cannot be relabelled as another key's or used in another place.
To rotate: move the old key into KANTOOR_VAULT_RETIRED_KEYS under its id, set
a new KANTOOR_VAULT_KEY and KANTOOR_VAULT_KEY_ID, restart, run
Kantoor.Vault.reencrypt/0 (bin/kantoor rpc "Kantoor.Vault.reencrypt()"), and
drop the retired key afterwards.
Without a key nothing is stored: the secret of a new endpoint is then shown
once, as before. If values are stored and the key is missing or wrong,
check!/0 stops the boot with a message that says which.
Summary
Functions
Called at boot. Raises when secrets are stored and the key is missing, or when one of them does not decrypt with the keys given (a wrong or lost key).
Whether a key is configured, so values can be stored.
Decrypts with the key the value names, from the active or the retired ones.
Decrypts a domain's Karta key (see encrypt_karta_key/1).
Decrypts the VAPID private key (see encrypt_push_key/1).
Encrypts with the active key. {:error, :no_key} when none is configured.
Encrypts a domain's Karta key. The context string keeps it from being read as an endpoint secret or the other way round.
Encrypts the installation's VAPID private key (Kantoor.Push.Vapid). Its own
context keeps it from being read as an endpoint secret or a Karta key.
Every key that can decrypt, by id.
Encrypts every stored secret again with the active key. Run after a rotation, then drop the retired key.
The signing secrets of the endpoints Kantoor registered, decrypted. A value that
will not decrypt is skipped (and check!/0 has complained about it at boot).
Functions
@spec check!() :: :ok
Called at boot. Raises when secrets are stored and the key is missing, or when one of them does not decrypt with the keys given (a wrong or lost key).
@spec configured?() :: boolean()
Whether a key is configured, so values can be stored.
Decrypts with the key the value names, from the active or the retired ones.
Decrypts a domain's Karta key (see encrypt_karta_key/1).
Decrypts the VAPID private key (see encrypt_push_key/1).
Encrypts with the active key. {:error, :no_key} when none is configured.
Encrypts a domain's Karta key. The context string keeps it from being read as an endpoint secret or the other way round.
Encrypts the installation's VAPID private key (Kantoor.Push.Vapid). Its own
context keeps it from being read as an endpoint secret or a Karta key.
Every key that can decrypt, by id.
@spec reencrypt() :: {:ok, non_neg_integer()} | {:error, :undecryptable}
Encrypts every stored secret again with the active key. Run after a rotation, then drop the retired key.
@spec stored_secrets() :: [String.t()]
The signing secrets of the endpoints Kantoor registered, decrypted. A value that
will not decrypt is skipped (and check!/0 has complained about it at boot).