Make stability improvements in message signing

* Made delay waiting for GW to transmit signing preferences apply
  also if signing is disabled since nodes always sends a signing
  presentation, and GW always replies with it's own presentation.
  This can cause message collition if the node at the same time
  proceed with other presentation messages.

* Made the signing backend "consume" signing presentation
  messages sent by GW when signing is disabled. These messages
  should not be forwarded to the "user".
This commit is contained in:
Patrick Fallberg
2016-10-30 12:01:35 +01:00
parent 50eeb75b08
commit c47a83f1da
+12 -12
View File
@@ -148,33 +148,36 @@ void signerPresentation(MyMessage &msg, uint8_t destination) {
#endif #endif
if (!_sendRoute(msg)) { if (!_sendRoute(msg)) {
SIGN_DEBUG(PSTR("Failed to transmit signing presentation!")); SIGN_DEBUG(PSTR("Failed to transmit signing presentation!\n"));
} }
#if defined(MY_SIGNING_FEATURE)
// If we do support signing, wait for the gateway to tell us how it prefer us to transmit our messages
if (destination == GATEWAY_ADDRESS) { if (destination == GATEWAY_ADDRESS) {
SIGN_DEBUG(PSTR("Waiting for GW to send signing preferences...\n")); SIGN_DEBUG(PSTR("Waiting for GW to send signing preferences...\n"));
wait(2000, C_INTERNAL, I_SIGNING_PRESENTATION); wait(2000, C_INTERNAL, I_SIGNING_PRESENTATION);
} }
#endif
} }
bool signerProcessInternal(MyMessage &msg) { bool signerProcessInternal(MyMessage &msg) {
uint8_t sender = msg.sender; uint8_t sender = msg.sender;
(void)sender; (void)sender;
if (mGetCommand(msg) == C_INTERNAL) { #if !defined(MY_SIGNING_FEATURE)
#if !defined(MY_SIGNING_FEATURE) && defined(MY_GATEWAY_FEATURE) if (msg.type == I_SIGNING_PRESENTATION) {
#if defined(MY_GATEWAY_FEATURE)
// If we act as gateway and do not have the signing feature and receive a signing request we still // If we act as gateway and do not have the signing feature and receive a signing request we still
// need to do make sure the requester does not believe the gateway still require signatures // need to do make sure the requester does not believe the gateway still require signatures
if (msg.type == I_SIGNING_PRESENTATION) {
prepareSigningPresentation(msg, sender); prepareSigningPresentation(msg, sender);
SIGN_DEBUG(PSTR("Informing node %d that we do not require signatures because we do not support it\n"), SIGN_DEBUG(PSTR("Informing node %d that we do not require signatures because we do not support it\n"),
sender); sender);
if (!_sendRoute(msg)) { if (!_sendRoute(msg)) {
SIGN_DEBUG(PSTR("Failed to transmit signing presentation!")); SIGN_DEBUG(PSTR("Failed to transmit signing presentation!\n"));
} }
return true; // No need to further process I_SIGNING_PRESENTATION in this case return true; // No need to further process I_SIGNING_PRESENTATION in this case
#else
// If we act as a node and do not have the signing feature then we just silently drop any signing
// presentation messages received
SIGN_DEBUG(PSTR("Received signing presentation, but signing is not supported (message ignored)\n"));
return true;
#endif
} }
#elif defined(MY_SIGNING_FEATURE) #elif defined(MY_SIGNING_FEATURE)
if (msg.type == I_NONCE_REQUEST) { if (msg.type == I_NONCE_REQUEST) {
@@ -205,7 +208,6 @@ bool signerProcessInternal(MyMessage &msg) {
SIGN_DEBUG(PSTR("Unsupported signing presentation version (%d)!\n"), msg.data[0]); SIGN_DEBUG(PSTR("Unsupported signing presentation version (%d)!\n"), msg.data[0]);
return true; // Just drop this presentation message return true; // Just drop this presentation message
} }
// We only handle version 1 here... // We only handle version 1 here...
if (msg.data[1] & SIGNING_PRESENTATION_REQUIRE_SIGNATURES) { if (msg.data[1] & SIGNING_PRESENTATION_REQUIRE_SIGNATURES) {
// We received an indicator that the sender require us to sign all messages we send to it // We received an indicator that the sender require us to sign all messages we send to it
@@ -216,7 +218,6 @@ bool signerProcessInternal(MyMessage &msg) {
SIGN_DEBUG(PSTR("Mark node %d as one that do not require signed messages\n"), msg.sender); SIGN_DEBUG(PSTR("Mark node %d as one that do not require signed messages\n"), msg.sender);
CLEAR_SIGN(msg.sender); CLEAR_SIGN(msg.sender);
} }
if (msg.data[1] & SIGNING_PRESENTATION_REQUIRE_WHITELISTING) { if (msg.data[1] & SIGNING_PRESENTATION_REQUIRE_WHITELISTING) {
// We received an indicator that the sender require us to salt signatures with serial // We received an indicator that the sender require us to salt signatures with serial
SIGN_DEBUG(PSTR("Mark node %d as one that require whitelisting\n"), msg.sender); SIGN_DEBUG(PSTR("Mark node %d as one that require whitelisting\n"), msg.sender);
@@ -266,7 +267,7 @@ bool signerProcessInternal(MyMessage &msg) {
SIGN_DEBUG(PSTR("Informing node %d that we do not require whitelisting\n"), sender); SIGN_DEBUG(PSTR("Informing node %d that we do not require whitelisting\n"), sender);
} }
if (!_sendRoute(msg)) { if (!_sendRoute(msg)) {
SIGN_DEBUG(PSTR("Failed to transmit signing presentation!")); SIGN_DEBUG(PSTR("Failed to transmit signing presentation!\n"));
} }
#endif // MY_GATEWAY_FEATURE #endif // MY_GATEWAY_FEATURE
return true; // No need to further process I_SIGNING_PRESENTATION return true; // No need to further process I_SIGNING_PRESENTATION
@@ -299,7 +300,6 @@ bool signerProcessInternal(MyMessage &msg) {
return true; // No need to further process I_NONCE_RESPONSE return true; // No need to further process I_NONCE_RESPONSE
} }
#endif // MY_SIGNING_FEATURE #endif // MY_SIGNING_FEATURE
}
return false; return false;
} }