SessionAP
SessionAP: who may form a session at an access point (distributed-deploys build step 11b, the authorization half of node certificates).
A node certificate (NodeCert) names the protocol roles its node may play, as "Proto.Role:offer" (it may OFFER the role at an access point) and "Proto.Role:initiate" (it may INITIATE a session in the role). When a session forms at access points both sides check (plan section 3, "Two-way checks when a session forms"):
- the offer checks that the INITIATOR's certificate names
"Proto.Role:initiate" for the role it plays (SessionNode.offer_verdict);
* the initiator checks that each OFFERING node's certificate names
"Proto.Role:offer" for the role it offers, before inviting it
(SessionNode.candidates). Offers are registered under names any member
can write, so the check is on the certificate of the node that holds
the offer, never on the registry entry.Everything here is pure: the certificate is the one ClusterNode verified in its handshake (ClusterNode.peer_cert). Checks apply in CERTIFICATE mode only; a shared-secret node has no certificates and checks nothing (specs/lang/clustering.md, "Authorization").
Functions
May the node that presented [cert] play role [role] of protocol [proto] in [mode] (offer_mode() or initiate_mode())? Ok(()), or Err(why): "presented no certificate" when the peer presented none (a certificate-mode node never links to such a peer, so this is a peer this node has not verified), else "not authorized for Proto.Role". A caller in shared-secret mode does not call this at all. The check is an exact match of permission(proto, role, mode) against the certificate's role list (NodeCert.has_role).
Examples
march> SessionAP.authorize(None, "Chat", "Client", SessionAP.offer_mode())
Err("presented no certificate")The mode an initiating node's certificate must name for a role: "initiate".
Examples
march> SessionAP.initiate_mode()
"initiate"The mode an offering node's certificate must name for a role: "offer".
Examples
march> SessionAP.offer_mode()
"offer"The permission a certificate must carry: "Proto.Role:mode".
Examples
march> SessionAP.permission("Chat", "Client", SessionAP.initiate_mode())
"Chat.Client:initiate"A role's certificate name: "Proto.Role" for protocol [proto] and role name [role] (the names forge cluster cert --roles takes, before :mode). The parts are joined as given, with no validation.
Examples
march> SessionAP.role_label("Chat", "Client")
"Chat.Client"The name of role number [i] in [roles] (a protocol's <P>_Msg.role_names()), or its number as text when the table does not have it (a peer built from a protocol with other role numbers: its fingerprint differs, so the session is refused for that first). The first entry with number [i] wins.
Examples
march> SessionAP.role_name([("Client", 1), ("Server", 2)], 2)
"Server"
march> SessionAP.role_name([("Client", 1), ("Server", 2)], 9)
"9"