Merge pull request #79 from fallberg/development
Fixed bug that caused the wrong message to be signed
This commit is contained in:
@@ -349,12 +349,12 @@ boolean MySensor::process() {
|
|||||||
// Check if sender requests an ack back.
|
// Check if sender requests an ack back.
|
||||||
if (mGetRequestAck(msg)) {
|
if (mGetRequestAck(msg)) {
|
||||||
// Copy message
|
// Copy message
|
||||||
ack = msg;
|
tmpMsg = msg;
|
||||||
mSetRequestAck(ack,false); // Reply without ack flag (otherwise we would end up in an eternal loop)
|
mSetRequestAck(tmpMsg,false); // Reply without ack flag (otherwise we would end up in an eternal loop)
|
||||||
mSetAck(ack,true);
|
mSetAck(tmpMsg,true);
|
||||||
ack.sender = nc.nodeId;
|
tmpMsg.sender = nc.nodeId;
|
||||||
ack.destination = msg.sender;
|
tmpMsg.destination = msg.sender;
|
||||||
sendRoute(ack);
|
sendRoute(tmpMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == C_INTERNAL) {
|
if (command == C_INTERNAL) {
|
||||||
@@ -591,18 +591,21 @@ int8_t MySensor::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MySensor::sign(MyMessage &message) {
|
bool MySensor::sign(MyMessage &message) {
|
||||||
MyMessage msgNonce;
|
if (!sendRoute(build(tmpMsg, nc.nodeId, message.destination, message.sensor, C_INTERNAL, I_GET_NONCE, false).set(""))) {
|
||||||
if (!sendRoute(build(msgNonce, nc.nodeId, message.destination, message.sensor, C_INTERNAL, I_GET_NONCE, false).set(""))) {
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// We have to wait for the nonce to arrive before we can sign our original message
|
// We have to wait for the nonce to arrive before we can sign our original message
|
||||||
// Other messages could come in-between. We trust process() takes care of them
|
// Other messages could come in-between. We trust process() takes care of them
|
||||||
unsigned long enter = millis();
|
unsigned long enter = millis();
|
||||||
|
msgSign = message; // Copy the message to sign since message buffer might be touched in process()
|
||||||
while (millis() - enter < 5000) {
|
while (millis() - enter < 5000) {
|
||||||
if (process()) {
|
if (process()) {
|
||||||
if (getLastMessage().type == I_GET_NONCE_RESPONSE) {
|
if (mGetCommand(getLastMessage()) == C_INTERNAL && getLastMessage().type == I_GET_NONCE_RESPONSE) {
|
||||||
// Proceed with signing if nonce has been received
|
// Proceed with signing if nonce has been received
|
||||||
if (signer.putNonce(getLastMessage()) && signer.signMsg(message)) return true;
|
if (signer.putNonce(getLastMessage()) && signer.signMsg(msgSign)) {
|
||||||
|
message = msgSign; // Write the signed message back
|
||||||
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ class MySensor
|
|||||||
uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication
|
uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication
|
||||||
|
|
||||||
MyMessage msg; // Buffer for incoming messages.
|
MyMessage msg; // Buffer for incoming messages.
|
||||||
MyMessage ack; // Buffer for ack messages.
|
MyMessage tmpMsg ; // Buffer for temporary messages (acks and nonces among others).
|
||||||
|
MyMessage msgSign; // Buffer for message to sign.
|
||||||
|
|
||||||
MyRFDriverClass radio;
|
MyRFDriverClass radio;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user