Reset noise state when server retracts and reasserts session

This commit is contained in:
Tony Garnock-Jones 2024-03-19 20:35:54 +01:00
parent 140dc240c8
commit 0f13f2b238
1 changed files with 12 additions and 11 deletions

View File

@ -247,16 +247,7 @@ export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketCon
(() => { throw new Error("Invalid pre-shared keys"); })();
const prologue = underlying(canonicalEncode(spec.service));
const H = new SaltyCrypto.Handshake(
algorithms,
patternName,
'initiator',
{
prologue,
remoteStaticPublicKey: underlying(spec.key),
preSharedKeys: preSharedKeys.map(underlying),
});
let H: SaltyCrypto.Handshake | null = null;
let transportState: SaltyCrypto.TransportState | null = null;
let responderSession: Ref | null = null;
let relay: Relay.Relay | null = null;
@ -306,6 +297,16 @@ export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketCon
if (!response) return;
switch (response._variant) {
case "accepted":
H = new SaltyCrypto.Handshake(
algorithms,
patternName,
'initiator',
{
prologue,
remoteStaticPublicKey: underlying(spec.key),
preSharedKeys: preSharedKeys.map(underlying),
});
transportState = null;
responderSession = response.responderSession;
const { packet, finished } = H.writeMessage(new Uint8Array());
at responderSession {
@ -340,7 +341,7 @@ export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketCon
if (p._variant !== 'complete') {
throw new Error("Unexpected fragmentation in handshake");
}
const { message, finished } = H.readMessage(underlying(p.value));
const { message, finished } = H!.readMessage(underlying(p.value));
if (message.byteLength !== 0) {
throw new Error("Unexpected payload during handshake");
}