Skip to content

Commit b0ef810

Browse files
committed
Merge pull request #336 from fallberg/master-patches
Security related patches
2 parents 9ef2604 + 29a5bfb commit b0ef810

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
#ifdef MY_SIGNING_FEATURE
2626
// Macros for manipulating signing requirement table
27-
#define DO_SIGN(node) (node == 0 ? (~doSign[0]&1) : (~doSign[node>>4]&(node%16)))
28-
#define SET_SIGN(node) (node == 0 ? (doSign[0]&=~1) : (doSign[node>>4]&=~(node%16)))
29-
#define CLEAR_SIGN(node) (node == 0 ? (doSign[0]|=1) : (doSign[node>>4]|=(node%16)))
27+
#define DO_SIGN(node) (~_doSign[node>>3]&(1<<(node%8)))
28+
#define SET_SIGN(node) (_doSign[node>>3]&=~(1<<(node%8)))
29+
#define CLEAR_SIGN(node) (_doSign[node>>3]|=(1<<(node%8)))
3030
#endif
3131

3232
// Inline function and macros
@@ -268,6 +268,9 @@ void MySensor::setupNode() {
268268
if (signer.requestSignatures()) {
269269
wait(2000);
270270
}
271+
#else
272+
// We do not support signing, make sure gateway knows this
273+
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_REQUEST_SIGNING, false).set(false));
271274
#endif
272275

273276
// Send presentation for this radio node (attach
@@ -393,7 +396,9 @@ boolean MySensor::sendRoute(MyMessage &message) {
393396
}
394397
// After this point, only the 'last' member of the message structure is allowed to be altered if the message has been signed,
395398
// or signature will become invalid and the message rejected by the receiver
396-
} else mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned
399+
} else if (nc.nodeId == message.sender) {
400+
mSetSigned(message, 0); // Message is not supposed to be signed, make sure it is marked unsigned
401+
}
397402
#endif
398403

399404
if (dest == GATEWAY_ADDRESS || !repeaterMode) {
@@ -585,11 +590,18 @@ boolean MySensor::process() {
585590
}
586591
#endif
587592

588-
// Add string termination, good if we later would want to print it.
589-
msg.data[mGetLength(msg)] = '\0';
590-
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
593+
if (msg.destination == nc.nodeId) {
594+
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
595+
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
596+
} else {
597+
if (repeaterMode && nc.nodeId != AUTO) {
598+
debug(PSTR("read and forward: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
599+
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
600+
} else {
601+
debug(PSTR("read and drop: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"),
591602
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), mGetSigned(msg), msg.getString(convBuf));
592-
mSetSigned(msg,0); // Clear the sign-flag now as verification (and debug printing) is completed
603+
}
604+
}
593605

594606
if(!(mGetVersion(msg) == PROTOCOL_VERSION)) {
595607
debug(PSTR("ver mismatch\n"));
@@ -607,6 +619,7 @@ boolean MySensor::process() {
607619

608620
if (destination == nc.nodeId) {
609621
// This message is addressed to this node
622+
mSetSigned(msg,0);
610623

611624
if (repeaterMode && last != nc.parentNodeId) {
612625
// Message is from one of the child nodes. Add it to routing table.

libraries/MySensors/MySensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class MySensor
366366

367367
MyTransport& radio;
368368
#ifdef MY_SIGNING_FEATURE
369-
uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication
369+
uint8_t doSign[32]; // Bitfield indicating which sensors require signed communication
370370
MyMessage msgSign; // Buffer for message to sign.
371371
MySigning& signer;
372372
#endif

libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void setup()
7575
digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
7676

7777
// Send the sketch version information to the gateway and Controller
78-
sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER"."SKETCH_MINOR_VER);
78+
sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
7979

8080
// Register binary input sensor to sensor_node (they will be created as child devices)
8181
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.

libraries/MySensors/examples/SecureActuator/SecureActuator.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void loop()
102102

103103
void incomingMessage(const MyMessage &message) {
104104
// We only expect one type of message from controller. But we better check anyway.
105-
if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS) {
105+
// And acks are not accepted as control messages
106+
if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS && !mGetAck(message)) {
106107
// Change relay state
107108
digitalWrite(message.sensor-1+LOCK_1, message.getBool()?LOCK_LOCK:LOCK_UNLOCK);
108109
// Store state in eeprom

0 commit comments

Comments
 (0)