mcl_core_lan_token (mcl_core v1.0.0)

View Source

The LAN entry point's token (docs/DESIGN.md §4.2, mcl-core#4).

A token names a member's node id and role, when it was issued and when it expires (15 minutes later). It is sealed with HMAC-SHA256 under the cluster-wide token key, which every node derives from the gossip secret with HKDF-SHA256 (RFC 5869, no salt, info mcl-lan token v1). Any node verifies a token any other node issued, and no new secret is handed out.

The holder of the gossip secret can forge tokens; that holder already owns the cluster through the cookie (design §2.1), so it adds no harm.

On the wire a token is base64url without padding over <<Version:8, NodeId:32/binary, Role:8, IssuedMs:64, ExpiresMs:64, Mac:32/binary>>, the times in system milliseconds. Pure: the caller passes the time and the key.

Summary

Functions

HKDF-SHA256 with no salt (a hash-long run of zeros, RFC 5869 §2.2), one output block: 32 bytes.

The cluster's token key, derived from its gossip secret.

How long a token lives.

A token for NodeId in Role, issued at NowMs.

The claims of a token sealed under Key and not expired at NowMs; anything else is refused, never raised on.

Types

claims/0

-type claims() :: #{node_id := <<_:256>>, role := role(), expires_at := integer()}.

role/0

-type role() :: owner | member.

Functions

hkdf_sha256(Ikm, Info)

-spec hkdf_sha256(binary(), binary()) -> <<_:256>>.

HKDF-SHA256 with no salt (a hash-long run of zeros, RFC 5869 §2.2), one output block: 32 bytes.

key(Secret)

-spec key(binary()) -> <<_:256>>.

The cluster's token key, derived from its gossip secret.

lifetime_ms()

-spec lifetime_ms() -> pos_integer().

How long a token lives.

mint(NodeId, Role, NowMs, Key)

-spec mint(<<_:256>>, role(), integer(), binary()) -> binary().

A token for NodeId in Role, issued at NowMs.

verify(Token, Key, NowMs)

-spec verify(term(), binary(), integer()) -> {ok, claims()} | {error, invalid | expired}.

The claims of a token sealed under Key and not expired at NowMs; anything else is refused, never raised on.