Skip to content

Commit

Permalink
feat: add support for SecurityCCCommandEncapsulationNonceGet
Browse files Browse the repository at this point in the history
fixes: #835
  • Loading branch information
AlCalzone committed Jun 2, 2020
1 parent 59c1b42 commit 6fbfaa9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## __WORK IN PROGRESS__
### Features
* Added support for `Protection CC`
* The driver now sends a nonce in reply to `SecurityCCCommandEncapsulationNonceGet` commands

### Bugfixes
* Nodes that ask for a CC are now automatically marked secure
Expand Down
18 changes: 14 additions & 4 deletions src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
} from "../commandclass/ICommandClassContainer";
import { MultiChannelCC } from "../commandclass/MultiChannelCC";
import { messageIsPing } from "../commandclass/NoOperationCC";
import { SecurityCC } from "../commandclass/SecurityCC";
import {
SecurityCC,
SecurityCCCommandEncapsulationNonceGet,
} from "../commandclass/SecurityCC";
import {
SupervisionCC,
SupervisionCCGet,
Expand Down Expand Up @@ -1225,9 +1228,16 @@ It is probably asleep, moving its messages to the wakeup queue.`,
* @param msg The decoded message
*/
private async handleMessage(msg: Message): Promise<void> {
// Assemble partial CCs on the driver level
if (isCommandClassContainer(msg) && !this.assemblePartialCCs(msg)) {
return;
if (isCommandClassContainer(msg)) {
// SecurityCCCommandEncapsulationNonceGet is two commands in one, but
// we're not set up to handle things like this. Reply to the nonce get
// and handle the encapsulation part normally
if (msg.command instanceof SecurityCCCommandEncapsulationNonceGet) {
void msg.getNodeUnsafe()?.handleSecurityNonceGet();
}

// Assemble partial CCs on the driver level
if (!this.assemblePartialCCs(msg)) return;
}

// if we have a pending request, check if that is waiting for this message
Expand Down
7 changes: 5 additions & 2 deletions src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,11 @@ version: ${this.version}`;

private hasLoggedNoNetworkKey = false;

/** Handles a nonce request */
private async handleSecurityNonceGet(): Promise<void> {
/**
* @internal
* Handles a nonce request
*/
public async handleSecurityNonceGet(): Promise<void> {
// Only reply if secure communication is set up
if (!this.driver.securityManager) {
if (!this.hasLoggedNoNetworkKey) {
Expand Down

0 comments on commit 6fbfaa9

Please sign in to comment.