Public facade for KMS encryption, identity, authorization, recovery, and WebAuthn APIs.

Encryption, identity, authorization, recovery, and WebAuthn calls route through KMS.Client, which delegates to the configured backend:

Embedded signing-key functions use KMS.Signing directly and are intentionally absent from the remote HTTP API. Most functions return {:ok, value} or {:error, reason}.

Basic alias encryption

{:ok, _kek} = KMS.create_alias("owner:alice")

{:ok, encrypted} =
  KMS.encrypt_alias("secret", "owner:alice", aad: "document:123/body")

{:ok, "secret"} =
  KMS.decrypt_alias(encrypted, "owner:alice", aad: "document:123/body")

:aad is additional authenticated data. It is not secret, but decrypt must use the exact same value supplied to encrypt.

Authorization

Local calls without :session are trusted/admin calls for RMK-only aliases. Session-protected aliases require a recipient secret even for trusted callers. Pass a session secret when KMS should enforce principal bindings:

KMS.decrypt_alias(ciphertext, "tenant/acme/docs",
  session: session.secret,
  aad: "document:123/body"
)

See docs/authz-bindings.md and docs/elixir-api.md for task-oriented guides.

Summary

Functions

Adds tags to a KEK alias and returns the updated tag list.

Advances a pending MFA session with factor input.

Begins WebAuthn/passkey authentication for a principal.

Begins WebAuthn/passkey registration for a principal.

Creates or returns the active KEK for alias_name.

Creates a binding granting a permission on a scope to a principal.

Registers a fallback public key for break-glass recovery envelopes.

Creates a session from a high-entropy caller passphrase.

Creates a principal with password/private-key material protected by KMS.

Creates a principal, enforcing principal.create when :session is supplied.

Creates a principal factor such as TOTP or WebAuthn.

Creates a password-authenticated session for a principal.

Creates a password-authenticated session with options.

Decrypts ciphertext with the active KEK for alias_name.

Decrypts data produced by encrypt_rmk_pdk/3 with the same high-entropy secret.

Deletes a binding.

Deletes a fallback public key.

Deletes a principal.

Deletes a principal factor.

Deletes a session by bearer secret.

Deletes all sessions for a principal.

Encrypts cleartext with the active KEK for alias_name.

Encrypts cleartext with a caller-supplied high-entropy secret and RMK wrapping.

Fetches an authenticated, non-expired session by bearer secret.

Fetches the active signing key with the requested version.

Fetches a binding by id.

Fetches a fallback public key by id.

Fetches a fallback public key by name.

Fetches a principal by {kind, ref}.

Fetches a principal factor by id.

Fetches a session by bearer secret.

Finishes WebAuthn/passkey authentication and returns a KMS session.

Finishes WebAuthn/passkey registration with a browser response.

Returns a binding, nil when absent, or {:error, reason} when the backend fails.

Returns a principal, nil when absent, or {:error, reason} when the backend fails.

Returns a principal factor, nil when absent, or {:error, reason} when the backend fails.

Returns a session, nil when absent, or {:error, reason} when the backend fails.

Installs one active RMK-wrapped P-256 signing key.

Idempotently installs an exact RMK-wrapped P-256 signing key.

Lists bindings for a principal id.

Lists registered fallback public keys.

Returns active KEK aliases containing tag.

Lists fallback envelopes for a KEK.

Returns tags attached to a KEK alias.

Lists factors for a principal.

Lists fallback envelopes for a principal.

Lists principals visible to the caller.

Lists sessions for a principal.

Extends an active session idle expiry without rotating the bearer secret.

Refreshes a session and rotates the bearer secret.

Removes tags from a KEK alias and returns the updated tag list.

Revokes one passphrase wrapping, including access through sessions already created from it.

Wraps a session-protected alias for a high-entropy passphrase; returns its wrapping id.

Rotates fallback public-key envelopes using the old private key.

Signs one caller-supplied 32-byte SHA-256 digest with the active P-256 key.

Returns the default AAD for an RMK-wrapped signing-key version.

Returns the DER-encoded public key for an active signing-key version.

Unwraps a KEK through a fallback private key from trusted local code.

