From f73f5a90c9579211bf3eba3a5489d5dc8c880067 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 16 Aug 2022 14:08:04 +0300 Subject: [PATCH] feat: only allow DH key exchange in the first 60 seconds --- .../components/serial-signer/serial-signer.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js index 21f07596..ff61659b 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js @@ -577,12 +577,28 @@ async function serialSigner(path) { }, handleDhExchangeResponse: async function (res = '') { console.log('### handleDhExchangeResponse', res) - const [pubKeyHex] = res.trim().split(' ') - if (!pubKeyHex) { + const [statusCode, data] = res.trim().split(' ') + let pubKeyHex, errorMessage, captionMessage + switch (statusCode) { + case '0': + pubKeyHex = data + if(!data) errorMessage = 'Failed to exchange DH secret!' + break + case '1': + errorMessage = 'Secure connection can only be established in the first 60 seconds after start-up!' + captionMessage = 'Restart and try again' + break + + default: + errorMessage = 'Unexpected error code' + break + } + + if (errorMessage) { this.$q.notify({ type: 'warning', - message: 'Failed to exchange DH secret!', - caption: `${res}`, + message: errorMessage, + caption: captionMessage || '', timeout: 10000 })