fix: check-paring message

This commit is contained in:
Vlad Stan 2022-08-18 09:01:05 +03:00
parent faa9a017a4
commit e37fc0b898

View File

@ -296,13 +296,13 @@ async function serialSigner(path) {
const device = this.getPairedDevice(deviceId) const device = this.getPairedDevice(deviceId)
if (device) { if (device) {
this.sharedSecret = nobleSecp256k1.utils.hexToBytes(device.sharedSecretHex) this.sharedSecret = nobleSecp256k1.utils.hexToBytes(
device.sharedSecretHex
)
this.hwwCheckSecureConnection() this.hwwCheckSecureConnection()
} else { } else {
this.hwwDhExchange() this.hwwDhExchange()
} }
}, },
hwwShowPasswordDialog: async function () { hwwShowPasswordDialog: async function () {
try { try {
@ -516,22 +516,19 @@ async function serialSigner(path) {
hwwCheckSecureConnection: async function () { hwwCheckSecureConnection: async function () {
const testString = 'lnbits' const testString = 'lnbits'
const iv = window.crypto.getRandomValues(new Uint8Array(16)) const iv = window.crypto.getRandomValues(new Uint8Array(16))
console.log('### this.sharedSecret', this.sharedSecret)
const encrypted = await this.encryptMessage( const encrypted = await this.encryptMessage(
this.sharedSecret, this.sharedSecret,
iv, iv,
testString testString.length + ' ' + testString
) )
const encryptedHex = nobleSecp256k1.utils.bytesToHex(encrypted) const encryptedHex = nobleSecp256k1.utils.bytesToHex(encrypted)
const encryptedIvHex = nobleSecp256k1.utils.bytesToHex(iv) const encryptedIvHex = nobleSecp256k1.utils.bytesToHex(iv)
try { try {
await this.writer.write( await this.sendCommandClearText(COMMAND_CHECK_PAIRING, [
COMMAND_CHECK_PAIRING + encryptedHex + encryptedIvHex
' ' + ])
encryptedHex +
encryptedIvHex +
'\n'
)
} catch (error) { } catch (error) {
this.$q.notify({ this.$q.notify({
type: 'warning', type: 'warning',
@ -606,7 +603,10 @@ async function serialSigner(path) {
.slice(1, 33) .slice(1, 33)
// window.localStorage.setItem('sharedSecret', nobleSecp256k1.utils.bytesToHex(this.sharedSecret)) // window.localStorage.setItem('sharedSecret', nobleSecp256k1.utils.bytesToHex(this.sharedSecret))
this.addPairedDevice(this.deviceId, nobleSecp256k1.utils.bytesToHex(this.sharedSecret)) this.addPairedDevice(
this.deviceId,
nobleSecp256k1.utils.bytesToHex(this.sharedSecret)
)
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
@ -765,6 +765,7 @@ async function serialSigner(path) {
}, },
sendCommandClearText: async function (command, attrs = []) { sendCommandClearText: async function (command, attrs = []) {
const message = [command].concat(attrs).join(' ') const message = [command].concat(attrs).join(' ')
console.log('### encryptedIvHex', message)
await this.writer.write(message + '\n') await this.writer.write(message + '\n')
}, },
extractCommand: async function (value) { extractCommand: async function (value) {
@ -836,8 +837,13 @@ async function serialSigner(path) {
return decryptedBytes return decryptedBytes
}, },
getPairedDevices: function () { getPairedDevices: function () {
console.log('### getPairedDevices', window.localStorage.getItem('lnbits-paired-devices')) console.log(
return JSON.parse(window.localStorage.getItem('lnbits-paired-devices')) || [] '### getPairedDevices',
window.localStorage.getItem('lnbits-paired-devices')
)
return (
JSON.parse(window.localStorage.getItem('lnbits-paired-devices')) || []
)
}, },
getPairedDevice: function (deviceId) { getPairedDevice: function (deviceId) {
const devices = this.getPairedDevices() const devices = this.getPairedDevices()
@ -857,10 +863,12 @@ async function serialSigner(path) {
sharedSecretHex: sharedSecretHex, sharedSecretHex: sharedSecretHex,
pairingDate: new Date().toISOString() pairingDate: new Date().toISOString()
}) })
window.localStorage.setItem('lnbits-paired-devices', JSON.stringify(devices)) window.localStorage.setItem(
'lnbits-paired-devices',
JSON.stringify(devices)
)
} }
}, },
created: async function () { created: async function () {}
}
}) })
} }