From 3bf9184670583f695f4062d402f5a088079526da Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Sun, 3 Jan 2016 20:51:40 +0100 Subject: [PATCH] Removed signing identifier from nonces It serves no practical use to have signing identifier in nonces as nonces are architecture independent. Fixes #318 --- libraries/MySensors/core/MySigning.cpp | 13 ++++++------- libraries/MySensors/core/MySigningAtsha204.cpp | 10 +--------- libraries/MySensors/core/MySigningAtsha204Soft.cpp | 10 +--------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/libraries/MySensors/core/MySigning.cpp b/libraries/MySensors/core/MySigning.cpp index 2d0225c..1202474 100644 --- a/libraries/MySensors/core/MySigning.cpp +++ b/libraries/MySensors/core/MySigning.cpp @@ -59,14 +59,14 @@ enum { SIGN_WAITING_FOR_NONCE = 0, SIGN_OK = 1 }; #if defined(MY_SIGNING_SOFT) extern bool signerAtsha204SoftCheckTimer(void); extern bool signerAtsha204SoftGetNonce(MyMessage &msg); -extern bool signerAtsha204SoftPutNonce(MyMessage &msg); +extern void signerAtsha204SoftPutNonce(MyMessage &msg); extern bool signerAtsha204SoftVerifyMsg(MyMessage &msg); extern bool signerAtsha204SoftSignMsg(MyMessage &msg); #endif #if defined(MY_SIGNING_ATSHA204) extern bool signerAtsha204CheckTimer(void); extern bool signerAtsha204GetNonce(MyMessage &msg); -extern bool signerAtsha204PutNonce(MyMessage &msg); +extern void signerAtsha204PutNonce(MyMessage &msg); extern bool signerAtsha204VerifyMsg(MyMessage &msg); extern bool signerAtsha204SignMsg(MyMessage &msg); #endif @@ -240,17 +240,16 @@ bool signerProcessInternal(MyMessage &msg) { return true; // No need to further process I_NONCE_RESPONSE } #if defined(MY_SIGNING_SOFT) - if (!signerAtsha204SoftPutNonce(msg)) { + signerAtsha204SoftPutNonce(msg); #endif #if defined(MY_SIGNING_ATSHA204) - if (!signerAtsha204PutNonce(msg)) { + signerAtsha204PutNonce(msg); #endif - SIGN_DEBUG(PSTR("Failed to store nonce to signing backend!\n")); #if defined(MY_SIGNING_SOFT) - } else if (!signerAtsha204SoftSignMsg(_msgSign)) { + if (!signerAtsha204SoftSignMsg(_msgSign)) { #endif #if defined(MY_SIGNING_ATSHA204) - } else if (!signerAtsha204SignMsg(_msgSign)) { + if (!signerAtsha204SignMsg(_msgSign)) { #endif SIGN_DEBUG(PSTR("Failed to sign message!\n")); } else { diff --git a/libraries/MySensors/core/MySigningAtsha204.cpp b/libraries/MySensors/core/MySigningAtsha204.cpp index b5ac3ca..ce78678 100644 --- a/libraries/MySensors/core/MySigningAtsha204.cpp +++ b/libraries/MySensors/core/MySigningAtsha204.cpp @@ -117,9 +117,6 @@ bool signerAtsha204GetNonce(MyMessage &msg) { // 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); - // Replace the first byte in the nonce with our signing identifier - _signing_current_nonce[0] = SIGNING_IDENTIFIER; - // Transfer the first part of the nonce to the message msg.set(_signing_current_nonce, MAX_PAYLOAD); _signing_verification_ongoing = true; @@ -131,17 +128,12 @@ bool signerAtsha204GetNonce(MyMessage &msg) { return true; } -bool signerAtsha204PutNonce(MyMessage &msg) { +void signerAtsha204PutNonce(MyMessage &msg) { DEBUG_SIGNING_PRINTBUF(F("Signing backend: ATSHA204"), NULL, 0); - if (((uint8_t*)msg.getCustom())[0] != SIGNING_IDENTIFIER) { - DEBUG_SIGNING_PRINTBUF(F("Incorrect signing identifier"), NULL, 0); - 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; } bool signerAtsha204SignMsg(MyMessage &msg) { diff --git a/libraries/MySensors/core/MySigningAtsha204Soft.cpp b/libraries/MySensors/core/MySigningAtsha204Soft.cpp index 2940d09..2b89fac 100644 --- a/libraries/MySensors/core/MySigningAtsha204Soft.cpp +++ b/libraries/MySensors/core/MySigningAtsha204Soft.cpp @@ -117,9 +117,6 @@ bool signerAtsha204SoftGetNonce(MyMessage &msg) { // 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); - // Replace the first byte in the nonce with our signing identifier - _signing_current_nonce[0] = SIGNING_IDENTIFIER; - // Transfer the first part of the nonce to the message msg.set(_signing_current_nonce, MAX_PAYLOAD); _signing_verification_ongoing = true; @@ -131,17 +128,12 @@ bool signerAtsha204SoftGetNonce(MyMessage &msg) { return true; } -bool signerAtsha204SoftPutNonce(MyMessage &msg) { +void signerAtsha204SoftPutNonce(MyMessage &msg) { DEBUG_SIGNING_PRINTBUF(F("Signing backend: ATSHA204Soft"), NULL, 0); - if (((uint8_t*)msg.getCustom())[0] != SIGNING_IDENTIFIER) { - DEBUG_SIGNING_PRINTBUF(F("Incorrect signing identifier"), NULL, 0); - 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; } bool signerAtsha204SoftSignMsg(MyMessage &msg) {