Karta. SASL. SCRAM
(Karta v1.0.0)
SCRAM-SHA-256 (RFC 5802, RFC 7677): the server side of the exchange, without channel binding, and the derivation of the keys a server stores.
Stored keys. A password is never stored. derive/3 turns it, a
random salt and an iteration count into StoredKey (the hash of the
client key) and ServerKey; the server keeps those three and the count.
A password given in clear (SMTP AUTH PLAIN or LOGIN) is checked the same
way: check_password/2 derives StoredKey with the stored salt and
compares in constant time. So one stored form serves every mechanism.
The exchange:
client_first/1parses the client's first message (n,,n=user,r=<client nonce>);server_first/4answers with the combined nonce, the salt and the iteration count;client_final/3checks the client's proof againstStoredKeyand returns the server's final message,v=<server signature>, with which the client in turn authenticates the server.
Channel binding (SCRAM-SHA-256-PLUS) is not offered: a client that
asks for it (p=) is refused; y (the client could, but the server did
not offer it) is accepted. An authorisation identity is accepted only
when it equals the user name. Passwords and user names are used as
given, without SASLprep (RFC 4013); for printable ASCII, which is what
Karta generates, SASLprep changes nothing.
Summary
Functions
Checks a password in clear against stored keys (salt, iterations, stored_key).
Checks the client's final message against the stored keys. Returns the server's final message on success.
Parses the client's first message.
StoredKey and ServerKey for a password (RFC 5802 §3).
A server nonce: 18 random bytes in base64 (printable, no commas).
The server's first message for a parsed client first message, and the
state for client_final/3.
Types
@type reason() ::
:invalid | :channel_binding | :extension | :authzid | :nonce | :proof
Functions
@spec check_password(binary(), %{ salt: binary(), iterations: pos_integer(), stored_key: binary() }) :: boolean()
Checks a password in clear against stored keys (salt, iterations, stored_key).
Checks the client's final message against the stored keys. Returns the server's final message on success.
@spec client_first(binary()) :: {:ok, client_first()} | {:error, reason()}
Parses the client's first message.
@spec derive(binary(), binary(), pos_integer()) :: keys()
StoredKey and ServerKey for a password (RFC 5802 §3).
@spec nonce() :: binary()
A server nonce: 18 random bytes in base64 (printable, no commas).
@spec server_first(client_first(), binary(), binary(), pos_integer()) :: {binary(), state()}
The server's first message for a parsed client first message, and the
state for client_final/3.