Unwraps principal private-key material through a fallback private key.

Updates a binding.

Updates a principal factor.

Loads and validates an active signing key, warming its private cache entry.

Verifies a DER P-256 signature over one caller-supplied 32-byte SHA-256 digest.

Functions

add_kek_tags(alias_name, tags, opts \\ [])

Adds tags to a KEK alias and returns the updated tag list.

advance_session(secret, attrs)

Advances a pending MFA session with factor input.

begin_webauthn_authentication(kind, ref, opts \\ [])

Begins WebAuthn/passkey authentication for a principal.

begin_webauthn_registration(kind, ref, opts \\ [])

Begins WebAuthn/passkey registration for a principal.

create_alias(alias_name, opts \\ [])

Creates or returns the active KEK for alias_name.

Options:

  • :tags - list of metadata tags.
  • :session - session secret for kek.create authorization and recipient wrapping.

New aliases with a session use protection: "session"; the KEK is sealed for that recipient, with no RMK-only key copy. Principal creators receive encrypt, decrypt, rewrap, and tag-management bindings. Without a session, new aliases use the existing protection: "rmk" model. Existing aliases are never converted.

See docs/use_cases/factor_bound_aliases.md for a complete example.

create_binding(principal_id, attrs)

Creates a binding granting a permission on a scope to a principal.

create_fallback_public_key(attrs)

Registers a fallback public key for break-glass recovery envelopes.

create_passphrase_session(attrs)

Creates a session from a high-entropy caller passphrase.

create_principal(attrs)

Creates a principal with password/private-key material protected by KMS.

create_principal(attrs, opts)

Creates a principal, enforcing principal.create when :session is supplied.

create_principal_factor(kind, ref, attrs)

Creates a principal factor such as TOTP or WebAuthn.

create_session(kind, ref, attrs)

Creates a password-authenticated session for a principal.

create_session(kind, ref, attrs, opts)

Creates a password-authenticated session with options.

decrypt_alias(encrypted, alias_name, opts \\ [])

Decrypts ciphertext with the active KEK for alias_name.

Accepts one ciphertext or a list of ciphertexts. The :aad option must match the value used during encryption. Pass :session to enforce principal authorization.

decrypt_alias!(encrypted, alias_name, opts \\ [])

Bang variant of decrypt_alias/3.

Returns plaintext on success and raises on {:error, reason}.

decrypt_rmk_pdk(encrypted, secret, opts \\ [])

Decrypts data produced by encrypt_rmk_pdk/3 with the same high-entropy secret.

delete_binding(id)

Deletes a binding.

delete_fallback_public_key(id)

Deletes a fallback public key.

delete_principal(kind, ref)

Deletes a principal.

delete_principal_factor(id)

Deletes a principal factor.

delete_session(secret)

Deletes a session by bearer secret.

delete_sessions(kind, ref, opts \\ [])

Deletes all sessions for a principal.

encrypt_alias(cleartext, alias_name, opts \\ [])

Encrypts cleartext with the active KEK for alias_name.

Options:

  • :aad - additional authenticated data. Defaults to "".
  • :session - session secret for principal authorization.
  • :tags - optional KEK tags used when creating a missing alias.

Session-protected aliases also require a matching recipient envelope. Creating a missing alias with a principal session requires kek.create permission.

Returns {:ok, ciphertext} or {:error, reason}.

encrypt_alias!(cleartext, alias_name, opts \\ [])

Bang variant of encrypt_alias/3.

Returns ciphertext on success and raises on {:error, reason}.

encrypt_rmk_pdk(cleartext, secret, opts \\ [])

Encrypts cleartext with a caller-supplied high-entropy secret and RMK wrapping.

Use this for shared-passphrase workflows where KMS should not decrypt without the caller-supplied secret. Supports :aad.

fetch_active_session(secret)

Fetches an authenticated, non-expired session by bearer secret.

fetch_active_signing_key(version)

Fetches the active signing key with the requested version.

fetch_binding(id)

Fetches a binding by id.

fetch_fallback_public_key(id)

Fetches a fallback public key by id.

