Make ephemeral keypair optional

This commit is contained in:
Belma Gutlic 2020-01-07 13:20:42 +01:00
parent 73c336088e
commit 28bf51c492
3 changed files with 8 additions and 6 deletions

View File

@ -16,7 +16,7 @@ import { WrappedConnection } from "./noise";
import {decode0, decode1, encode1} from "./encoder"; import {decode0, decode1, encode1} from "./encoder";
export class Handshake extends XXHandshake { export class Handshake extends XXHandshake {
private ephemeralKeys: KeyPair; private ephemeralKeys?: KeyPair;
private initialMsg: bytes; private initialMsg: bytes;
constructor( constructor(
@ -27,12 +27,14 @@ export class Handshake extends XXHandshake {
staticKeys: KeyPair, staticKeys: KeyPair,
connection: WrappedConnection, connection: WrappedConnection,
remotePeer: PeerId, remotePeer: PeerId,
ephemeralKeys: KeyPair,
initialMsg: bytes, initialMsg: bytes,
ephemeralKeys?: KeyPair,
handshake?: XX, handshake?: XX,
) { ) {
super(isInitiator, libp2pPrivateKey, libp2pPublicKey, prologue, staticKeys, connection, remotePeer, handshake); super(isInitiator, libp2pPrivateKey, libp2pPublicKey, prologue, staticKeys, connection, remotePeer, handshake);
if (ephemeralKeys) {
this.ephemeralKeys = ephemeralKeys; this.ephemeralKeys = ephemeralKeys;
}
this.initialMsg = initialMsg; this.initialMsg = initialMsg;
} }

View File

@ -130,7 +130,7 @@ export class Noise implements NoiseConnection {
): Promise<XXFallback> { ): Promise<XXFallback> {
const { isInitiator, libp2pPublicKey, remotePeer, connection } = params; const { isInitiator, libp2pPublicKey, remotePeer, connection } = params;
const handshake = const handshake =
new XXFallback(isInitiator, this.privateKey, libp2pPublicKey, this.prologue, this.staticKeys, connection, remotePeer, ephemeralKeys, initialMsg); new XXFallback(isInitiator, this.privateKey, libp2pPublicKey, this.prologue, this.staticKeys, connection, remotePeer, initialMsg, ephemeralKeys);
try { try {
await handshake.propose(); await handshake.propose();

View File

@ -48,10 +48,10 @@ describe("XX Fallback Handshake", () => {
}); });
const handshakeInit = const handshakeInit =
new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB, ephemeralKeys, initialMsg); new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB, initialMsg, ephemeralKeys);
const handshakeResp = const handshakeResp =
new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA, ephemeralKeys, initialMsg); new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA, initialMsg);
await handshakeInit.propose(); await handshakeInit.propose();