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 RelayWakeUpService, 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 registerWakeUp at https://example.com/cald/relay/register-wake-up.
// 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.
// Push wake-ups: a receiver tells its relay how its device can be woken when a message
// is queued for it, so an idle phone learns about one in seconds instead of at its next poll.
//
// Channel-neutral by design: the client DECLARES its wake-up channel (FCM, later APNs or
// UnifiedPush) and the relay never infers one from the connection. A relay that doesn't support the
// declared channel answers UNSUPPORTED_CHANNEL and the client keeps polling (Tier-2 retrieval,
// RelayReceiver.proto), so every client works with every relay, woken or not.
//
// A wake-up itself carries nothing but "you have mail": the push service learns only that something
// arrived for a device. The device then retrieves through Tier 2 as usual.
//
// A signed structure is carried as its signed bytes and verified over those exact bytes, never a
// re-serialization -- protobuf serialization is not canonical.
// How a device can be woken. The relay treats `address` as opaque and hands it to the channel.
enum WakeUpChannelType {
// Unset: never a supported channel, so a request that omits the type is UNSUPPORTED_CHANNEL
// rather than silently read as FCM.
WAKE_UP_CHANNEL_UNSPECIFIED = 0;
// Firebase Cloud Messaging; `address` is the device's FCM registration token.
FCM = 1;
// Reserved for later: an APNs device token.
APNS = 2;
// Reserved for later: a UnifiedPush endpoint URL.
UNIFIED_PUSH = 3;
}
message WakeUpAddress {
WakeUpChannelType channelType = 1;
string address = 2;
}
// The exact content a wake-up registration's signature covers, serialized once by the client and
// transmitted verbatim as RegisterWakeUpRequest.signedWakeUpRegistration (mirrors
// SignedSessionRequest). Registering again replaces the number's earlier address: a number has one
// current key pair, so one device, and a device that changes channel or token re-registers.
message SignedWakeUpRegistration {
cald.core.v1.PhoneNumber phoneNumber = 1;
WakeUpAddress wakeUpAddress = 2;
// When the client signed this. The relay refuses a registration far from its own clock, and
// never lets an older registration replace a newer one signed with the same certificate.
int64 timestampEpochMillis = 3;
// The canonical URL of the register-wake-up endpoint this is posted to: the relay's base URL +
// "/relay/register-wake-up". A relay refuses one naming any other
// endpoint, or none, so a registration captured at one relay serving the number registers nothing at another.
string audience = 4;
}
// The relay's stored form of an accepted registration, not exchanged on the wire: the verified
// registration plus the hash (SHA-256) of the signing certificate it was verified under, so a newer
// registration under the same certificate is told from a replayed older one, a registration from a
// new certificate (a new device) always replaces the old, and a registration whose certificate is
// no longer the number's current one can be recognized as stale.
message StoredWakeUpRegistration {
SignedWakeUpRegistration registration = 1;
cald.core.v1.Hash signingCertificateFingerprint = 2;
}
message RegisterWakeUpRequest {
// Serialized SignedWakeUpRegistration -- the exact bytes `signature` was computed over. The
// relay parses it and never re-serializes.
bytes signedWakeUpRegistration = 1;
// Over signedWakeUpRegistration, with SignedWakeUpRegistration.phoneNumber's current signing key,
// under signing context `cald/relay/wake-up-registration/v1` (Core.proto).
bytes signature = 2;
}
message RegisterWakeUpResponse {
Status status = 1;
enum Status {
// Never sent: an empty or missing status must not read as success.
STATUS_UNSPECIFIED = 0;
REGISTERED = 1;
// A bad signature, an unresolvable number, a timestamp too far from the relay's clock, or a
// malformed request -- deliberately not distinguished (as establishSession does for
// sessions). Also the answer when the requesting source is over the route's per-source
// limit, nothing having been checked.
AUTHENTICATION_FAILED = 2;
// Authenticated, but this relay can't wake a device through the declared channel (or the
// channel is unset or unknown to it). Nothing is stored; the client keeps polling.
UNSUPPORTED_CHANNEL = 3;
}
}
service RelayWakeUpService {
// Register (or replace) how the signer's device is woken when a message is queued for it.
rpc registerWakeUp(RegisterWakeUpRequest) returns (RegisterWakeUpResponse);
}