REPL auto-setup (zero-friction startup): - OnceLock → RwLock for CLIENT_AUTH to allow delayed init after OPAQUE login - Extract opaque_register/opaque_login helpers from one-shot commands - Token cache (.session file) with QPCE encryption when password provided - Add --username/--password/--state-password to repl subcommand - resolve_access_token: auto-register + login, cache token, prompt interactively - rpassword for secure password input (no echo) Interactive REPL (multi-conversation): - SessionState: identity, hybrid key, ConversationStore, per-conversation GroupMembers - ConversationStore: SQLite-backed conversations + messages with full CRUD - Slash commands: /dm, /group, /invite, /join, /switch, /list, /members, /history, /whoami - Background polling (1s interval) with auto-join from MLS Welcome messages - pending_member pattern: persistent keystore for HPKE init key, replenish after join - Self-DM handled as local-only notepad (no MLS/server channel) - ANSI display module for colored prompts, incoming messages, status/error output Username resolution: - resolveIdentity RPC (@20 in node.capnp): look up username by identity key - Server: resolve_identity_key in Store trait, FileBackedStore, SqlStore - Client: resolve_identity in rpc.rs, used in auto-join for peer display names - resolveUser: bidirectional lookup (username → identity key) Encrypted local storage (nothing in cleartext): - ConversationStore uses SQLCipher when --state-password is provided - Argon2id key derivation with per-database random salt (.convdb-salt, mode 0600) - Transparent migration of existing unencrypted databases via sqlcipher_export - Token cache encrypted with QPCE format (Argon2id + ChaCha20Poly1305) Server changes: - resolveIdentity + resolveUser RPC handlers with auth + validation - Auth: sealed-sender identity binding on enqueue, channel member authorization - Delivery: hybrid decrypt attempts, identity key validation on enqueue - Config: --allow-sealed-sender flag for anonymous delivery mode - zeroize added to server dependencies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
108 lines
5.7 KiB
Cap'n Proto
108 lines
5.7 KiB
Cap'n Proto
# node.capnp — Unified quicnprotochat node RPC interface.
|
|
#
|
|
# Combines Authentication and Delivery operations into a single service.
|
|
#
|
|
# ID generated with: capnp id
|
|
@0xd5ca5648a9cc1c28;
|
|
|
|
interface NodeService {
|
|
# Upload a single-use KeyPackage for later retrieval by peers.
|
|
# identityKey : Ed25519 public key bytes (32 bytes)
|
|
# package : TLS-encoded openmls KeyPackage
|
|
# auth : Auth context (version=1, non-empty accessToken required).
|
|
uploadKeyPackage @0 (identityKey :Data, package :Data, auth :Auth) -> (fingerprint :Data);
|
|
|
|
# Fetch and atomically remove one KeyPackage for a given identity key.
|
|
# Returns empty Data if none are stored.
|
|
fetchKeyPackage @1 (identityKey :Data, auth :Auth) -> (package :Data);
|
|
|
|
# Enqueue an opaque payload for delivery to a recipient.
|
|
# channelId : Optional channel identifier (empty for default). A 16-byte UUID
|
|
# is recommended for 1:1 channels.
|
|
# version : Schema/wire version. Must be 1.
|
|
# Returns the monotonically increasing per-inbox sequence number assigned to this message.
|
|
enqueue @2 (recipientKey :Data, payload :Data, channelId :Data, version :UInt16, auth :Auth) -> (seq :UInt64);
|
|
|
|
# Fetch and drain all queued payloads for the recipient.
|
|
# limit: max number of messages to return (0 = fetch all).
|
|
# Returns envelopes with per-inbox sequence numbers for ordered MLS processing.
|
|
fetch @3 (recipientKey :Data, channelId :Data, version :UInt16, auth :Auth, limit :UInt32) -> (payloads :List(Envelope));
|
|
|
|
# Long-poll: wait up to timeoutMs for new payloads, then drain queue.
|
|
# limit: max number of messages to return (0 = fetch all).
|
|
# Returns envelopes with per-inbox sequence numbers for ordered MLS processing.
|
|
fetchWait @4 (recipientKey :Data, channelId :Data, version :UInt16, timeoutMs :UInt64, auth :Auth, limit :UInt32) -> (payloads :List(Envelope));
|
|
|
|
# Health probe for readiness/liveness.
|
|
health @5 () -> (status :Text);
|
|
|
|
# Upload the hybrid (X25519 + ML-KEM-768) public key for sealed envelope encryption.
|
|
uploadHybridKey @6 (identityKey :Data, hybridPublicKey :Data, auth :Auth) -> ();
|
|
|
|
# Fetch a peer's hybrid public key (for post-quantum envelope encryption).
|
|
fetchHybridKey @7 (identityKey :Data, auth :Auth) -> (hybridPublicKey :Data);
|
|
|
|
# ── OPAQUE password-authenticated registration ──────────────────────────
|
|
|
|
# Start OPAQUE registration: client sends blinded password element.
|
|
opaqueRegisterStart @8 (username :Text, request :Data) -> (response :Data);
|
|
|
|
# Finish OPAQUE registration: client uploads sealed credential envelope.
|
|
opaqueRegisterFinish @9 (username :Text, upload :Data, identityKey :Data) -> (success :Bool);
|
|
|
|
# ── OPAQUE password-authenticated login ─────────────────────────────────
|
|
|
|
# Start OPAQUE login: client sends credential request.
|
|
opaqueLoginStart @10 (username :Text, request :Data) -> (response :Data);
|
|
|
|
# Finish OPAQUE login: client sends credential finalization, receives session token.
|
|
opaqueLoginFinish @11 (username :Text, finalization :Data, identityKey :Data) -> (sessionToken :Data);
|
|
|
|
# ── P2P endpoint discovery ────────────────────────────────────────────────
|
|
|
|
# Publish this node's iroh endpoint address for P2P connectivity.
|
|
# nodeAddr is the serialized iroh NodeAddr (JSON or custom encoding).
|
|
publishEndpoint @12 (identityKey :Data, nodeAddr :Data, auth :Auth) -> ();
|
|
|
|
# Resolve a peer's iroh endpoint for direct P2P connection.
|
|
resolveEndpoint @13 (identityKey :Data, auth :Auth) -> (nodeAddr :Data);
|
|
|
|
# Peek at queued payloads without removing them (non-destructive read).
|
|
# Returns envelopes sorted by seq. Use `ack` to remove processed messages.
|
|
peek @14 (recipientKey :Data, channelId :Data, version :UInt16, auth :Auth, limit :UInt32) -> (payloads :List(Envelope));
|
|
|
|
# Acknowledge (remove) all messages up to and including the given sequence number.
|
|
ack @15 (recipientKey :Data, channelId :Data, version :UInt16, seqUpTo :UInt64, auth :Auth) -> ();
|
|
|
|
# Fetch multiple peers' hybrid public keys in a single round-trip.
|
|
fetchHybridKeys @16 (identityKeys :List(Data), auth :Auth) -> (keys :List(Data));
|
|
|
|
# Enqueue the same payload to multiple recipients in a single round-trip.
|
|
batchEnqueue @17 (recipientKeys :List(Data), payload :Data, channelId :Data, version :UInt16, auth :Auth) -> (seqs :List(UInt64));
|
|
|
|
# Create a 1:1 channel between the caller and the given peer. Returns a 16-byte channelId (UUID).
|
|
# Both members can enqueue/fetch for this channel; recipientKey must be the other member.
|
|
createChannel @18 (peerKey :Data, auth :Auth) -> (channelId :Data);
|
|
|
|
# Resolve a username to its Ed25519 identity key (32 bytes).
|
|
# Returns empty Data if the username is not registered.
|
|
resolveUser @19 (username :Text, auth :Auth) -> (identityKey :Data);
|
|
|
|
# Reverse lookup: resolve an Ed25519 identity key to the registered username.
|
|
# Returns empty Text if the identity key is not associated with any user.
|
|
resolveIdentity @20 (identityKey :Data, auth :Auth) -> (username :Text);
|
|
}
|
|
|
|
struct Auth {
|
|
version @0 :UInt16; # 1 = token-based auth (required)
|
|
accessToken @1 :Data; # opaque bearer token issued at login
|
|
deviceId @2 :Data; # optional UUID bytes for auditing/rate limiting
|
|
}
|
|
|
|
# A delivery envelope pairing a per-inbox sequence number with an opaque payload.
|
|
# Clients sort by `seq` before processing to guarantee MLS commit ordering.
|
|
struct Envelope {
|
|
seq @0 :UInt64; # monotonically increasing per-inbox counter (assigned by server)
|
|
data @1 :Data; # opaque payload (hybrid-encrypted MLS message)
|
|
}
|