SaltDns.Certificates.StoreCrypto (Salt v1.0.0)

Encryption of the objects in the certificate store, with a key of its own: SALT_DNS_CERT_STORE_KEY, not the vault key that protects DNS secrets, so that losing one does not open the other. The cipher is SaltDns.Crypto (AES-256-GCM with a key id and a context bound into the authentication); the context is the object's key in the store, so an object copied to another name does not decrypt.

Configuration (config :salt_dns, SaltDns.Certificates):

  • :store_key - base64 of 32 bytes (production: SALT_DNS_CERT_STORE_KEY)
  • :store_key_id - label of the active key, default "s1" (SALT_DNS_CERT_STORE_KEY_ID)
  • :store_retired_keys - %{id => base64} of keys that still decrypt (SALT_DNS_CERT_STORE_RETIRED_KEYS, id:base64 pairs, comma separated)

Rotation: add the old key to the retired keys, set a new key and key id. New versions use the new key; objects are immutable and are never rewritten, so old ones stay readable through the retired key until their certificates have expired (at most the certificate lifetime), then the retired key can be dropped.

Summary

Functions

The id of the active key.

Decrypts the object's content; :error for a wrong key, name or tampered bytes.

Encrypts plaintext for the object object_key; returns {key_id, ciphertext}.

The key id a ciphertext carries.

Functions

active_key_id()

@spec active_key_id() :: String.t()

The id of the active key.

decrypt(ciphertext, object_key)

@spec decrypt(binary(), String.t()) :: {:ok, binary()} | :error

Decrypts the object's content; :error for a wrong key, name or tampered bytes.

encrypt(plaintext, object_key)

@spec encrypt(binary(), String.t()) :: {String.t(), binary()}

Encrypts plaintext for the object object_key; returns {key_id, ciphertext}.

key_id(ciphertext)

@spec key_id(binary()) :: {:ok, String.t()} | :error

The key id a ciphertext carries.