<p>In <ahref="https://rfc.vac.dev/35/">35/WAKU2-NOISE</a> we defined how Waku messages’ payloads can be encrypted using key material derived from key agreements based on the <ahref="http://www.noiseprotocol.org/noise.html">Noise Protocol Framework</a>.</p>
an encryption/decryption session - <em>or a Noise session</em> - would be instantiated.</p>
<p>This post provides an overview on how we can possibly implement and manage one or multiple Noise sessions in Waku.</p>
<h1id="preliminaries">
Preliminaries
<aclass="anchor"href="#preliminaries">#</a>
</h1>
<p>We assume that two users, e.g. Alice and Bob, successfully completed a Noise handshake.</p>
<p>Using <ahref="%28http://www.noiseprotocol.org/noise.html%29">Noise terminology</a>, at the end of the handshake they will share:</p>
<ul>
<li>two <em>Cipher States</em><code>CSOutbound</code> and <code>CSInbound</code>, to encrypt and decrypt outbound and inbound messages, respectively;</li>
<li>a handshake hash value <code>h</code>.</li>
</ul>
<p>As suggested in Noise specifications in regards to <ahref="http://www.noiseprotocol.org/noise.html#channel-binding">Channel Binding</a>,
we can identify a Noise session with a <code>session-id</code> derived from the handshake hash value <code>h</code> shared on completion of a Noise handshake.</p>
<p>More specifically, when Alice and Bob call <ahref="http://www.noiseprotocol.org/noise.html#the-symmetricstate-object">Split()</a> in order to derive the two final encryption and decryption Cipher States,
they further compute <code>session-id = HKDF(h)</code> using the supported key derivation function <code>HKDF</code>.</p>
<p>Such <code>session-id</code> will uniquely identify the Noise cryptographic session instantiated on completion of a Noise handshake,
which would then consist of the tuple <code>(session-id, CSOutbound, CSInbound)</code>.
For each instantiated Noise session we assume this tuple to be properly persisted,
since it is required to either retrieve and encrypt/decrypt any further exchanged message.</p>
<p>Once a Noise session is instantiated,
any further encrypted message between Alice and Bob within this session is exchanged on a <code>contentTopic</code> with name <code>/{application-name}/{application-version}/wakunoise/1/sessions/{ct-id}/proto</code>,
where <code>ct-id = Hash(Hash(session-id))</code>
and <code>/{application-name}/{application-version}/</code> identifies the application currently employing <ahref="https://rfc.vac.dev/35/">35/WAKU2-NOISE</a>.</p>
<h1id="session-states">
Session states
<aclass="anchor"href="#session-states">#</a>
</h1>
<p>A Noise session corresponding to a certain <code>session-id</code>:</p>
<ul>
<li>is always <strong>active</strong> as long as it is not marked as <strong>stale</strong>.
For an active <code>session-id</code>, new messages are published on the content topic <code>/{application-name}/{application-version}/wakunoise/1/sessions/{ct-id}/proto</code>;</li>
<li>is marked as <strong>stale</strong> if a <ahref="https://rfc.vac.dev/spec/35/#session-termination-message">session termination message</a> containing <code>Hash(session-id)</code> is published on the content topic <code>/{application-name}/{application-version}/wakunoise/1/sessions/{ct-id}/proto</code>.
However, since <code>session-id</code> is shared between Alice and Bob,
one party MAY decide to mark a Noise session as stale if no message from the other end was received within a certain fixed time window.</p>
<p>The above mechanism allows a Noise session to be marked as stale either privately or publicly,
depending if <code>Hash(session-id)</code> is sent on <code>/{application-name}/{application-version}/wakunoise/1/sessions/{ct-id}/proto</code> to the other party in encrypted form or not, respectively.</p>
<p>When a Noise session is publicly marked as stale,
network peers MAY discard all <ahref="https://rfc.vac.dev/spec/13/">stored</a> messages addressed to the content topic <code>/{application-name}/{application-version}/wakunoise/1/sessions/{ct-id}/proto</code>.
In this the case and in order for parties to retrieve any eventually delayed message,
peers SHOULD wait a fixed amount of time before discarding stored messages corresponding to a stale Noise session.</p>
<p>A stale Noise session cannot be directly marked as active
and parties are required to instantiate a new Noise session if they wish to communicate again.</p>
<p>However, parties can optionally persist and include the <code>session-id</code> corresponding to a stale Noise session in the <ahref="https://noiseprotocol.org/noise.html#prologue">prologue information</a> employed in the Noise handshake they execute to instantiate their new Noise session.
This effectively emulates a mechanism to <em>“re-activate”</em> a stale Noise session by binding it to a newly created active Noise session.</p>
<p>In order to reduce users’ metadata leakage, it is desirable (as suggested in <ahref="https://rfc.vac.dev/spec/35/#after-handshake">35/WAKU2-NOISE</a>) that content topics used for communications change every time a new message is exchanged.
This can be easily realized by employing a key derivation function to compute a new <code>session-id</code> from the previously employed one (e.g. <code>session-id = HKDF(prev-session-id)</code>),
while keeping the Inbound/outbound Cipher States, the content topic derivation mechanism and the stale mechanism the same as above.
In this case, when one party sends <strong>and</strong> receives at least one message,
he SHALL publicly mark as stale all Noise sessions relative to messages exchanged before the earlier of these two send/receive events.</p>
<p>Alice and Bob might possess one or more devices (e.g. laptops, smartphones, etc.) they wish to use to communicate.
In the following, we assume Alice and Bob to possess $N$ and $M$ devices, respectively.</p>
<p>Since a Noise session contains cryptographic material required to encrypt and decrypt messages exchanged on a pre-defined content topic derived from a <code>session-id</code>,
messages should be encrypted and decrypted within the Noise session instantiated between the currently-in-use sender’s and receiver’s device.</p>
<p>This is achieved through two main supported session management mechanisms that we called <code>N11M</code> and <code>NM</code>, respectively.</p>
<p>In a $N11M$ setting, each party’s device shares the same Noise session information used to encrypt and decrypt messages exchanged with the other party.</p>
<p>More precisely, once the first Noise session between any of Alice’s and Bob’s device is instantiated,
its session information is securely propagated to all other devices,
which then become able to send and receive new messages on the content topic associated to such session.
We note, however, that two devices belonging to one party cannot simultaneously send different messages to the other, since only the first message received will be correctly decrypted using the next nonce.</p>
<p>The most updated session information between Alice and Bob is propagated in encrypted form to other devices,
using previously instantiated Noise sessions.
In particular, all Alice’s (resp., Bob’s) devices that want to receive such updated session information, are required to have an already instantiated Noise session between them in order to receive it in encrypted form.
The propagated session information corresponds to the latest session information stored on the device currently communicating with (any of the devices of) the other party.</p>
<p>We note that sessions information is propagated only among devices belonging to the same party and not with other party’s devices.
Hence, Alice has no knowledge on the number of devices Bob is using and vice versa.</p>
<p>When any device marks a Noise session between Alice and Bob as stale,
all other (updated) devices will consider such session as stale
without publishing the <code>Hash(session-id)</code> on the corresponding session content topic.</p>
<p>In case a Noise session between two devices belonging to the same party is marked as stale,
such two devices stop to reciprocally propagate any information regarding Noise sessions instantiated with other parties.</p>
<p>As regards security, an attacker that compromises an encrypted message propagating session information,
might be able to compromise one or multiple messages exchanged within the session such information refers to.
This can be mitigated by adopting techniques similar to the the ones proposed in <ahref="https://rfc.vac.dev/spec/35/#after-handshake">35/WAKU2-NOISE</a>,
where encryption keys are changed every time a new message is exchanged.</p>
<p>This session management mechanism is loosely based on the paper <ahref="https://eprint.iacr.org/2019/1363.pdf">“Multi-Device for Signal”</a>.</p>
<p>A message is sent from the currently-in-use sender’s device to all recipent’s devices,
by properly encrypting and sending it to the content topics of each corresponding active Noise session.</p>
<p>We note that this allows the recipient to receive a message on all his devices simultaneously.
However, on the sender side, only the device which effectively sent the message will know its full content.</p>
<p>If it is required for sent messages to be available on all sender’s devices,
each pair of sender’s devices SHOULD have an active Noise session used for syncing purposes:
this sums up to a total of $N-1$ and $M-1$ extra Noise sessions instantiated on each Alice’s and Bob’s device, respectively.</p>
<p>Thus, if Alice wants to send a message to Bob from one of her $N$ devices,
she encrypts and sends her message to each of Bob’s $M$ devices
(and, eventually, to each of her other $N-1$ devices),
using the appropriate Noise session information.</p>
<p>If one device marks a Noise session as stale,
all active sessions instantiated with such device SHOULD be marked as stale as soon as possible.
If the device declaring a stale session does not send a session termination message to all the other party’s devices with which has an active session,
the other party SHOULD send a termination message to mark all such Noise sessions as stale.</p>
<p>This session management mechanism is loosely based on <ahref="https://signal.org/docs/specifications/sesame/">Signal’s Sesame Algorithm</a>.</p>