March Docs

NodeCert

NodeCert: a cluster node's certificate (distributed-deploys build step 11a).

A certificate names one node, the protocol roles it may play and the raw primitives it may use, and is signed (ed25519) by the cluster's OPERATOR key. Nodes present certificates in the cert-mode handshake (NetKernel.handshake_auth); each side verifies the other's against the operator public key and the clock, then proves it holds the key the certificate names. See specs/lang/clustering.md, "Node certificates".

Names are SPIFFE-style URIs, so a service mesh can carry the same identities later (SPIFFE itself is not implemented): node spiffe://<trust-domain>/pool/<pool>/node/<name> issuer spiffe://<trust-domain>/operator/<first 16 hex digits of the operator key>

Roles are "Proto.Role:offer" / "Proto.Role:initiate"; the one flag so far is "raw_send". Step 11b checks them: roles at session formation (SessionAP.authorize, from SessionNode's access points and direct runner), raw_send on every raw send and registry lookup (ClusterNode, NodeSend, NodeCall). See specs/lang/clustering.md, "Authorization".

Wire form. The body is the canonical MessagePack array ["march-node-cert-v1", node, [role...], [flag...], not_after, issuer, pubkey_hex, serial] (Msgpack.encode's smallest-form encoding; forge's cluster cert writes the same bytes), and a signed certificate is [Bin(body), Bin(signature)]; its text form (MARCH_NODE_CERT, forge cluster cert's .cert file) is that, base64. The signature covers the body bytes exactly as sent, so verification never re-encodes. not_after is unix SECONDS, inclusive.

A revocation is signed by the same operator key: body ["march-revocation-v1", node, serial, issued_at] revoking one certificate (serial != "") or every certificate of a node (serial == ""). Revocations are gossiped between nodes (ClusterNode).

Types

typeCertCert = { node : String, roles : List(String), flags : List(String), not_after : Int,#
typeSignedSigned = { cert : Cert, body : List(Int), signature : Bytes }#

A certificate as received: the decoded fields, the exact body bytes the signature covers, and the signature.

typeRevocationRevocation = { node : String, serial : String, issued_at : Int }#
typeSignedRevocationSignedRevocation = { rev : Revocation, body : List(Int), signature : Bytes }#
typeCredentialsCredentials = { signed : Signed, secret_key : Bytes, operator_pubkey : Bytes,#

What a node needs to take part in a cert-mode handshake: its own signed certificate, the ed25519 secret key the certificate names (64 bytes: seed || public key), the operator public key every peer's certificate must verify under, and a predicate for revoked certificates (the node's live revocation list).

Functions

fncert_versioncert_version() : String do "march-node-cert-v1" end#

The version string a certificate body starts with: \

fndecodedecode(bytes : List(Int)) : Result(Cert, String)#

Decode a canonical body (the inverse of encode). Err (prefixed "NodeCert: ") for bytes that are not MessagePack, a body of the wrong shape, a version other than cert_version(), or roles / flags that are not all strings. Checks no signature.

fndecode_revocationdecode_revocation(bytes : List(Int)) : Result(Revocation, String)#

Decode a revocation body (the inverse of encode_revocation). Err (prefixed "NodeCert: ") for bytes that are not MessagePack, the wrong shape, or a version other than revocation_version().

fnencodeencode(c : Cert) : List(Int)#

The canonical MessagePack body of [c] (what the operator signs): the array [cert_version(), node, roles, flags, not_after, issuer, pubkey, serial] in Msgpack's smallest-form encoding, so one certificate always encodes to the same bytes.

fnencode_revocationencode_revocation(r : Revocation) : List(Int)#

The canonical MessagePack body of a revocation (what the operator signs): [revocation_version(), node, serial, issued_at].

fnexpiredexpired(c : Cert, now : Int) : Bool do now > c.not_after end#

Has [c] expired at [now] (unix seconds)? not_after is inclusive: a certificate is still valid during its last second.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.expired(c, 2000000000)
false
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.expired(c, 2000000001)
true
fnfrom_bytesfrom_bytes(bytes : List(Int)) : Result(Signed, String)#

Parse the wire bytes of to_bytes (does NOT verify: see verify). Err (prefixed "NodeCert: ") for bytes that are not a two-element [Bin(body), Bin(signature)] array, or a body decode refuses.

fnfrom_textfrom_text(t : String) : Result(Signed, String)#

Parse the text form of to_text (surrounding whitespace trimmed; does NOT verify). Err for bad base64 or what from_bytes refuses.

fnhas_flaghas_flag(c : Cert, flag : String) : Bool do List.member(c.flags, flag) end#

Does [c] carry [flag] (e.g. "raw_send")? An exact string match against c.flags.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.has_flag(c, "raw_send")
true
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.has_flag(c, "debug")
false
fnhas_rolehas_role(c : Cert, role : String) : Bool do List.member(c.roles, role) end#

Does [c] let its node play role [role] ("Proto.Role:offer" or "Proto.Role:initiate")? An exact string match against c.roles.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.has_role(c, "Chat.Server:offer")
true
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.has_role(c, "Chat.Server:initiate")
false
fnis_revokedis_revoked(c : Cert, rs : List(Revocation)) : Bool#

Is [c] revoked by any of [rs] (revokes)? False for an empty list.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.is_revoked(c, [{ node: "other", serial: "1000-ab", issued_at: 5 }])
true
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.is_revoked(c, [])
false
fnissued_msissued_ms(c : Cert) : Option(Int)#

When [c] was issued (unix ms), if its serial says (ordered_serial): the text before the serial's first "-", when it is 1 to 18 decimal digits and a "-" follows. None for a serial with no order.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.issued_ms(c)
Some(1000)
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.issued_ms({ c with serial: "f00d" })
None
fnissuer_uriissuer_uri(trust_domain : String, operator_pub_hex : String) : String#

The issuer URI for an operator public key given as hex ([operator_pub_hex]): the trust domain and the key's first 16 hex digits.

Examples

march> NodeCert.issuer_uri("example.org", "0123456789abcdef0123")
"spiffe://example.org/operator/0123456789abcdef"
fnkey_from_hexkey_from_hex(s : String, len : Int) : Result(Bytes, String)#

A key (or signature) from its hex text (surrounding whitespace trimmed), checking it is exactly [len] bytes. Err names the problem: text that is not hex, or the wrong length.

Examples

march> Result.map(NodeCert.key_from_hex(" 0a0b ", 2), Bytes.to_list)
Ok([10, 11])
march> NodeCert.key_from_hex("0a0b", 32)
Err("expected 32 bytes, got 2")
fnkeypairkeypair() : Bytes do ed25519_seed_keypair(Crypto.random_bytes(32)) end#

A fresh, random ed25519 secret key (64 bytes: seed || public key), from a 32-byte random seed.

fnkeypair_from_seedkeypair_from_seed(seed : Bytes) : Bytes do ed25519_seed_keypair(seed) end#

The 64-byte ed25519 secret key (seed || public key) a 32-byte [seed] determines (RFC 8032): the same seed always gives the same key. Returns empty Bytes when [seed] is not exactly 32 bytes.

Examples

march> Bytes.length(NodeCert.keypair_from_seed(Bytes.from_list([1, 2])))
0
fnnode_namenode_name(uri : String) : String#

The node name a certificate's URI ends in (the segment after the last "/node/"), or "" when the URI has no node segment. The handshake requires it to equal the name the peer announces.

Examples

march> NodeCert.node_name("spiffe://example.org/pool/web/node/n1")
"n1"
march> NodeCert.node_name("spiffe://example.org/operator/0123")
""
fnnode_urinode_uri(trust_domain : String, pool : String, name : String) : String#

The SPIFFE-style URI of node [name] in [pool] under [trust_domain]. No part is validated or escaped.

Examples

march> NodeCert.node_uri("example.org", "web", "n1")
"spiffe://example.org/pool/web/node/n1"
fnorder_problemorder_problem(next : Cert, held : Cert) : Option(String)#

Why [next] may not replace [held] (supersedes), if it may not: None when it may, else a message naming both serials.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.order_problem({ c with serial: "999-cd" }, c)
Some("certificate 999-cd was issued before 1000-ab, the certificate in use")
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.order_problem({ c with serial: "2000-cd" }, c)
None
fnordered_serialordered_serial(issued_ms : Int, rest : String) : String do int_to_string(issued_ms) ++ "-" ++ rest end#

A serial carrying issue time [issued_ms] (unix ms): "<issued_ms>-<rest>".

Examples

march> NodeCert.ordered_serial(1000, "ab")
"1000-ab"
fnpublic_keypublic_key(sk : Bytes) : Bytes do Bytes.slice(sk, 32, 32) end#

The 32-byte public key inside a 64-byte secret key [sk] (its last 32 bytes).

Examples

march> Bytes.length(NodeCert.public_key(Bytes.from_list(List.range(0, 64))))
32
march> List.take(Bytes.to_list(NodeCert.public_key(Bytes.from_list(List.range(0, 64)))), 3)
[32, 33, 34]
fnrevocation_from_bytesrevocation_from_bytes(bytes : List(Int)) : Result(SignedRevocation, String)#

Parse the wire bytes of revocation_to_bytes (does NOT verify: see verify_revocation). Err for a malformed array or a body decode_revocation refuses.

fnrevocation_from_textrevocation_from_text(t : String) : Result(SignedRevocation, String)#

Parse the text form of revocation_to_text (surrounding whitespace trimmed; does NOT verify). Err for bad base64 or what revocation_from_bytes refuses.

fnrevocation_idrevocation_id(r : Revocation) : String#

A short identity for a revocation: the first 16 hex digits of the sha256 of its canonical body. Two copies of one revocation (from a release, from a peer's gossip, from MARCH_CLUSTER_REVOCATIONS) have the same id, so a node's report of the revocations it knows can be matched against a release's (Control, step 12b).

fnrevocation_to_bytesrevocation_to_bytes(s : SignedRevocation) : List(Int)#

A signed revocation's wire bytes: [Bin(body), Bin(signature)], as to_bytes is for a certificate.

fnrevocation_to_textrevocation_to_text(s : SignedRevocation) : String#

The text form of a signed revocation (base64): what forge cluster revoke prints.

fnrevocation_versionrevocation_version() : String do "march-revocation-v1" end#

The version string a revocation body starts with: \

fnrevokesrevokes(r : Revocation, c : Cert) : Bool#

Does [r] revoke [c]? A revocation with a serial revokes the certificate with that serial (whatever its node); one with serial "" revokes every certificate whose node equals r.node.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.revokes({ node: "spiffe://example.org/pool/web/node/n1", serial: "", issued_at: 5 }, c)
true
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.revokes({ node: "spiffe://example.org/pool/web/node/n1", serial: "999-cd", issued_at: 5 }, c)
false
fnsignsign(c : Cert, operator_sk : Bytes) : Signed#

Sign [c] with the operator secret key [operator_sk] (64 bytes, as from keypair): the ed25519 signature over encode(c), kept with the body bytes it covers.

fnsign_revocationsign_revocation(r : Revocation, operator_sk : Bytes) : SignedRevocation#

Sign [r] with the operator secret key [operator_sk]: the ed25519 signature over encode_revocation(r), kept with the body it covers.

fnsupersedessupersedes(next : Cert, held : Cert) : Bool#

May [next] replace [held], by issue order? Refused when [held] carries an issue time and [next] was issued before it, or carries none (a certificate from before ordered serials cannot replace one after). When [held] has no issue time there is no order to keep and the answer is yes (the release floor guards that case, Control). The same certificate again is yes.

Examples

march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.supersedes({ c with serial: "999-cd" }, c)
false
march> let c = { node: "spiffe://example.org/pool/web/node/n1", roles: ["Chat.Server:offer"], flags: ["raw_send"], not_after: 2000000000, issuer: "spiffe://example.org/operator/00", pubkey: "", serial: "1000-ab" }
march> NodeCert.supersedes(c, { c with serial: "f00d" })
true
fnto_bytesto_bytes(s : Signed) : List(Int)#

The signed certificate's wire bytes: [Bin(body), Bin(signature)].

fnto_textto_text(s : Signed) : String do Bytes.encode_base64(Bytes.from_list(to_bytes(s))) end#

The text form (base64 of to_bytes): MARCH_NODE_CERT and forge's .cert files.

fnverifyverify(s : Signed, operator_pubkey : Bytes, now : Int) : Result(Cert, String)#

Verify a signed certificate against [operator_pubkey] (32 bytes) at [now] (unix seconds), in this order: the signature must cover the body, [now] must not be past not_after (not_after itself is still valid), and the certificate's pubkey must be the hex of a 32-byte key. Returns the certificate, or why it is refused. Revocation is the caller's (see is_revoked).

fnverify_revocationverify_revocation(s : SignedRevocation, operator_pubkey : Bytes) : Result(Revocation, String)#

Verify a signed revocation against [operator_pubkey]: Ok with the revocation when the operator signed its body, else Err (so a member node cannot revoke another).