pub struct Initiator { /* private fields */ }Expand description
Noise initiator state for one connection: the server half.
The server always sends the first handshake message, so this type produces message 1 and
consumes message 2. It starts with the published Sentinel PSK; Initiator::set_psk selects
the key the session will actually use, which message 1 must announce.
The suite is the one the client announced in client/init: a server must run exactly that one,
because the client builds its responder for it. There is no fallback - Initiator::new
refuses a prologue that announces another suite, and Initiator::with_announced_suite takes
the suite from the announcement so the two cannot disagree.
Implementations§
Source§impl Initiator
impl Initiator
Sourcepub fn new(
identity: &Identity,
peer_public: &[u8; 32],
suite: Suite,
prologue: &[u8],
) -> Result<Initiator>
pub fn new( identity: &Identity, peer_public: &[u8; 32], suite: Suite, prologue: &[u8], ) -> Result<Initiator>
Builds the initiator for an explicit peer key and suite.
prologue reaches Noise unchanged, so both sides must mix in the same bytes: the exact
client/init and server/init of a first handshake, or the previous handshake hash on a
re-handshake. When the prologue carries a client/init, the suite it announces must be
suite; a prologue that carries no announcement - a re-handshake hash, which is not
JSON - leaves suite as the only source, and a suite this build does not have is always
refused.
Sourcepub fn with_announced_suite(
identity: &Identity,
peer_public: &[u8; 32],
prologue: &[u8],
) -> Result<Initiator>
pub fn with_announced_suite( identity: &Identity, peer_public: &[u8; 32], prologue: &[u8], ) -> Result<Initiator>
Builds the initiator for the suite the prologue’s client/init announces.
This is the constructor for a first handshake: the announcement decides the suite, so the
two cannot disagree. A prologue that is not the init exchange, that carries no
client/init, that carries two of them, that announces no suite or that announces one
this build does not have is rejected; use Initiator::new on a re-handshake, where the
prologue is the previous handshake hash.
Sourcepub fn set_psk(&mut self, psk: &[u8; 32]) -> Result<()>
pub fn set_psk(&mut self, psk: &[u8; 32]) -> Result<()>
Replaces the pre-shared key used by the rest of the handshake.
The initiator starts with the published Sentinel PSK. Call this before writing message 1 when the handshake announces a private key, because message 1’s payload names the key this call selects; noise mixes the key into message 2 either way, so both sides must use the same value or the peer’s message 2 does not authenticate.
Sourcepub fn write_message(&mut self, payload: &[u8]) -> Result<Vec<u8>>
pub fn write_message(&mut self, payload: &[u8]) -> Result<Vec<u8>>
Writes Noise handshake message 1 with payload and returns the message.
The payload is the PSK metadata (psk_id, psk_category) the session layer builds; this
module does not interpret it. It travels encrypted, so it must fit into a Noise message.
Sourcepub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>>
pub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>>
Reads Noise handshake message 2 and returns its decrypted payload.
The payload is returned verbatim; Sendspin requires it to be the empty JSON object, which the session layer checks. Fails when the message does not authenticate, which covers a message sealed with another PSK, a changed byte and a truncation.
Sourcepub fn handshake_finished(&self) -> bool
pub fn handshake_finished(&self) -> bool
Returns whether both handshake messages have been processed.
Sourcepub fn into_transport(self) -> Result<TransportState>
pub fn into_transport(self) -> Result<TransportState>
Finishes the handshake and switches to transport mode.
Returns what Responder::into_transport returns: the handshake hash a re-handshake
mixes in and the suite these keys were derived under. Fails if message 2 is still
outstanding, which Initiator::handshake_finished reports ahead of time.