feat: show pairing code

This commit is contained in:
Vlad Stan 2022-08-18 17:54:26 +03:00
parent d8d4d4d057
commit 90938e89e1
2 changed files with 50 additions and 24 deletions

View file

@ -351,6 +351,25 @@
</q-card> </q-card>
</q-dialog> </q-dialog>
<q-dialog v-model="showConsole" position="top">
<q-card class="q-pa-lg q-pt-xl">
<q-input
filled
dense
for="serial-port-console"
v-model.trim="receivedData"
type="textarea"
rows="25"
cols="200"
label="Console"
></q-input>
<div class="row q-mt-lg">
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div>
</q-card>
</q-dialog>
<q-dialog v-model="hww.showSeedDialog" position="top"> <q-dialog v-model="hww.showSeedDialog" position="top">
<q-card class="q-pa-lg q-pt-xl"> <q-card class="q-pa-lg q-pt-xl">
<span>Check word at position {{hww.seedWordPosition}} on display</span> <span>Check word at position {{hww.seedWordPosition}} on display</span>

View file

@ -244,7 +244,7 @@ async function serialSigner(path) {
this.handleShowSeedResponse(commandData) this.handleShowSeedResponse(commandData)
break break
case COMMAND_PAIR: case COMMAND_PAIR:
this.handleDhExchangeResponse(commandData) this.handlePairResponse(commandData)
break break
case COMMAND_LOG: case COMMAND_LOG:
console.log( console.log(
@ -310,7 +310,7 @@ async function serialSigner(path) {
) )
this.hwwCheckPairing() this.hwwCheckPairing()
} else { } else {
this.hwwDhExchange() this.hwwPair()
} }
}, },
hwwShowPasswordDialog: async function () { hwwShowPasswordDialog: async function () {
@ -550,7 +550,7 @@ async function serialSigner(path) {
handleCheckPairingResponse: async function (res = '') { handleCheckPairingResponse: async function (res = '') {
console.log('### handleCheckPairingResponse', res) console.log('### handleCheckPairingResponse', res)
}, },
hwwDhExchange: async function () { hwwPair: async function () {
try { try {
this.decryptionKey = nobleSecp256k1.utils.randomPrivateKey() this.decryptionKey = nobleSecp256k1.utils.randomPrivateKey()
const publicKey = nobleSecp256k1.Point.fromPrivateKey( const publicKey = nobleSecp256k1.Point.fromPrivateKey(
@ -565,20 +565,20 @@ async function serialSigner(path) {
]) ])
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
message: 'Starting secure session!', message: 'Pairing started!',
timeout: 5000 timeout: 5000
}) })
} catch (error) { } catch (error) {
this.$q.notify({ this.$q.notify({
type: 'warning', type: 'warning',
message: 'Failed to send DH Public Key to device!', message: 'Failed to pair with device!',
caption: `${error}`, caption: `${error}`,
timeout: 10000 timeout: 10000
}) })
} }
}, },
handleDhExchangeResponse: async function (res = '') { handlePairResponse: async function (res = '') {
console.log('### handleDhExchangeResponse', res) console.log('### handlePairResponse', res)
const [statusCode, data] = res.trim().split(' ') const [statusCode, data] = res.trim().split(' ')
let pubKeyHex, errorMessage, captionMessage let pubKeyHex, errorMessage, captionMessage
switch (statusCode) { switch (statusCode) {
@ -588,7 +588,7 @@ async function serialSigner(path) {
break break
case '1': case '1':
errorMessage = errorMessage =
'Secure connection can only be established in the first 10 seconds after start-up!' 'Device pairing only possible in the first 10 seconds after start-up!'
captionMessage = 'Restart and try again' captionMessage = 'Restart and try again'
break break
@ -604,7 +604,7 @@ async function serialSigner(path) {
caption: captionMessage || '', caption: captionMessage || '',
timeout: 10000 timeout: 10000
}) })
this.closeSerialPort()
return return
} }
const hwwPublicKey = nobleSecp256k1.Point.fromHex('04' + pubKeyHex) const hwwPublicKey = nobleSecp256k1.Point.fromHex('04' + pubKeyHex)
@ -613,17 +613,30 @@ async function serialSigner(path) {
.getSharedSecret(this.decryptionKey, hwwPublicKey) .getSharedSecret(this.decryptionKey, hwwPublicKey)
.slice(1, 33) .slice(1, 33)
// window.localStorage.setItem('sharedSecret', nobleSecp256k1.utils.bytesToHex(this.sharedSecret)) const sharedSecretHex = nobleSecp256k1.utils.bytesToHex(this.sharedSecret)
const sharedSecredHash = await nobleSecp256k1.utils.sha256(asciiToUint8Array(sharedSecretHex))
const fingerprint = nobleSecp256k1.utils.bytesToHex(sharedSecredHash).substring(0, 5).toUpperCase()
console.log('### fingerprint', fingerprint)
//
LNbits.utils
.confirmDialog('Confirm code from display: '+fingerprint)
.onOk(() => {
this.addPairedDevice( this.addPairedDevice(
this.deviceId, this.deviceId,
nobleSecp256k1.utils.bytesToHex(this.sharedSecret) nobleSecp256k1.utils.bytesToHex(this.sharedSecret)
) )
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
message: 'Secure session created!', message: 'Paired with device!',
timeout: 5000 timeout: 5000
}) })
}).onCancel(() => {
this.closeSerialPort()
})
}, },
hwwHelp: async function () { hwwHelp: async function () {
try { try {
@ -825,12 +838,6 @@ async function serialSigner(path) {
console.log('### decryptData ', data, command) console.log('### decryptData ', data, command)
return command return command
} catch (error) { } catch (error) {
this.$q.notify({
type: 'warning',
message: 'Failed to decrypt message from device!',
caption: `${error}`,
timeout: 10000
})
return '/error Failed to decrypt message from device!' return '/error Failed to decrypt message from device!'
} }
}, },