Skip to content

Commit 8d2c172

Browse files
committed
Merge pull request arduino#428 from fallberg/signing
Add destination parameter to signingPresentation
2 parents 21f0e02 + 99084ec commit 8d2c172

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

libraries/MySensors/core/MySigning.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ void signerInit(void) {
129129
#endif
130130
}
131131

132-
void signerPresentation(MyMessage &msg) {
133-
prepareSigningPresentation(msg, GATEWAY_ADDRESS);
132+
void signerPresentation(MyMessage &msg, uint8_t destination) {
133+
prepareSigningPresentation(msg, destination);
134134

135135
#if defined(MY_SIGNING_REQUEST_SIGNATURES)
136136
msg.data[1] |= SIGNING_PRESENTATION_REQUIRE_SIGNATURES;
@@ -145,8 +145,10 @@ void signerPresentation(MyMessage &msg) {
145145

146146
#if defined(MY_SIGNING_FEATURE)
147147
// If we do support signing, wait for the gateway to tell us how it prefer us to transmit our messages
148-
SIGN_DEBUG(PSTR("Waiting for GW to send signing preferences...\n"));
149-
wait(2000);
148+
if (destination == GATEWAY_ADDRESS) {
149+
SIGN_DEBUG(PSTR("Waiting for GW to send signing preferences...\n"));
150+
wait(2000);
151+
}
150152
#endif
151153
}
152154

libraries/MySensors/core/MySigning.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
* Just set the flag @ref MY_SIGNING_REQUEST_SIGNATURES and the node will inform the gateway that it expects the gateway to sign all
158158
* messages sent to the node. If this is set in a gateway, it will @b NOT force all nodes to sign messages to it. It will only require
159159
* signatures from nodes that in turn require signatures.<br>
160+
* If you want to have two nodes communicate securely directly with each other, the nodes that require signatures must send a presentation
161+
* message to all nodes it expect signed messages from (only the gateway is informed automatically). See @ref signerPresentation().<br>
160162
* A node can have three "states" with respect to signing:
161163
* 1. Node does not support signing in any way (neither @ref MY_SIGNING_ATSHA204 nor @ref MY_SIGNING_SOFT is set)
162164
* 2. Node does support signing but don't require messages sent to it to be signed (@ref MY_SIGNING_REQUEST_SIGNATURES is not set)
@@ -506,14 +508,19 @@ void signerInit(void);
506508
/**
507509
* @brief Does signing specific presentation for a node.
508510
*
509-
* This function makes sure any signing related presentation info is shared with the gateway.
511+
* This function makes sure any signing related presentation info is shared with the other part.
510512
* The presentation of the gateways signing preferences is done in @ref signerProcessInternal().
511513
* \n@b Usage: This function should be called by the presentation routine of the mysensors library.
512-
* There is no need to call this directly from a sketch.
514+
* You only need to call this directly from a sketch to set up a node to node signed message exchange.
515+
* If you do call this directly from a sketch, and you at some point change your sketch to go from
516+
* requireing signing to not requireing signatures, you need to present this change to the node at least
517+
* once, so it can update its requirements tables accordingly. Or it will keep believing that this node
518+
* require signatures and attempt to send signed messages to it.
513519
*
514520
* @param msg Message buffer to use.
521+
* @param destination Node ID of the destination.
515522
*/
516-
void signerPresentation(MyMessage &msg);
523+
void signerPresentation(MyMessage &msg, uint8_t destination);
517524

518525
/**
519526
* @brief Manages internal signing message handshaking.

libraries/MySensors/core/MyTransport.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ void transportPresentNode() {
463463
#endif
464464
else
465465
if (_nc.nodeId != AUTO) {
466-
// Send signing preferences for this node
467-
signerPresentation(_msg);
466+
// Send signing preferences for this node to the GW
467+
signerPresentation(_msg, GATEWAY_ADDRESS);
468468

469469
// Send presentation for this radio node
470470
#ifdef MY_REPEATER_FEATURE

0 commit comments

Comments
 (0)