rekey: upgrade round 2 onwards
This commit is contained in:
parent
93ff823827
commit
6e63bb0e66
2 changed files with 12 additions and 7 deletions
|
@ -14,10 +14,9 @@ export default async function rekey(connection, secret_join) {
|
||||||
|
|
||||||
// 2: Round 2
|
// 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"
|
if(typeof their_round1 !== "object"
|
||||||
|| event !== "rekey"
|
|
||||||
|| their_round1.round !== 1
|
|| their_round1.round !== 1
|
||||||
|| typeof their_round1.content !== "string")
|
|| typeof their_round1.content !== "string")
|
||||||
throw new Error(`Error: Received invalid round 1 from peer`);
|
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 });
|
connection.send("rekey", { round: 2, content: our_round2 });
|
||||||
|
|
||||||
// 3: Compute new shared key
|
// 3: Compute new shared key
|
||||||
const their_round2 = (await once(connection, "message-rekey"))[0];
|
const their_round2 = (await once(connection, "message-rekey"))[1];
|
||||||
if(typeof their_round2 !== "string") return null;
|
|
||||||
const new_shared_key = jpake.ComputeSharedKey(their_round2);
|
if(typeof their_round2 !== "object"
|
||||||
if(typeof new_shared_key !== "string") return null;
|
|| 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");
|
return Buffer.from(new_shared_key, "hex");
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import make_cert from 'make-cert';
|
||||||
import l from 'log';
|
import l from 'log';
|
||||||
|
|
||||||
import settings from '../../settings.mjs';
|
import settings from '../../settings.mjs';
|
||||||
import starttls from '../../lib/transport/starttls.mjs';
|
import Connection from '../../lib/transport/Connection.mjs';
|
||||||
|
|
||||||
export default async function() {
|
export default async function() {
|
||||||
const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78=";
|
const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78=";
|
||||||
|
|
Loading…
Reference in a new issue