Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow S2 keys in OZW format for migration from networkKey #399

Merged
merged 1 commit into from Sep 30, 2021
Merged

Allow S2 keys in OZW format for migration from networkKey #399

merged 1 commit into from Sep 30, 2021

Conversation

kpine
Copy link
Contributor

@kpine kpine commented Sep 30, 2021

This allows for migrations from "networkKey", which are allowed to be in OZW format, to "S0_Legacy" without requiring a change in key format. Client applications can choose to migrate key formats on their own.

First reported at https://community.home-assistant.io/t/zwave-js-fails-to-load/342679. Based on the error, I am assuming the user had a previously working addon, so the key must have originally been entered in the OZW format, and after upgrading the addon it migrated it to the S0_Legacy option name, which doesn't allow OZW format keys.

Copy link
Collaborator

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@kpine kpine marked this pull request as ready for review September 30, 2021 00:20
@kpine
Copy link
Contributor Author

kpine commented Sep 30, 2021

Some rudimentary testing:

❯ cat opt1.js && ts-node src/bin/server.ts --config opt1.js --mock-driver
module.exports = {
  networkKey: "0x2e, 0xcc, 0xab, 0x1c, 0xa3, 0x7f, 0x0e, 0xb5, 0x70, 0x71, 0x2d, 0x98, 0x25, 0x43, 0xee, 0x0c"
};
The `networkKey` option is deprecated in favor of `securityKeys` option. To eliminate this warning, move your networkKey into the securityKeys.S0_Legacy option. Refer to the Z-Wave JS docs for more information
Starting server on port 3000
ZwaveJS server listening on port 3000
Server listening on port 3000
^CShutting down
Closing server...
Server closed

❯ cat opt2.js && ts-node src/bin/server.ts --config opt2.js --mock-driver
module.exports = {
  securityKeys: {
    S0_Legacy: "0x2e, 0xcc, 0xab, 0x1c, 0xa3, 0x7f, 0x0e, 0xb5, 0x70, 0x71, 0x2d, 0x98, 0x25, 0x43, 0xee, 0x0c",
    S2_Authenticated: "0x2e, 0xcc, 0xab, 0x1c, 0xa3, 0x7f, 0x0e, 0xb5, 0x70, 0x71, 0x2d, 0x98, 0x25, 0x43, 0xee, 0x0c",
    S2_AccessControl:  "0x2e, 0xcc, 0xab, 0x1c, 0xa3, 0x7f, 0x0e, 0xb5, 0x70, 0x71, 0x2d, 0x98, 0x25, 0x43, 0xee, 0x0c",
    S2_Unauthenticated: "0x2e, 0xcc, 0xab, 0x1c, 0xa3, 0x7f, 0x0e, 0xb5, 0x70, 0x71, 0x2d, 0x98, 0x25, 0x43, 0xee, 0x0c",
  },
};
Starting server on port 3000
ZwaveJS server listening on port 3000
Server listening on port 3000
^CShutting down
Closing server...
Server closed

❯ cat opt3.js && ts-node src/bin/server.ts --config opt3.js --mock-driver
module.exports = {
  securityKeys: {
    S2_Authenticated: "asdfasdfasdf",
  },
};
Error: failed loading config file /home/keith/src/zwave-js/zwave-js-server/opt3.js
Error: Invalid key format for securityKeys.S2_Authenticated option
    at normalizeKey (/home/keith/src/zwave-js/zwave-js-server/src/bin/server.ts:17:11)
    at /home/keith/src/zwave-js/zwave-js-server/src/bin/server.ts:60:53
    at Object.<anonymous> (/home/keith/src/zwave-js/zwave-js-server/src/bin/server.ts:119:3)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/home/keith/src/zwave-js/zwave-js-server/node_modules/ts-node/src/index.ts:1310:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/keith/src/zwave-js/zwave-js-server/node_modules/ts-node/src/index.ts:1313:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)

❯ cat opt4.js && ts-node src/bin/server.ts --config opt4.js --mock-driver
module.exports = {
  networkKey: "2eccab1ca37f0eb570712d982543ee0c"
};
The `networkKey` option is deprecated in favor of `securityKeys` option. To eliminate this warning, move your networkKey into the securityKeys.S0_Legacy option. Refer to the Z-Wave JS docs for more information
Starting server on port 3000
ZwaveJS server listening on port 3000
Server listening on port 3000
^CShutting down
Closing server...
Server closed

❯ cat opt5.js && ts-node src/bin/server.ts --config opt5.js --mock-driver
module.exports = {
  securityKeys: {
    S0_Legacy: "2eccab1ca37f0eb570712d982543ee0c",
    S2_Authenticated: "2eccab1ca37f0eb570712d982543ee0c",
    S2_AccessControl: "2eccab1ca37f0eb570712d982543ee0c",
    S2_Unauthenticated: "2eccab1ca37f0eb570712d982543ee0c",
  },
};
Starting server on port 3000
ZwaveJS server listening on port 3000
Server listening on port 3000
^CShutting down
Closing server...
Server closed

@balloob balloob merged commit a0e014e into zwave-js:master Sep 30, 2021
@kpine kpine deleted the s2-key-migration branch September 30, 2021 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants