//! OTP/1 — the opentracker wire protocol. //! //! One encrypted UDP datagram per report, no handshake, no connection state. A //! cold TCP+TLS connection costs roughly ten round trips before the first byte //! of payload, and a phone that sleeps between reports has a cold connection //! nearly every time; a single datagram that survives the phone changing IP //! mid-journey is the entire point of this protocol. //! //! This crate is the codec and nothing else: **no I/O, no async, no RNG, no //! clock.** Nonces and timestamps are passed in by the caller. That is what //! makes it fuzzable, property-testable, and able to emit reproducible golden //! vectors — which are the contract the Kotlin implementation is checked //! against, and the thing that stops a protocol change from silently bricking //! installed apps. //! //! ## Shape of a datagram //! //! ```text //! header[21] || ChaCha20Poly1305(K_dir, nonce, payload, aad = header) //! ``` //! //! ## Why there is no replay protection //! //! Timestamps are absolute and client-supplied, and the server stores points //! under `UNIQUE(user_id, ts)` with `ON CONFLICT DO UPDATE`. A replayed //! datagram therefore carries a timestamp that already exists and collapses //! into the row already there — replay is idempotent *by construction*. An //! attacker without the key cannot forge new positions and cannot create //! duplicate rows, so a counter, a persisted ledger and a replay window would //! all be state to maintain for no gain. //! //! ## Example //! //! ``` //! use otproto::{Header, Message, MsgType, Point, kdf, msg::Direction}; //! //! let token_key = [0x11; 32]; //! let k_up = kdf::derive(&token_key, Direction::Up); //! let nonce = [0x22; 12]; // in production: 12 fresh random bytes //! //! let msg = Message::Loc(vec![Point::new(1_785_000_042, 525_200_080, 134_050_000)]); //! let datagram = otproto::seal_message(&k_up, 0x1122_3344_5566_7788, nonce, &msg); //! assert_eq!(datagram.len(), 62); //! //! // The server peeks the header to choose a key, then opens. //! let peeked = Header::peek(&datagram).unwrap(); //! assert_eq!(peeked.msg_type, MsgType::Loc); //! let (_, back) = otproto::open_message(&k_up, &datagram).unwrap(); //! assert_eq!(back, msg); //! ``` pub mod error; pub mod frame; pub mod kdf; pub mod msg; pub mod point; pub use error::{DecodeError, ValidationError}; pub use frame::{ HEADER_LEN, Header, MAX_DATAGRAM, MAX_REPLY, MIN_DATAGRAM, REVOKED_DATAGRAM_LEN, TAG_LEN, VERSION, datagram_len, fits_reply_budget, may_answer_unverified, open, open_message, seal, seal_message, }; pub use kdf::{KEY_LEN, Key, revocation_key}; pub use msg::{ Ack, AckFlags, Config, ConfigFlags, ConfigGet, Direction, Hello, HelloFlags, MAX_POINTS, Message, MsgType, NONCE_LEN, Nack, NackReason, Nonce, Ping, Pong, Profile, RevokeReason, Revoked, }; pub use point::{Flags as PointFlags, POINT_LEN, Point};