mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-10 09:41:37 +00:00
Test negative output
This commit is contained in:
parent
eeaaa8cc84
commit
26cb0c5a17
@ -51,7 +51,7 @@ export class IKHandshake implements IHandshake {
|
||||
try {
|
||||
await verifySignedPayload(receivedMessageBuffer.ns, plaintext, this.remotePeer.id);
|
||||
} catch (e) {
|
||||
throw new Error(`Error occurred while verifying signed payload: ${e.message}`);
|
||||
throw new Error(`Error occurred while verifying initiator's signed payload: ${e.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ export class IKHandshake implements IHandshake {
|
||||
try {
|
||||
await verifySignedPayload(receivedMessageBuffer.ns, plaintext, this.remotePeer.id);
|
||||
} catch (e) {
|
||||
throw new Error(`Error occurred while verifying signed payload: ${e.message}`);
|
||||
throw new Error(`Error occurred while verifying responder's signed payload: ${e.message}`);
|
||||
}
|
||||
} else {
|
||||
const messageBuffer = this.ik.sendMessage(this.session, this.payload);
|
||||
|
@ -1,11 +1,11 @@
|
||||
import Wrap from "it-pb-rpc";
|
||||
import Duplex from 'it-pair/duplex';
|
||||
import {Buffer} from "buffer";
|
||||
import {assert, expect} from "chai";
|
||||
|
||||
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
||||
import {generateKeypair, getPayload} from "../src/utils";
|
||||
import {IKHandshake} from "../src/handshake-ik";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("IK Handshake", () => {
|
||||
let peerA, peerB, fakePeer;
|
||||
@ -53,4 +53,28 @@ describe("IK Handshake", () => {
|
||||
assert(false, e.message);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw error if responder's static key changed", async() => {
|
||||
try {
|
||||
const duplex = Duplex();
|
||||
const connectionFrom = Wrap(duplex[0]);
|
||||
const connectionTo = Wrap(duplex[1]);
|
||||
|
||||
const prologue = Buffer.from('/noise');
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const staticKeysResponder = generateKeypair();
|
||||
const oldScammyKeys = generateKeypair();
|
||||
|
||||
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||
const handshakeInit = new IKHandshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, peerB, oldScammyKeys.publicKey);
|
||||
|
||||
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||
const handshakeResp = new IKHandshake(false, respPayload, prologue, staticKeysResponder, connectionTo, peerA, staticKeysInitiator.publicKey);
|
||||
|
||||
await handshakeInit.stage0();
|
||||
await handshakeResp.stage0();
|
||||
} catch (e) {
|
||||
expect(e.message).to.include("Error occurred while verifying initiator's signed payload");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user