syntax = "proto3"; package cald.relay.v1; import "Core.proto"; // If false, all generated code goes in a single java file option java_multiple_files = true; option java_package = "nexus.cald.api.relay"; // Calling this service: each rpc in RelaySenderService, at the end of this file, is an HTTP POST to // //. is the name between "cald." and ".v1" in this file's package // (cald.relay.v1, so "relay"), and is the rpc's name in kebab-case: a relay at // https://example.com/cald takes submitMessage at https://example.com/cald/relay/submit-message. // The body is the request message in protobuf's standard JSON encoding (Content-Type: // application/json), and a 200 answer's body is the response message, encoded the same way. Every // outcome the service decides, refusals included, is a 200 whose status field says which; any other // HTTP status means the call didn't go through. A server that doesn't offer an rpc has no route for // it. // The sender side of the Relay wire contract: an anonymous submission to the recipient's relay, // plus the end-to-end message the sender builds, encrypts, and puts in the envelope. The receiver // side is RelayReceiver.proto. The submission-agent flow is // the one non-anonymous addition -- a sender hands its own relay an already-built SignedMessage // plus a destination, and that relay encrypts and forwards it on the sender's behalf. // // A signed structure is always carried as its signed bytes and verified over those exact bytes, // never a re-serialization -- protobuf serialization is not canonical. // --------------------------------------------------------------------------- // Tier 1: anonymous submission (what the relay sees) // --------------------------------------------------------------------------- message RoutingEnvelope { cald.core.v1.PhoneNumber recipientPhoneNumber = 1; // Ciphertext sealed to the recipient number's current encryption certificate. // Decrypts to a SignedMessage. Opaque to the relay -- it holds no key and does no inspection. bytes encryptedMessage = 2; // Sender-generated, unique per recipient: de-duplication and the handle an abuse report // references. An opaque token -- carries nothing about the sender. string messageId = 3; // The hash of the full DER of the recipient encryption certificate the payload was sealed to // (SHA-256 today), so a recipient holding more than one unexpired encryption certificate during a // rollover picks the right private key (RELAY-R018). A hash naming no algorithm is malformed; one in // an algorithm the reader can't compute names no certificate it holds. cald.core.v1.Hash recipientKeyFingerprint = 4; // Requested queue lifetime in seconds. 0 means the relay's default; above the relay's maximum // is clamped. int64 timeToLiveSeconds = 5; } message SubmitMessageRequest { RoutingEnvelope envelope = 1; } message SubmitMessageResponse { // Deliberately specific (unlike the CA's indistinguishable completion failures): no secret to // guess, and the sender needs to know whether to retry, re-resolve the recipient's certificate, // or stop. Status status = 1; enum Status { STATUS_UNSPECIFIED = 0; // never sent; a reader treats it as not accepted ACCEPTED = 1; // the envelope is now queued for the recipient RECIPIENT_NOT_ACCEPTED = 2; // the relay's acceptance policy declined this number ENVELOPE_TOO_LARGE = 3; // over the relay's envelope size limit DUPLICATE_MESSAGE_ID = 4; // this same envelope (messageId and ciphertext) is already queued // The source is over its limit or blocked, or the recipient's queue is full. RATE_LIMITED = 5; MALFORMED_ENVELOPE = 6; // a required field is missing or empty } } // --------------------------------------------------------------------------- // End-to-end payload (recipient-only) // // The decrypted content of RoutingEnvelope.encryptedMessage. Part of the cald-api contract // because it is exchanged between sender and recipient, but the relay is never a party to it: it // does not parse, validate, or construct any message in this section. A receiver's client imports // this file to parse what it decrypts. // --------------------------------------------------------------------------- message SignedMessage { // One or more. A version-1 sender sets exactly one CaLD signature; repeated from the outset so // an additional co-signature -- e.g. a web-PKI certificate carrying organisation identity -- // slots in with no wire break. repeated Signature signatures = 1; // Serialized CaldMessage -- the exact bytes every signature covers, behind its signing context. The // recipient verifies against these bytes and parses CaldMessage from them; it never // re-serializes. recipientPhoneNumber and sentAtEpochMillis live inside CaldMessage, so the // signature covers them; the recipient checks the envelope's recipientPhoneNumber matches and // de-duplicates on SHA-256 of these bytes. bytes signedCaldMessage = 2; } message Signature { // Who signed: a phone number's certificate, or, unsigned, a web origin. // Exactly one, and never both: a reader that meets neither refuses the signature. oneof signer { // A hint for which certificate to resolve, not a signed claim -- it sits outside the signed // bytes. Security rests on the signature verifying under a certificate the recipient trusts // for this number. cald.core.v1.PhoneNumber signerPhoneNumber = 1; // A web origin, unverified: nothing is signed, so this is only a hint at who sent it. // With this signer `signature`, `signingCertificateFingerprint` and `signerCertificates` are // all unset -- a web origin has no key here and no certificate -- and a reader drops the // message if any is set. Such a message is accepted only as a sign-in pointer // (SignIn.proto's SignInPointer) to a URL on this same origin; every sign-in fact comes from // the document the reader then fetches from that URL over TLS. It is never reported as // forged. WebOriginSigner webOrigin = 6; } // The hash of the full DER of the signing certificate used (SHA-256 today; a reader computes with // the algorithm the hash names, and one it can't compute names no certificate). Always set for a // phone-number signer, never for a web origin: the compact identifier the recipient uses to hit // its cache or ask a Lookup Service. cald.core.v1.Hash signingCertificateFingerprint = 2; // Over the enclosing SignedMessage's signedCaldMessage, under signing context `cald/message/v1` // (Core.proto), for messages and call messages alike. No algorithm field: the signature scheme // is derived from the resolved signing certificate's algorithm family, the same way the CA // derives family from a submitted key. Empty for a web-origin signer. bytes signature = 3; // Optional. The signer's whole current pair -- signing and encryption // certificates, DER -- so the recipient can verify this message, and seal its reply, without a // Lookup read. `rootCACertificate` is ignored if set: the anchor is always the recipient's own // pinned root. `intermediateCACertificates` is never sent, and ignored if set: intermediates come // from the recipient's own list. When carried, `signingCertificateFingerprint` must // be the hash of its signing certificate, and both certificates must be present. Never set for a // web-origin signer. cald.core.v1.CertificateBundle signerCertificates = 5; } // A web origin as a message's sender: the origin in canonical form (scheme and host lower-cased, // no default port, no path). // Unverified: anyone can name any origin here. A reader uses it only to require that a sign-in // pointer's URL is on this same origin, and takes every sign-in fact from the document fetched // from that URL over TLS. message WebOriginSigner { string origin = 1; } // The signed unit. The intended recipient, a send time, and one or more pieces of typed content. // Every message type the system carries -- first-party or third-party -- is a MessageContent, so // this message never changes to add a type. message CaldMessage { // The intended recipient, inside the signed bytes so the signature is bound to it: a recipient // cannot re-encrypt and re-address this signed message as though the sender sent it to someone // else. Same value as RoutingEnvelope.recipientPhoneNumber -- no difference; the // envelope carries a cleartext copy only because the relay routes without decrypting. The // recipient rejects a mismatch. cald.core.v1.PhoneNumber recipientPhoneNumber = 1; int64 sentAtEpochMillis = 2; // One or more. The whole CaldMessage is signed as a unit, so a bundle (e.g. a message plus an // attachment descriptor) is atomic. The recipient de-duplicates end to end on SHA-256 of the // signed bytes, handles the contents it understands, and ignores or reports the rest. // Ordering, where a content type needs it, is that schema's own concern. repeated MessageContent contents = 3; } // A typed, self-describing piece of content. The relay never sees this; CaLD interprets it only // when schemaName is a CaLD schema. message MessageContent { // The authority that defines this content's format -- a CaLD builtin, a CaLD-blessed // extension, an open standard, or a closed third party -- and, with it, the codec for // messageBytes. The concrete vocabulary (reserved prefixes, reverse-DNS for third parties, // how open standards are named) is NOT specified yet; only this shape is fixed. // CaLD mandates a protobuf encoding for messageBytes only when schemaName is one of its own // schemas. string schemaName = 1; // Version within schemaName's own versioning scheme (semver, a date, "draft-03", ...), hence a // string, not an int. string schemaVersion = 2; // Which message within (schemaName, schemaVersion). string messageTypeName = 3; // The serialized content, in the format schemaName implies. Opaque to CaLD unless schemaName // is a CaLD schema. bytes messageBytes = 4; } // --------------------------------------------------------------------------- // Submission agent -- a sender authenticating to its OWN relay, opt-in // alternative to building and encrypting the RoutingEnvelope itself. Unlike everything above, // this is NOT anonymous and NOT part of the standardized Tier-1 interoperability surface -- // relays are not required to offer it. // --------------------------------------------------------------------------- message SubmitViaAgentRequest { // The sender's own signed-but-unencrypted payload, built exactly the way it would be for the // direct path (the relay verifies Signature.signature over signedCaldMessage as transmitted, // never a re-serialization). This signature IS the sender's authentication to its own relay -- // proof it currently holds a registered signing certificate -- no separate signed envelope. SignedMessage message = 1; // Where to deliver. MUST equal the signed CaldMessage's own recipientPhoneNumber -- the relay // rejects a mismatch rather than trusting this field alone. cald.core.v1.PhoneNumber destinationPhoneNumber = 2; // As RoutingEnvelope.timeToLiveSeconds: 0 means the destination relay's default; clamping is // the destination's own concern, not this relay's. int64 timeToLiveSeconds = 3; } // SubmitViaAgentResponse.downstreamRejectionReason: SubmitMessageResponse.Status's refusals, by the // same names, and nothing else, so it can't say ACCEPTED. In a message of its own because proto enum // values share their enclosing scope: nested beside SubmitViaAgentResponse.Status these names would // collide, and top-level they would claim RATE_LIMITED and the rest for the whole package. message DownstreamRejection { enum Reason { REASON_UNSPECIFIED = 0; // never sent beside DESTINATION_REJECTED; read as DESTINATION_UNREACHABLE RECIPIENT_NOT_ACCEPTED = 1; ENVELOPE_TOO_LARGE = 2; DUPLICATE_MESSAGE_ID = 3; RATE_LIMITED = 4; MALFORMED_ENVELOPE = 5; } } message SubmitViaAgentResponse { Status status = 1; // Set iff status == DESTINATION_REJECTED: the destination relay's own refusal, passed through so // the sender knows whether to retry, re-resolve, or stop -- the same "no secret to guess" // reasoning as SubmitMessageResponse.Status. Its own enum, holding only refusals, so it can't // say ACCEPTED. DownstreamRejection.Reason downstreamRejectionReason = 2; enum Status { STATUS_UNSPECIFIED = 0; // never sent; a reader treats it as not accepted ACCEPTED = 1; // the destination relay queued the forwarded envelope UNVERIFIABLE_SENDER = 2; // bad/missing signature, or signerPhoneNumber has no current signing cert MALFORMED_REQUEST = 3; // missing fields, or signedCaldMessage doesn't decode RECIPIENT_MISMATCH = 4; // CaldMessage.recipientPhoneNumber != destinationPhoneNumber UNRESOLVABLE_DESTINATION = 5; // destination has no current pair, or no usable relay-address extension RATE_LIMITED = 6; // this relay's own submission controls DESTINATION_REJECTED = 7; // the downstream Tier-1 submitMessage was declined // The downstream call itself failed, or its answer named no status this relay knows. DESTINATION_UNREACHABLE = 8; // The signature's fingerprint doesn't name the signer's current signing certificate, or it carries a // pair other than the signer's current pair: receivers would judge the message forged // and report it. SIGNER_CERTIFICATE_MISMATCH = 9; } } // --------------------------------------------------------------------------- // Service // --------------------------------------------------------------------------- // Tier 1 -- the interoperability surface every relay implements identically. // HTTP POST carriage of submitMessage is mandatory at every relay; this gRPC service is the // optional same-shape alternative. service RelaySenderService { // Anonymous: no credentials, no session, no prior relationship. rpc submitMessage(SubmitMessageRequest) returns (SubmitMessageResponse); // Authenticated submission-agent flow. Optional: a relay need not // offer this even if it implements submitMessage. rpc submitViaAgent(SubmitViaAgentRequest) returns (SubmitViaAgentResponse); }