syntax = "proto3";
package cald.relay.v1;
import "Core.proto";
import "RelaySender.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 RelayReceiverService, 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 establishSession at
// https://example.com/cald/relay/establish-session. 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 receiver side of the Relay wire contract; the sender side is RelaySender.proto. Covers the
// recipient's abuse report that drives per-source-IP reputation and Tier 2's authenticated
// message retrieval: session establishment, polled delivery, and the consumption cursor.
//
// There is deliberately no "enrol" operation. How a relay decides which numbers it will accept
// and queue messages for is its own policy, not a standardized wire step.
//
// A signed structure is carried as its signed bytes and verified over those exact bytes, never a
// re-serialization -- protobuf serialization is not canonical.
message AbuseReport {
// Serialized AbuseReportBody -- the exact bytes `signature` was computed over. The relay
// parses it and never re-serializes.
bytes signedAbuseReportBody = 1;
// Over signedAbuseReportBody, with the reporter's current signing key, under signing context
// `cald/relay/abuse-report/v1` (Core.proto). The relay resolves the
// reporter's signing certificate from a Lookup Service and verifies against it; an unsigned or
// unverifiable report is discarded.
bytes signature = 2;
}
// The report payload, serialized into AbuseReport.signedAbuseReportBody and signed.
message AbuseReportBody {
cald.core.v1.PhoneNumber reporterPhoneNumber = 1;
int64 timestampEpochMillis = 2;
// The delivered message being reported. The relay resolves it to a source IP through its
// retained ingest record; a report for an expired record is a no-op.
string messageId = 3;
Verdict verdict = 4;
// The canonical URL of the report-abuse endpoint this is posted to: the relay's base URL +
// "/relay/report-abuse". A relay absorbs one naming any other endpoint, or none, like any other
// report it can't verify, so a report captured at one relay counts at no other. (Every signature
// is made under its payload kind's own signing context, Core.proto, so no other signed
// payload's bytes and signature are taken for a report whatever they decode as.)
string audience = 5;
enum Verdict {
MALFORMED = 0; // did not decrypt, parse, or verify
UNWANTED = 1; // well-formed but abusive
}
}
message AbuseReportResponse {
// RECORDED for every report a relay receives, whatever it did with it. Carries nothing about whether it
// matched a live attribution record or what effect it had -- an oracle-free acknowledgement.
Status status = 1;
enum Status {
// Never sent; a reader treats it, and a status it doesn't know, as the report not taken.
STATUS_UNSPECIFIED = 0;
RECORDED = 1;
}
}
// ---------------------------------------------------------------------------
// Tier 2: authenticated retrieval of queued messages -- session establishment, polled delivery,
// and the consumption cursor. Standardized-but-looser than Tier 1: a relay MAY offer this
// profile and MAY extend it, but need not implement it identically to every other relay.
// ---------------------------------------------------------------------------
// The exact parameter set a Tier-2 session-establishment signature covers,
// mirroring Lookup.proto's SignedLookupRead: the client builds this, serializes it once, and
// transmits the result verbatim as EstablishSessionRequest.signedSessionRequest alongside a signature
// over it. There is no reconstruction step on the verifying side.
message SignedSessionRequest {
cald.core.v1.PhoneNumber receiverPhoneNumber = 1;
// When this was signed. A relay refuses a request more than 5 minutes from its own clock, either way.
int64 timestampEpochMillis = 2;
// The canonical URL of the establish-session endpoint this is posted to: the relay's base URL +
// "/relay/establish-session". A relay refuses one naming any other endpoint, or none, so a request
// captured or induced for one relay opens no session at another.
// Field 4, not 3, on purpose: AbuseReportBody's field 3 is its sender-chosen string messageId and
// a MALFORMED report leaves field 4 out, so with audience at 3 a report of a message whose id is this URL
// would decode, under a verifying signature, as a session request.
string audience = 4;
}
message EstablishSessionRequest {
// Serialized SignedSessionRequest -- the exact bytes `signature` was computed over. The relay
// parses it and never re-serializes.
bytes signedSessionRequest = 1;
// Over signedSessionRequest, with SignedSessionRequest.receiverPhoneNumber's current signing key,
// under signing context `cald/relay/session-request/v1` (Core.proto).
bytes signature = 2;
}
message EstablishSessionResponse {
Status status = 1;
// Set only when status is ESTABLISHED.
string sessionToken = 2;
// Set only when status is ESTABLISHED. The client re-establishes (there is no separate renew
// call) once past this instant.
int64 expiresAtEpochMillis = 3;
enum Status {
// Never sent; a reader treats it, and a status it doesn't know, as a failure.
STATUS_UNSPECIFIED = 0;
ESTABLISHED = 1;
// A bad signature, an unresolvable receiver number, or a malformed request --
// deliberately not distinguished.
AUTHENTICATION_FAILED = 2;
// The requesting source is over this route's per-source limit; nothing was checked.
// Try again later.
RATE_LIMITED = 3;
}
}
message RetrieveMessagesRequest {
// From a prior EstablishSessionResponse.
string sessionToken = 1;
}
message RetrieveMessagesResponse {
Status status = 1;
// Set only when status is OK: every envelope currently queued for the session's receiver
// number. Retrieval does not itself remove these from the queue --
// AcknowledgeMessagesRequest does.
repeated RoutingEnvelope envelopes = 2;
enum Status {
// Never sent; a reader treats it, and a status it doesn't know, as a failure.
STATUS_UNSPECIFIED = 0;
OK = 1;
// Missing, expired, or unrecognized token -- not distinguished from each other.
SESSION_INVALID = 2;
// The requesting source is over this route's per-source limit; the token wasn't
// looked at. Try again later.
RATE_LIMITED = 3;
}
}
message AcknowledgeMessagesRequest {
// From a prior EstablishSessionResponse.
string sessionToken = 1;
// RoutingEnvelope.messageIds previously returned by RetrieveMessagesResponse for this
// session's receiver number. An id that is unknown, already released, or belongs to a
// different number is silently ignored -- acknowledgement is not an oracle
// either.
repeated string messageIds = 2;
}
message AcknowledgeMessagesResponse {
Status status = 1;
enum Status {
// Never sent; a reader treats it, and a status it doesn't know, as a failure.
STATUS_UNSPECIFIED = 0;
OK = 1;
// Missing, expired, or unrecognized token -- not distinguished from each other.
SESSION_INVALID = 2;
// The requesting source is over this route's per-source limit; the token wasn't
// looked at. Try again later.
RATE_LIMITED = 3;
}
}
// A receiver's stored form of one sender's certificate pair, not exchanged on the wire:
// kept by each client under its own storage, keyed on the number and the signing certificate's
// fingerprint, so a message signed under a certificate the sender has since replaced still verifies.
// Each time is epoch milliseconds, and 0 means it hasn't happened.
message StoredSenderCertificates {
bytes encodedSigningCertificate = 1;
bytes encodedEncryptionCertificate = 2;
// When a message first verified under this pair. 0 for a pair learned only from Lookup.
int64 firstVerifiedAtEpochMillis = 3;
// When Lookup last named this pair as the number's current one.
int64 confirmedCurrentAtEpochMillis = 4;
// When the receiver learned a newer pair had replaced this one.
int64 supersededAtEpochMillis = 5;
}
service RelayReceiverService {
// Recipient feedback that drives per-source-IP reputation. The reporter is authenticated by
// resolving its signing certificate from a Lookup Service -- there is no relay-side enrolment.
rpc reportAbuse(AbuseReport) returns (AbuseReportResponse);
// Tier 2: prove possession of a receiver number's signing key and obtain a bearer session
// token.
rpc establishSession(EstablishSessionRequest) returns (EstablishSessionResponse);
// Tier 2: an ordinary polled call, not a stream -- deliver everything currently queued for the
// authenticated session's receiver number.
rpc retrieveMessages(RetrieveMessagesRequest) returns (RetrieveMessagesResponse);
// Tier 2: the consumption cursor -- acknowledge messageIds so the relay may release them.
rpc acknowledgeMessages(AcknowledgeMessagesRequest) returns (AcknowledgeMessagesResponse);
}