* Signing support with MAX_PAYLOAD>32 Support in the signing backends to handle configurations where MAX_PAYLOAD is more than 32 bytes. Fixes #748 * Support big message signatures Support for signing messages larger than 32 bytes. This is not fully testable with the current version of the library but the change would add theoretical support for signing any sized messages. Fixes #749 * Have gw properly indicate whitelisting preferences If the gateway hold a signing whitelist, inform all nodes of this requirement and not just nodes that hold whitelists themselves. Fixes #806 * Harden security The flag MY_SIGNING_GW_REQUEST_SIGNATURES_FROM_ALL has been removed. Gateway will now request signatures from everyone by default. In addition to this, no nodes in the network will allow clearing of signing/whitelisting preferences by OTA commands by default. If the old behaviour is needed (suitable for gradual signing roll out and development purposes) a new flag, MY_SIGNING_WEAK_SECURITY can be set. Fixes #807 * Signing debug messages rewritten All signing related debug has been rewritten to better match other core debug printouts. Also, backends are updated to have a smaller implementation delta. * Simplified signing option implemented Enable by MY_SIGNING_SIMPLE_PASSWD. Signing, and signing requirements will be enabled, as will encryption. Whitelisting is optional. The value provided to MY_SIGNING_SIMPLE_PASSWD is used as HMAC and AES key. Whitelists use the first 8 bytes of the password and the ninth byte from the node ID as serial. Password is required to be at least 8 characters wide. It is zero padded if it is not long enough to cover the AES (16 bytes) and HMAC (32 bytes) keys. It is not recommended to have a password shorter than 32 bytes, and there is no need for a password longer than 32 bytes. * Add documentation section for signing debug * Add nRF5 encryption to simple signing option * Restructure MySigning documentation * Minor fixes for Linux
127 lines
4.6 KiB
Arduino
127 lines
4.6 KiB
Arduino
/*
|
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
|
* between your home built sensors/actuators and HA controller of choice.
|
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
|
* network topology allowing messages to be routed to nodes.
|
|
*
|
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
|
* Copyright (C) 2013-2015 Sensnology AB
|
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
|
*
|
|
* Documentation: http://www.mysensors.org
|
|
* Support Forum: http://forum.mysensors.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* version 2 as published by the Free Software Foundation.
|
|
*
|
|
*******************************
|
|
*/
|
|
/**
|
|
* @ingroup MySigninggrp
|
|
* @{
|
|
* @file SecureActuator.ino
|
|
* @brief Example sketch showing how to securely control locks.
|
|
*
|
|
* This example will remember lock state even after power failure.
|
|
*
|
|
* REVISION HISTORY
|
|
* - See git log (git log libraries/MySensors/examples/SecureActuator/SecureActuator.ino)
|
|
*/
|
|
|
|
/**
|
|
* @example SecureActuator.ino
|
|
* This example implements a secure actuator in the form of a IO controlled electrical lock.<br>
|
|
* Multiple locks are supported as long as they are on subsequent IO pin indices. The first lock pin
|
|
* is defined by @ref LOCK_1. The number of locks is controlled by @ref NOF_LOCKS .<br>
|
|
* The sketch will require incoming messages to be signed and the use of signing backend is selected
|
|
* by @ref MY_SIGNING_ATSHA204 or @ref MY_SIGNING_SOFT. Hard or soft ATSHA204 signing is supported.<br>
|
|
* Whitelisting can be enabled through @ref MY_SIGNING_NODE_WHITELISTING in which case a single entry
|
|
* is provided in this example which typically should map to the gateway of the network.
|
|
*/
|
|
|
|
#define MY_DEBUG //!< Enable debug prints to serial monitor
|
|
#define MY_DEBUG_VERBOSE_SIGNING //!< Enable signing related debug prints to serial monitor
|
|
#define MY_NODE_LOCK_FEATURE //!< Enable lockdown of node if suspicious activity is detected
|
|
|
|
// Enable and select radio type attached
|
|
#define MY_RADIO_NRF24 //!< NRF24L01 radio driver
|
|
//#define MY_RADIO_RFM69 //!< RFM69 radio driver
|
|
|
|
// Select soft/hardware signing method
|
|
#define MY_SIGNING_SOFT //!< Software signing
|
|
//#define MY_SIGNING_ATSHA204 //!< Hardware signing using ATSHA204A
|
|
|
|
// Enable node whitelisting
|
|
//#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
|
|
// Enable this if you want destination node to sign all messages sent to this node.
|
|
#define MY_SIGNING_REQUEST_SIGNATURES
|
|
|
|
|
|
// SETTINGS FOR MY_SIGNING_SOFT
|
|
#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 //!< Unconnected analog pin for random seed
|
|
|
|
// SETTINGS FOR MY_SIGNING_ATSHA204
|
|
#ifndef MY_SIGNING_ATSHA204_PIN
|
|
#define MY_SIGNING_ATSHA204_PIN 17 //!< A3 - pin where ATSHA204 is attached
|
|
#endif
|
|
|
|
#include <MySensors.h>
|
|
|
|
|
|
#define LOCK_1 3 //!< Arduino Digital I/O pin number for first lock (second on pin+1 etc)
|
|
#define NOF_LOCKS 1 //!< Total number of attached locks
|
|
#define LOCK_LOCK 1 //!< GPIO value to write to lock attached lock
|
|
#define LOCK_UNLOCK 0 //!< GPIO value to write to unlock attached lock
|
|
|
|
void setup()
|
|
{
|
|
for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
|
|
// Set lock pins in output mode
|
|
pinMode(pin, OUTPUT);
|
|
// Set lock to last known state (using eeprom storage)
|
|
digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK);
|
|
}
|
|
}
|
|
|
|
void presentation()
|
|
{
|
|
// Send the sketch version information to the gateway and Controller
|
|
sendSketchInfo("Secure Lock", "1.0");
|
|
|
|
// Fetch lock status
|
|
for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
|
|
// Register all locks to gw (they will be created as child devices)
|
|
present(lock, S_LOCK, "SecureActuator", false);
|
|
}
|
|
}
|
|
|
|
/** @brief Sketch execution code */
|
|
void loop()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief Incoming message handler
|
|
*
|
|
* @param message The message to handle.
|
|
*/
|
|
void receive(const MyMessage &message)
|
|
{
|
|
// We only expect one type of message from controller. But we better check anyway.
|
|
// And acks are not accepted as control messages
|
|
if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS && !mGetAck(message)) {
|
|
// Change relay state
|
|
digitalWrite(message.sensor-1+LOCK_1, message.getBool()?LOCK_LOCK:LOCK_UNLOCK);
|
|
// Store state in eeprom
|
|
saveState(message.sensor, message.getBool());
|
|
// Write some debug info
|
|
Serial.print("Incoming change for lock:");
|
|
Serial.print(message.sensor);
|
|
Serial.print(", New status: ");
|
|
Serial.println(message.getBool());
|
|
}
|
|
}
|
|
/** @}*/
|