Expand description
§coqui-peer
Who a peer is, and whether we trust it, with no TLS and no cryptographic transport. This is
the core every authentication method shares: the peer id, a trust store with pairing and key
rotation, and a sans-IO handshake trait. A method lives in a crate of its own;
coqui-peer-tls is the TLS one. See the
documentation.
Status: alpha.
0.0.0-alpha.1is a pre-release: the API may change in any release before 1.0.
§Features
PeerId: a peer’s id as<alg>:<hash>text (sha256:3f15...), parsed from the forms people paste (bare hex, colon-separated hex, grouped base32), compared in constant time.TrustStore: accepted and waiting peers on disk. A peer is recorded as waiting only after it proved its key, bounded per source (IPv6 grouped by /64) and in total; an operator accepts or removes it by id.WaitingQueueis the same bounding for a host that stores waiting entries elsewhere.- Invitations and key rotation: one-time pairing secrets the store keeps only as a hash, redeemed atomically; a successor key announced under the current one, promoted once proven, the old key retiring after a window you choose.
- Pairing (module
pair): a joiner and a responder accept each other’s keys by an invitation, a short PIN checked by SPAKE2 (featurepin), or an RFC 8628-style device flow. Sans-IO; codes, pending joiners and decisions are data your app shows and acts on, and every limit is an option with a default. - A sans-IO
Handshake: feed received bytes or messages in, get bytes or messages out, over a byte stream, WebSocket messages or datagrams. Blocking drivers, with deadlines; async ones with thetokiofeature. One length-prefixed frame format for every message. - Files and PEM: the store’s atomic, no-replace writes and its PEM format, for method crates.
- Plain data and no process-wide state; nothing reads a file or an environment variable unless you name a directory.
§Installation
cargo add coqui-peer@0.0.0-alpha.1| Feature | Adds | Needed for | Default |
|---|---|---|---|
serde | serde | reading and writing PeerId and Digest as text, in the format you choose | off |
tokio | tokio (io-util, time) | the asynch drivers and frame functions | off |
pin | spake2, hkdf, hmac, rand_core | PIN pairing (Pairing::pin), Random::os | off |
Rust 1.89 or later. A default build depends on data-encoding, sha1, sha2, subtle and
zeroize.
§Quick start
Open a store, record a peer that has proved its key, and let the operator accept it:
use coqui_peer::{KeyMaterial, PeerId, TrustStore};
let store = TrustStore::open(std::path::Path::new("/var/lib/app"))?;
// A method hands the store the peer's public key; the id is its SHA-256.
let key = KeyMaterial::new("example", "PUBLIC KEY", vec![0u8; 32])?;
store.record_waiting(&key, Some("192.0.2.7:4000".parse()?)); // only after the key proof
store.accept(&key.id())?;
assert!(store.is_accepted(&key.id()));
// An id from text, in any accepted spelling.
let pinned: PeerId =
"sha256:630dcd2966c4336691125448bbb25b4ff412a49c732db2c8abc1b8581bd710dd".parse()?;
assert_eq!(pinned, key.id());Running a method’s handshake over a stream, with a deadline:
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
let established = coqui_peer::drive_stream_until(method.initiate()?, &mut socket, deadline)?;
let peer: PeerId = established.peer; // verified
let channel = established.session; // what the method produced§API overview
| Module | Purpose |
|---|---|
coqui_peer | PeerId, Digest; TrustStore, WaitingQueue, invitations and rotation; KeyMaterial; Clock, Random, Weakening; the Handshake and Method traits, the drivers and the frame functions; Error. |
coqui_peer::pair | Pairing by invitation, PIN or device flow: Pairing, PairingJoiner, PairingResponder, PairingDesk and their options. |
coqui_peer::asynch | The drivers and frame functions over tokio streams and async message transports (tokio). |
coqui_peer::file | Atomic writes: write_new never replaces, replace does; owner-only on request. |
coqui_peer::pem | The PEM block format the store writes, with its header lines. |
§The key-proof contract
A peer is recorded as waiting only after it proved, inside the handshake, that it holds the
private key of the key it presented. A presented key proves nothing: public keys and
certificates are copied freely, and recording them unproven would let a stranger queue
somebody else’s identity. Every method crate meets this contract; it is documented on
TrustStore.
§Development
cargo fmt --all --check
cargo clippy --all-targets --all-features -- -D warnings
cargo +1.89 clippy --all-targets --all-features -- -D warnings
cargo test --all-features
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
cargo +nightly-2026-09-21 public-api --all-features -sss --color never | diff -u tools/public-api.txt -§Releasing
This project follows Semantic Versioning and keeps a
CHANGELOG.md.
Pushing a tag matching v* runs the release workflow: the tests and a strict documentation
build gate a GitHub release, marked as a pre-release when the version has a - suffix. The
crate is published to crates.io with cargo publish by a maintainer.
§License
MPL-2.0; see LICENSE.
Modules§
- asynch
tokio - The loops of
drive_streamanddrive_messagesover tokio streams and async message transports. - file
- Whole-file writes that a crash or a concurrent writer cannot leave half done: the contents go to a temporary file beside the target, are synced, and only then take the target’s name.
- pair
- Pairing: how a joiner and a responder come to accept each other’s keys, over any channel.
- pem
- PEM blocks as the trust store writes them: header lines, then one block with 64-character base64 lines and LF line endings.
Structs§
- Admission
- What
WaitingQueue::admitdecided for one peer. - Clock
- The wall clock a
TrustStoreor a pairing desk reads for expiry and retirement times. - Established
- A verified peer and what the method produced besides.
- Invitation
- A one-time pairing secret: whoever presents it may pair, until it expires or its uses run out.
- Invitation
Entry - An open invitation, as listed: everything but the secret.
- Invitation
Id - The id of an invitation: the SHA-256 of its secret, and the name of its file. Knowing it does not let anyone redeem the invitation.
- Invitation
Options - How
TrustStore::invitemakes an invitation. - KeyMaterial
- The public key material a method gives the trust store for one peer, with the name of the method that understands it.
- PeerId
- Who a peer is: the hash of its public key or certificate, the whole of what one peer is told of another.
- Random
- A source of cryptographically secure random bytes: invitation secrets, user codes and pairing slots are drawn from it.
- Retiring
- An accepted key with a retirement time: it is refused from
retireson. - Rotation
Options - How an accepted peer’s key is replaced by its successor.
- Successor
- A pending successor:
newwas announced by the peer accepted asold, and is accepted once the peer proves it (or the caller promotes it). - Trust
Store - Persistent trust: peers an operator accepted, peers that were turned away and wait to be accepted (pairing), open invitations, and announced successor keys.
- Waiting
Entry - A peer waiting for acceptance.
- Waiting
Limits - Bounds on the waiting queue.
- Waiting
Queue - Decides which unaccepted peers are recorded as waiting, without storing anything: the
policy of
TrustStore::record_waiting, for a host that keeps its waiting entries elsewhere. - Weakening
- A setting looser than its strict value, as plain data for the caller to show or log.
Enums§
- Digest
- The algorithm a
PeerIdis made with: the<alg>of its<alg>:<hash>text. - Drive
Error - Why driving a handshake failed.
- Error
- Failures of ids, key material and the trust store. No message holds key material or a path.
- Framing
- How a method divides what it sends.
- Rotation
Event - A change of a peer’s key, for the caller to report as it chooses.
Constants§
- FORMAT_
VERSION - The version of the on-disk format
TrustStorewrites and reads. - MAX_
KEY_ BYTES - The most key material a store holds for one peer.
- MAX_
LABEL - The longest invitation label, in bytes.
- MAX_
MESSAGE - The longest message
drive_streamframes or accepts, in bytes.
Traits§
- Handshake
- One authentication exchange, driven by the caller.
- Message
Transport - A blocking transport of whole messages: WebSocket messages, datagrams, a shared-memory queue.
- Method
- An authentication method: a configured factory of handshakes.
- Read
Timeout - A blocking transport whose reads can be bounded in time, as the
_untilloops need to end at their deadline. - Write
Timeout - A blocking transport whose writes can be bounded in time, as the
_untilloops need when the peer stops reading.
Functions§
- complete_
messages drive_messageswithout the finalfinish, ascomplete_streamis todrive_stream.- complete_
messages_ until complete_messagesthat ends atdeadline, asdrive_messages_untildoes.- complete_
stream drive_streamwithout the finalfinish: returns the handshake once itis_complete, with everything it queued sent.- complete_
stream_ until complete_streamthat ends atdeadline, asdrive_stream_untildoes.- drive_
messages - Runs
handshaketo completion over a blocking message transport. Each message the handshake sends is one transport message, and each received one is handed over whole, for eitherFraming. - drive_
messages_ until drive_messagesthat ends atdeadline: every receive and send waits at most what is left until it, throughReadTimeoutandWriteTimeout, and both timeouts are cleared before it returns.- drive_
stream - Runs
handshaketo completion over a blocking byte stream. - drive_
stream_ until drive_streamthat ends atdeadline: every read and write waits at most what is left until it, throughReadTimeoutandWriteTimeout, and both timeouts are cleared before it returns.- read_
frame - Reads one frame written by
write_frame. The buffer grows as bytes arrive, so a declared length costs nothing until the peer sends it. - write_
frame - Writes
messageas one frame, its length first as four big-endian bytes, and flushes.