Kantoor. Push. Vapid
(Kantoor v1.0.0)
The installation's VAPID key pair and the sub claim web push needs.
Where the keys come from
- The environment, when both are set:
VAPID_PUBLIC_KEYandVAPID_PRIVATE_KEY(base64url, no padding;VAPID_SUBJECToptional). Nothing is written to the database then. - Otherwise one pair is generated on first use and kept in
push_keys(row 1). The private key is encrypted withKantoor.VaultwhenKANTOOR_VAULT_KEYis configured (scheme: "vault"), and stored as is when it is not (scheme: "plain", which the settings page warns about).
Why a stored pair is acceptable: the key is the installation's own,
made here; no third party is involved and no account is created. Rotating it
invalidates every existing browser subscription, so rotate/0 is a
deliberate, logged operation, not something that happens by itself.
Caching: the pair is the same for the life of a release, so it is read
once and kept in :persistent_term (disable with
config :kantoor, push_key_cache: false, which tests do).
Summary
Functions
Base64url without padding, the encoding web push uses.
Makes a new pair unless one already exists, and returns it. Safe to call from several replicas at once: the insert is guarded by the primary key.
The pair and subject, as %{public:, private:, subject:}.
The base64url public key a browser subscribes with.
Replaces the stored pair with a new one. Every existing subscription stops working (the browsers must subscribe again with the new public key), so this is for an operator who has decided to. Returns the new pair.
Whether the stored private key is encrypted, plain, or not stored at all.
The VAPID sub claim (a mailto: address the push service may contact).
Functions
Base64url without padding, the encoding web push uses.
Makes a new pair unless one already exists, and returns it. Safe to call from several replicas at once: the insert is guarded by the primary key.
@spec forget() :: :ok
Forgets a cached pair (after rotate/0, and between tests).
The pair and subject, as %{public:, private:, subject:}.
@spec public_key() :: String.t()
The base64url public key a browser subscribes with.
Replaces the stored pair with a new one. Every existing subscription stops working (the browsers must subscribe again with the new public key), so this is for an operator who has decided to. Returns the new pair.
@spec storage() :: :vault | :plain | :none | :environment
Whether the stored private key is encrypted, plain, or not stored at all.
@spec subject() :: String.t()
The VAPID sub claim (a mailto: address the push service may contact).