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

fix: always use S2 for endpoint communication if node uses S2 #5310

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,10 +2053,28 @@ protocol version: ${this.protocolVersion}`;
const endpoint = this.getEndpoint(endpointIndex);
if (!endpoint) continue;

// Always interview Security first because it changes the interview order
// The root endpoint has been interviewed, so we know if the device supports security and which security classes it has
const securityClass = this.getHighestSecurityClass();

// From the specs, Multi Channel Capability Report Command:
// Non-secure End Point capabilities MUST also be supported securely and MUST also be advertised in
// the S0/S2 Commands Supported Report Commands unless they are encapsulated outside Security or
// Security themselves.
// Nodes supporting S2 MUST support addressing every End Point with S2 encapsulation and MAY
// explicitly list S2 in the non-secure End Point capabilities.

// This means we need to explicitly add S2 to the list of supported CCs of the endpoint, if the node is using S2.
// Otherwise the communication will incorrectly use no encryption.
const endpointMissingS2 =
securityClassIsS2(securityClass) &&
this.supportsCC(CommandClasses["Security 2"]) &&
!endpoint.supportsCC(CommandClasses["Security 2"]);
if (endpointMissingS2) {
endpoint.addCC(CommandClasses["Security 2"], { secure: true });
}

// Always interview Security first because it changes the interview order

if (endpoint.supportsCC(CommandClasses["Security 2"])) {
// Security S2 is always supported *securely*
endpoint.addCC(CommandClasses["Security 2"], { secure: true });
Expand Down