From 6e63bb0e6692ffc30afce94dab5270388380a225 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 2 Oct 2021 17:38:24 +0100 Subject: [PATCH] rekey: upgrade round 2 onwards --- src/lib/transport/rekey.mjs | 17 +++++++++++------ src/subcommands/test-server/test-server.mjs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/transport/rekey.mjs b/src/lib/transport/rekey.mjs index 49c558b..83aa17e 100644 --- a/src/lib/transport/rekey.mjs +++ b/src/lib/transport/rekey.mjs @@ -14,10 +14,9 @@ export default async function rekey(connection, secret_join) { // 2: Round 2 - let [ event, their_round1 ] = (await once(connection, "message-rekey")); + const their_round1 = (await once(connection, "message-rekey"))[1]; if(typeof their_round1 !== "object" - || event !== "rekey" || their_round1.round !== 1 || typeof their_round1.content !== "string") throw new Error(`Error: Received invalid round 1 from peer`); @@ -28,10 +27,16 @@ export default async function rekey(connection, secret_join) { connection.send("rekey", { round: 2, content: our_round2 }); // 3: Compute new shared key - const their_round2 = (await once(connection, "message-rekey"))[0]; - if(typeof their_round2 !== "string") return null; - const new_shared_key = jpake.ComputeSharedKey(their_round2); - if(typeof new_shared_key !== "string") return null; + const their_round2 = (await once(connection, "message-rekey"))[1]; + + if(typeof their_round2 !== "object" + || their_round2.round !== 1 + || typeof their_round2.content !== "string") + throw new Error(`Error: Received invalid round 2 from peer`); + + const new_shared_key = jpake.ComputeSharedKey(their_round2.content); + if(typeof new_shared_key !== "string") + throw new Error(`Error: Failed to compute shared key`); return Buffer.from(new_shared_key, "hex"); diff --git a/src/subcommands/test-server/test-server.mjs b/src/subcommands/test-server/test-server.mjs index 284d96e..5376dd4 100644 --- a/src/subcommands/test-server/test-server.mjs +++ b/src/subcommands/test-server/test-server.mjs @@ -6,7 +6,7 @@ import make_cert from 'make-cert'; import l from 'log'; import settings from '../../settings.mjs'; -import starttls from '../../lib/transport/starttls.mjs'; +import Connection from '../../lib/transport/Connection.mjs'; export default async function() { const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78=";