Signing related fixes
* Secure actuator example now require signed messages by default * Whitelisting config example in MyConfig.h now uses correct keywords * keywords.txt updated with the actual whitelisting keyword * Signing backends have improved debug output - The type of backend is presented in Get and Put nonce functions - The resulting signature is printed for both sender and receiver * Fixed bug in soft signer (the untransmitted part of the nonce buffer was not the same in both ends) * The ATSHA personalizer is updated to use acceptable syntax for user provided HMAC key
This commit is contained in:
@@ -211,7 +211,7 @@
|
||||
// Note that a node can still transmit a non-salted message (i.e. have white listing disabled)
|
||||
// to a node that has white listing enabled (assuming the receiver does not have a matching entry
|
||||
// for the sender in it's white list)
|
||||
//#define MY_SIGNING_NODE_WHITELIST {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
|
||||
//#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
|
||||
|
||||
// Atsha204 default pin setting
|
||||
#ifndef MY_SIGNING_ATSHA204_PIN
|
||||
|
||||
@@ -75,6 +75,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
|
||||
|
||||
|
||||
bool signerGetNonce(MyMessage &msg) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ATSHA204"));
|
||||
// Generate random number for use as nonce
|
||||
// We used a basic whitening technique that takes the first byte of a new random value and builds up a 32-byte random value
|
||||
// This 32-byte random value is then hashed (SHA256) to produce the resulting nonce
|
||||
@@ -119,6 +120,7 @@ bool signerCheckTimer() {
|
||||
}
|
||||
|
||||
bool signerPutNonce(MyMessage &msg) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ATSHA204"));
|
||||
if (((uint8_t*)msg.getCustom())[0] != SIGNING_IDENTIFIER) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ISI")); // ISI = Incorrect signing identifier
|
||||
return false;
|
||||
@@ -155,6 +157,7 @@ bool signerSignMsg(MyMessage &msg) {
|
||||
|
||||
// Transfer as much signature data as the remaining space in the message permits
|
||||
memcpy(&msg.data[mGetLength(msg)], &_singning_rx_buffer[SHA204_BUFFER_POS_DATA], MAX_PAYLOAD-mGetLength(msg));
|
||||
DEBUG_SIGNING_PRINTBUF(F("SIM:"), (uint8_t*)&msg.data[mGetLength(msg)], MAX_PAYLOAD-mGetLength(msg)); // SIM = Signature in message
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
|
||||
|
||||
|
||||
bool signerGetNonce(MyMessage &msg) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ATSHA204Soft"));
|
||||
// Set randomseed
|
||||
randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
|
||||
|
||||
@@ -121,12 +122,15 @@ bool signerCheckTimer() {
|
||||
}
|
||||
|
||||
bool signerPutNonce(MyMessage &msg) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ATSHA204Soft"));
|
||||
if (((uint8_t*)msg.getCustom())[0] != SIGNING_IDENTIFIER) {
|
||||
DEBUG_SIGNING_PRINTLN(F("ISI")); // ISI = Incorrect signing identifier
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(_signing_current_nonce, (uint8_t*)msg.getCustom(), MAX_PAYLOAD);
|
||||
// We set the part of the 32-byte nonce that does not fit into a message to 0xAA
|
||||
memset(&_signing_current_nonce[MAX_PAYLOAD], 0xAA, sizeof(_signing_current_nonce)-MAX_PAYLOAD);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -156,6 +160,7 @@ bool signerSignMsg(MyMessage &msg) {
|
||||
|
||||
// Transfer as much signature data as the remaining space in the message permits
|
||||
memcpy(&msg.data[mGetLength(msg)], _signing_hmac, MAX_PAYLOAD-mGetLength(msg));
|
||||
DEBUG_SIGNING_PRINTBUF(F("SIM:"), (uint8_t*)&msg.data[mGetLength(msg)], MAX_PAYLOAD-mGetLength(msg)); // SIM = Signature in message
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@
|
||||
// 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. Default is not to require signing.
|
||||
//#define MY_SIGNING_REQUEST_SIGNATURES
|
||||
#define MY_SIGNING_REQUEST_SIGNATURES
|
||||
|
||||
|
||||
// SETTINGS FOR MY_SIGNING_SOFT
|
||||
// Set the soft_serial value to an arbitrary value for proper security (9 bytes)
|
||||
#define MY_SIGNING_SOFT_SERIAL 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09
|
||||
#define MY_SIGNING_SOFT_SERIAL 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09
|
||||
// Key to use for HMAC calculation in soft signing (32 bytes)
|
||||
#define MY_SIGNING_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
|
||||
|
||||
@@ -80,8 +80,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef USER_KEY_DATA
|
||||
#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
const uint8_t user_key_data[32] = {MY_HMAC_KEY};
|
||||
#endif
|
||||
|
||||
@@ -877,7 +876,6 @@ void setup()
|
||||
}
|
||||
Serial.print(key[i], HEX);
|
||||
if (i < 31) Serial.print(',');
|
||||
if (i+1 == 16) Serial.print("\\\n ");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ MY_INCLUSION_MODE_DURATION LITERAL1
|
||||
MY_SIGNING_ATSHA204 LITERAL1
|
||||
MY_SIGNING_SOFT LITERAL1
|
||||
MY_VERIFICATION_TIMEOUT_MS LITERAL1
|
||||
MY_SIGNING_NODE_WHITELIST LITERAL1
|
||||
MY_SIGNING_NODE_WHITELISTING LITERAL1
|
||||
MY_SIGNING_ATSHA204_PIN LITERAL1
|
||||
MY_SIGNING_SOFT_RANDOMSEED_PIN LITERAL1
|
||||
MY_SIGNING_SOFT_SERIAL LITERAL1
|
||||
|
||||
Reference in New Issue
Block a user