pub struct TrustStore { /* private fields */ }Expand description
Persistent trust: peers an operator accepted, peers that were turned away and wait to be accepted (pairing), open invitations, and announced successor keys.
§Pairing
- A server turns away a peer it does not trust, after the peer proved it holds the
key it presented, and records its key with
record_waiting. - The operator lists
waitingand eitheraccepts an entry by id orremoves it. - The next handshake finds the peer
is_accepted.
Every method must meet this contract: nothing is recorded as waiting until the peer has shown, inside the handshake, that it holds the private key of the public key it presents (a signature over the handshake transcript, a key exchange that only the key’s holder can complete, …). Presenting a key proves nothing: anyone can copy a public certificate, and a store that records unproven keys lets a stranger fill the queue with somebody else’s identity, or put a real peer’s id in front of the operator under a source address that is not theirs. A handshake that fails to prove the key records nothing.
An invitation lets a joiner pair without waiting: it presents the
secret over a channel that proves its key, and the inviter redeems
it and accepts the key.
§Rotation
A peer accepted as key A announces its successor B over a session A authenticated
(announce_successor). The first time the peer proves B
in a handshake, the method promote_successors it, unless
RotationOptions::require_approval leaves that to the caller; A is then accepted until
RotationOptions::retire_after has passed, and refused from then on. Removing A removes
its pending successor. Each step is queued as a RotationEvent.
§Key material and methods
The store keeps the bytes a method hands it as a KeyMaterial and never interprets
them: a PEM certificate for tls, another method’s own key for it. Each file records the
method name, so a store can hold the keys of several methods side by side, and a method
reads only the entries that name it. The id of an entry is the SHA-256 of its bytes; the
store checks that when it reads a file.
§On-disk format (version 1)
Under <state_dir>/peers/:
accepted/<64 lowercase hex>.pem one PEM block; the name is the peer's id
waiting/<64 lowercase hex>.pem the same, for a peer that proved its key and was refused
successors/<64 lowercase hex>.pem an announced successor key, named by its id
invitations/<64 lowercase hex>.inv an open invitation, named by the SHA-256 of its secretBefore the PEM block a file may hold header lines (PEM allows explanatory text there):
Method: <name>; in a waiting file Source: <ip>:<port> (IPv6 as [addr]:port), the
address the handshake came from; in an accepted file Successor: <64 hex> (the announced
or promoting successor) and Retires: <unix seconds>; in a successor file
Predecessor: <64 hex>. An invitation file is header lines only: Expires: <unix seconds>, Uses: <count> and, when not empty, Label: <text>; it never holds the
secret. A key file without a Method: line, or named otherwise, is not read. Accepting moves a file from waiting/ to
accepted/, rewritten without the Source: line.
Implementations§
Source§impl TrustStore
impl TrustStore
Sourcepub fn builder() -> TrustStoreBuilder
pub fn builder() -> TrustStoreBuilder
A builder with nothing set.
Source§impl TrustStore
impl TrustStore
Sourcepub fn waiting_queue(self, settings: WaitingSettings) -> Self
pub fn waiting_queue(self, settings: WaitingSettings) -> Self
This store with a new, empty waiting queue under settings, the replacement for the queue it
was built with. Rotation and the clock stay.
Sourcepub fn settings(&self) -> TrustStoreSettings
pub fn settings(&self) -> TrustStoreSettings
The settings it was built with.
Sourcepub fn non_defaults(&self) -> Vec<NonDefault>
pub fn non_defaults(&self) -> Vec<NonDefault>
Every setting that differs from its default, named by key path.
Sourcepub fn rotation(&self) -> RotationOptions
pub fn rotation(&self) -> RotationOptions
The rotation options in force.
Sourcepub fn accepted_key(&self, id: &PeerId) -> Option<KeyMaterial>
pub fn accepted_key(&self, id: &PeerId) -> Option<KeyMaterial>
The key material of an accepted peer, when it is accepted, not retired, and its file is sound.
Sourcepub fn waiting_key(&self, id: &PeerId) -> Option<KeyMaterial>
pub fn waiting_key(&self, id: &PeerId) -> Option<KeyMaterial>
The key material of a waiting peer, when it is waiting and its file is sound.
Sourcepub fn accept(&self, id: &PeerId) -> Result<(), Error>
pub fn accept(&self, id: &PeerId) -> Result<(), Error>
Accepts a waiting peer by its id.
§Errors
Error::NotWaiting, Error::AlreadyAccepted, or Error::Material when the
stored key does not hash to the name.
Sourcepub fn accept_key(&self, key: &KeyMaterial) -> Result<PeerId, Error>
pub fn accept_key(&self, key: &KeyMaterial) -> Result<PeerId, Error>
Accepts a key directly, without it having waited.
§Errors
Error::Material when the key is not valid, Error::AlreadyAccepted when it is
accepted and current, Error::Io on write failure. A key past its retirement time is
accepted again, its file rewritten without Successor: and Retires:.
Sourcepub fn is_accepted(&self, id: &PeerId) -> bool
pub fn is_accepted(&self, id: &PeerId) -> bool
Whether id is accepted, not past its retirement time, and its stored key really hashes
to it.
Sourcepub fn record_waiting(&self, key: &KeyMaterial, source: Option<SocketAddr>)
pub fn record_waiting(&self, key: &KeyMaterial, source: Option<SocketAddr>)
Records a turned-away peer’s key as waiting. Failures are not reported to the peer.
Call this only after the peer proved it holds the key (see the pairing contract).
Bounded: invalid keys are ignored; one source holds at most
per_source entries, a newcomer being refused
(WhenFull); it records a new peer at most once per
record_interval; the same
peer from the same source is recorded at most once per
rerecord; the directory holds at most
total. A source is an IPv4 address (IPv4-mapped IPv6 included)
or an IPv6 prefix of ipv6_prefix bits, /64 by
default. The full source address is stored with the entry. None is the source of
callers that do not know it, which share one bucket.
Sourcepub fn invite(
&self,
random: &Random,
options: InvitationOptions,
label: &str,
) -> Result<Invitation, Error>
pub fn invite( &self, random: &Random, options: InvitationOptions, label: &str, ) -> Result<Invitation, Error>
Makes an invitation with a secret from random and records it (without the secret).
§Errors
Error::InvalidOptions when label is not one line of at most MAX_LABEL
bytes without surrounding spaces, uses is 0 or valid_for is zero;
Error::Random when random fails; Error::Io when the file cannot be written.
Sourcepub fn redeem(&self, secret: &[u8; 32]) -> Result<Invitation, Error>
pub fn redeem(&self, secret: &[u8; 32]) -> Result<Invitation, Error>
Redeems an invitation by its secret, using one of its uses: the invitation with the uses left after this one. The last use removes it.
Atomic: of concurrent redemptions of a single-use invitation exactly one succeeds. An expired invitation is removed.
§Errors
Error::NotInvited when no open invitation has this secret, Error::Expired when
it expired, Error::Io when its file cannot be read or moved.
Sourcepub fn invitations(&self) -> Result<Vec<InvitationEntry>, Error>
pub fn invitations(&self) -> Result<Vec<InvitationEntry>, Error>
Sourcepub fn revoke_invitation(&self, id: &InvitationId) -> Result<bool, Error>
pub fn revoke_invitation(&self, id: &InvitationId) -> Result<bool, Error>
Sourcepub fn announce_successor(
&self,
old: &PeerId,
new: &KeyMaterial,
) -> Result<(), Error>
pub fn announce_successor( &self, old: &PeerId, new: &KeyMaterial, ) -> Result<(), Error>
Records new as the pending successor of the accepted key old, replacing a successor
old announced before. Call it only with a key the holder of old sent over a session
old authenticated.
§Errors
Error::NotAccepted when old is not accepted or is already retiring;
Error::AlreadyAccepted when new is accepted; Error::SuccessorTaken when new is
the pending successor of another key that is still accepted; Error::Material when new is not
valid or is old; Error::Io on write failure.
Sourcepub fn successor_key(&self, new: &PeerId) -> Option<KeyMaterial>
pub fn successor_key(&self, new: &PeerId) -> Option<KeyMaterial>
The key of new when it is the pending successor of a key that is still accepted, not
retiring, and names it.
Sourcepub fn prove_successor(&self, new: &PeerId) -> Result<(), Error>
pub fn prove_successor(&self, new: &PeerId) -> Result<(), Error>
Records that the holder of the pending successor new proved it in a handshake (a
Proven: line with the time). A method calls it after the handshake signature verifies,
whether or not it then promotes. The first proof’s time is kept.
§Errors
Error::NoSuccessor when new is not the pending successor of an accepted key;
Error::Io on write failure.
Sourcepub fn promote_successor(&self, new: &PeerId) -> Result<PeerId, Error>
pub fn promote_successor(&self, new: &PeerId) -> Result<PeerId, Error>
Accepts the pending successor new and gives its predecessor a retirement time
(RotationOptions::retire_after from now). Returns the predecessor’s id. A method calls
it once the peer proved new, unless RotationOptions::require_approval is set; the
caller calls it to approve.
§Errors
Error::NoSuccessor when new is not the pending successor of an accepted key;
Error::NotProven when nobody proved it and RotationOptions::allow_unproven is not
set; Error::Io on write failure.
Sourcepub fn take_rotation_events(&self) -> Vec<RotationEvent>
pub fn take_rotation_events(&self) -> Vec<RotationEvent>
The rotation events since the last call, oldest first. Only events of this process are
kept, at most 1024; the on-disk state is in successors and
retiring.
Trait Implementations§
Source§impl Clone for TrustStore
impl Clone for TrustStore
Source§impl Debug for TrustStore
impl Debug for TrustStore
Source§impl PairingStore for TrustStore
impl PairingStore for TrustStore
Source§fn accept_key(&self, key: &KeyMaterial) -> Result<PeerId, Error>
fn accept_key(&self, key: &KeyMaterial) -> Result<PeerId, Error>
key and returns its id. Read moreSource§fn redeem(&self, secret: &[u8; 32]) -> Result<Invitation, Error>
fn redeem(&self, secret: &[u8; 32]) -> Result<Invitation, Error>
Source§fn accepted_key(&self, id: &PeerId) -> Option<KeyMaterial>
fn accepted_key(&self, id: &PeerId) -> Option<KeyMaterial>
None. The responder asks after accept_key
and refuses to report a pairing the store does not hold.