mirror of
https://github.com/koush/scrypted.git
synced 2026-03-20 16:40:24 +00:00
zwave: network key base64 to hex data migration
This commit is contained in:
25
plugins/zwave/src/hex.ts
Normal file
25
plugins/zwave/src/hex.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export function isHex(s: string) {
|
||||
for (const c of s) {
|
||||
switch (c.toLowerCase()) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
break;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { Driver, Endpoint, ZWaveController, ZWaveNode, CommandClass } from "zwav
|
||||
import { ValueID, CommandClasses } from "@zwave-js/core"
|
||||
import { randomBytes } from "crypto";
|
||||
import path from "path";
|
||||
import { isHex } from "./hex";
|
||||
|
||||
const { log, deviceManager } = sdk;
|
||||
|
||||
@@ -53,7 +54,14 @@ export class ZwaveControllerProvider extends ScryptedDeviceBase implements Devic
|
||||
let s2AccessControlKey = this.storage.getItem('s2AccessControlKey');
|
||||
let s2AuthenticatedKey = this.storage.getItem('s2AuthenticatedKey');
|
||||
let s2UnauthenticatedKey = this.storage.getItem('s2UnauthenticatedKey');
|
||||
|
||||
|
||||
// 1/17/2022: the network key was stored as base64, but for consistency with HA
|
||||
// and others, it was switched to hex. this is the data migration.
|
||||
if (!isHex(networkKey)) {
|
||||
networkKey = Buffer.from(networkKey, 'base64').toString('hex');
|
||||
this.storage.setItem('networkKey', networkKey);
|
||||
}
|
||||
|
||||
if (!networkKey) {
|
||||
networkKey = randomBytes(16).toString('hex').toUpperCase();
|
||||
this.storage.setItem('networkKey', networkKey);
|
||||
|
||||
Reference in New Issue
Block a user