fetch_fallback_public_key_by_name(name)

Fetches a fallback public key by name.

fetch_principal(kind, ref, opts \\ [])

Fetches a principal by {kind, ref}.

fetch_principal_factor(id)

Fetches a principal factor by id.

fetch_session(secret)

Fetches a session by bearer secret.

finish_webauthn_authentication(challenge_id, response, opts \\ [])

Finishes WebAuthn/passkey authentication and returns a KMS session.

finish_webauthn_registration(challenge_id, response, opts \\ [])

Finishes WebAuthn/passkey registration with a browser response.

get_binding(id)

Returns a binding, nil when absent, or {:error, reason} when the backend fails.

get_principal(kind, ref)

Returns a principal, nil when absent, or {:error, reason} when the backend fails.

Prefer fetch_principal/3 when the caller needs a uniform tagged result.

get_principal_factor(id)

Returns a principal factor, nil when absent, or {:error, reason} when the backend fails.

get_session(secret)

Returns a session, nil when absent, or {:error, reason} when the backend fails.

install_signing_key(attrs)

Installs one active RMK-wrapped P-256 signing key.

install_signing_key_once(attrs)

Idempotently installs an exact RMK-wrapped P-256 signing key.

list_bindings(principal_id)

Lists bindings for a principal id.

list_fallback_public_keys()

Lists registered fallback public keys.

list_kek_aliases_by_tag(tag, opts \\ [])

Returns active KEK aliases containing tag.

list_kek_fallbacks(kek_id)

Lists fallback envelopes for a KEK.

list_kek_tags(alias_name, opts \\ [])

Returns tags attached to a KEK alias.

list_principal_factors(kind, ref)

Lists factors for a principal.

list_principal_fallbacks(principal_id)

Lists fallback envelopes for a principal.

list_principals(opts \\ [])

Lists principals visible to the caller.

list_sessions(kind, ref)

Lists sessions for a principal.

nudge_session(secret, opts \\ [])

Extends an active session idle expiry without rotating the bearer secret.

refresh_session(session, opts \\ [])

Refreshes a session and rotates the bearer secret.

remove_kek_tags(alias_name, tags, opts \\ [])

Removes tags from a KEK alias and returns the updated tag list.

revoke_alias_passphrase(alias_name, wrapping_id, opts \\ [])

Revokes one passphrase wrapping, including access through sessions already created from it.

rewrap_alias_for_passphrase(alias_name, passphrase, opts \\ [])

Wraps a session-protected alias for a high-entropy passphrase; returns its wrapping id.

rewrap_alias_for_principal(alias_name, target_kind, target_ref, opts \\ [])

Shares an alias with a target principal.

For session-protected aliases, seals a KEK copy to the target's public key and grants a decrypt binding. The caller needs an active session, kek.rewrap, and a usable recipient envelope. For existing RMK-only aliases, retains the legacy binding-only behavior; it does not add cryptographic user-secret protection.

rotate_fallback_public_key(public_key_ref, attrs, private_key, opts \\ [])

Rotates fallback public-key envelopes using the old private key.

This is a trusted local/break-glass operation. Do not route fallback private keys through ordinary HTTP clients or logs.

sign_digest(digest, version)

Signs one caller-supplied 32-byte SHA-256 digest with the active P-256 key.

signing_key_aad(version)

Returns the default AAD for an RMK-wrapped signing-key version.

signing_public_key_der(version)

Returns the DER-encoded public key for an active signing-key version.

unwrap_kek(kek_id, public_key_ref, private_key, opts \\ [])

Unwraps a KEK through a fallback private key from trusted local code.

unwrap_principal_private_key(principal_id, public_key_ref, private_key, opts \\ [])

Unwraps principal private-key material through a fallback private key.

update_binding(id, attrs)

Updates a binding.

update_principal(kind, ref, attrs, opts \\ [])

Updates a principal.

update_principal_factor(id, attrs)

Updates a principal factor.

validate_signing_key(version)

Loads and validates an active signing key, warming its private cache entry.

verify_digest(digest, signature, version)

Verifies a DER P-256 signature over one caller-supplied 32-byte SHA-256 digest.