Added contract id verification. (#180)

* Added contract id config.
* Verify contract id with user/peer challenge.
* Updated cluster scripts.
* Updated node client lib for contract id verification.
This commit is contained in:
Ravin Perera
2020-12-01 16:08:41 +05:30
committed by GitHub
parent de71b97371
commit 596fd2b43c
16 changed files with 140 additions and 56 deletions

View File

@@ -15,7 +15,7 @@ async function main() {
let server = 'wss://localhost:8080'
if (process.argv.length == 3) server = 'wss://localhost:' + process.argv[2]
if (process.argv.length == 4) server = 'wss://' + process.argv[2] + ':' + process.argv[3]
const hpc = new HotPocket.Client(server, keys, HotPocket.protocols.bson);
const hpc = new HotPocket.Client(null, server, keys, HotPocket.protocols.bson);
// Establish HotPocket connection.
if (!await hpc.connect()) {

View File

@@ -40,7 +40,7 @@ const HotPocketKeyGenerator = {
},
}
function HotPocketClient(server, keys, protocol = protocols.json) {
function HotPocketClient(contractId, server, keys, protocol = protocols.json) {
let ws = null;
const msgHelper = new MessageHelper(keys, protocol);
@@ -102,7 +102,14 @@ function HotPocketClient(server, keys, protocol = protocols.json) {
}
if (m.type == 'handshake_challenge') {
// sign the challenge and send back the response
// Check whether contract id is matching if specified.
if (contractId && m.contract_id != contractId)
{
console.error("Contract id mismatch.")
ws.close();
}
// Sign the challenge and send back the response
const response = msgHelper.createHandshakeResponse(m.challenge);
ws.send(JSON.stringify(response));

View File

@@ -22,7 +22,7 @@ function RoboClient(server, port, clientId) {
this.connect = async () => {
this.keys = await HotPocketKeyGenerator.generate();
this.hpclient = new HotPocketClient(server + port, this.keys);
this.hpclient = new HotPocketClient(null, server + port, this.keys);
if (!await this.hpclient.connect()) {

View File

@@ -11,7 +11,7 @@ async function main() {
let server = 'wss://localhost:8080'
if (process.argv.length == 3) server = 'wss://localhost:' + process.argv[2]
if (process.argv.length == 4) server = 'wss://' + process.argv[2] + ':' + process.argv[3]
const hpc = new HotPocket.Client(server, keys, HotPocket.protocols.json);
const hpc = new HotPocket.Client(null, server, keys, HotPocket.protocols.json);
// Establish HotPocket connection.
if (!await hpc.connect()) {