Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MySigning.h 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. */
  19. /**
  20. * @defgroup MySigninggrpPub Message signing
  21. * @ingroup publics
  22. * @{
  23. *
  24. * @brief The message signing infrastructure provides message authenticity to users by signing
  25. * MySensors messages.
  26. *
  27. * Signing support created by Patrick "Anticimex" Fallberg.
  28. *
  29. * @section MySigninggrptoc Table of contents
  30. *
  31. * @ref MySigninggrphowuse <br>
  32. * @ref MySigningwhitelisting <br>
  33. * @ref MySigninglimitations <br>
  34. * @ref MySigningusecases <br>
  35. * @ref MySigningtechnical <br>
  36. * @ref MySigninggrpbackground <br>
  37. * @ref MySigninggrphow <br>
  38. * @ref MySigninggrpencryption <br>
  39. *
  40. * @section MySigninggrphowuse How to use this
  41. *
  42. * Before we begin with the details, I just want to emphasize that signing is completely optional
  43. * and not enabled by default.
  44. *
  45. * If you do want the additional security layer signing provides, you pick the backend of your
  46. * choice in your sketch. Currently, two compatible backends are supported; @ref MY_SIGNING_ATSHA204
  47. * (hardware backed) and @ref MY_SIGNING_SOFT (software backed). There also exist a simplified
  48. * variant (@ref MY_SIGNING_SIMPLE_PASSWD) of the software backend which only require one setting
  49. * to activate.
  50. *
  51. * If you use hardware backed signing, then connect the device as follows:
  52. * @image html MySigning/wiring.png
  53. * @note The pull-up resistor is optional but recommended.
  54. * @note If you change the default pin (A3) make sure you use a pin that supports input/output
  55. * (ex. A6 & A7 on a Pro Mini are input only pins).
  56. *
  57. * To use signing, you need to perform three major steps which are described below.
  58. *
  59. * <b>Firstly</b>, you need to make sure to pick a backend to use.
  60. * @code{.cpp}
  61. * //#define MY_SIGNING_SOFT
  62. * //#define MY_SIGNING_SIMPLE_PASSWD
  63. * #define MY_SIGNING_ATSHA204
  64. * #include <MySensors.h>
  65. * ...
  66. * @endcode
  67. * Make sure to set the define before the inclusion of MySensors.h.
  68. * It is ok to mix @ref MY_SIGNING_SOFT and @ref MY_SIGNING_ATSHA204 in a network.
  69. * They are fully compatible. It is however not recommended to use @ref MY_SIGNING_SOFT on nodes
  70. * that are publicly accessible (more on that later).
  71. *
  72. * If you use @ref MY_SIGNING_SOFT or @ref MY_SIGNING_ATSHA204 you also need to decide if the node
  73. * (or gateway) in question require messages to be signed in addition to the ability to generate
  74. * signatures for other nodes.
  75. * This has to be set by at least one of the nodes in a "pair" or nobody will actually start
  76. * calculating a signature for a message.
  77. * Just set the flag @ref MY_SIGNING_REQUEST_SIGNATURES and the node will inform the gateway that it
  78. * expects the gateway to sign all messages sent to the node. Note that when set in a gateway, the
  79. * gateway will require ALL nodes in the network to sign messages.
  80. * If this behaviour is undesired, enable the flag @ref MY_SIGNING_WEAK_SECURITY which will allow
  81. * the gateway to only require signatures from nodes that in turn require signatures. It will also
  82. * allow the gateway (and all nodes) to "downgrade" security by clearing the signing/whitelisting
  83. * requirements (whitelisting is described later on in the @ref MySigningwhitelisting section) in
  84. * the EEPROM if a node presents itself as not having any security requirements.
  85. * If @ref MY_SIGNING_WEAK_SECURITY is not set, any node that has presented itself with
  86. * signing/whitelisting requirements will be permanently marked as such by the receiver
  87. * (typically the gateway). The only way then to reset/revert this requirement is to clear the
  88. * EEPROM at the receiver (or disable @ref MY_SIGNING_REQUEST_SIGNATURES, but the preference will be
  89. * remembered if the request flag is re-enabled before EEPROM is cleared).<br>
  90. * If you want to have two nodes communicate securely directly with each other, the nodes that
  91. * require signatures must send a presentation message to all nodes it expect signed messages from
  92. * (only the gateway is informed automatically). See @ref signerPresentation().<br>
  93. * A node can have three "states" with respect to signing:
  94. * 1. Node does not support signing in any way (neither @ref MY_SIGNING_ATSHA204,
  95. * @ref MY_SIGNING_SOFT nor @ref MY_SIGNING_SIMPLE_PASSWD is set)
  96. * 2. Node does support signing but don't require messages sent to it to be signed (neither
  97. * @ref MY_SIGNING_REQUEST_SIGNATURES nor @ref MY_SIGNING_SIMPLE_PASSWD is set)
  98. * 3. Node does support signing and require messages sent to it to be signed (@ref
  99. * MY_SIGNING_SOFT or @ref MY_SIGNING_ATSHA204 together with @ref MY_SIGNING_REQUEST_SIGNATURES or
  100. * @ref MY_SIGNING_SIMPLE_PASSWD are set)
  101. *
  102. * <b>Secondly</b>, you need to verify the configuration for the backend.<br>
  103. * For hardware backed signing it is the pin the device is connected to. In MyConfig.h there are
  104. * defaults which you might need to adjust to match your personal build. The setting is defined
  105. * using @ref MY_SIGNING_ATSHA204_PIN.<br>
  106. * If you use an official MySensors board (like the SenseBender GW) you do not need to set the pin,
  107. * this is configured automatically by the Arduino board definition files.
  108. *
  109. * Similar to picking your backend, this can also be set in your sketch:
  110. * @code{.cpp}
  111. * #define MY_SIGNING_ATSHA204
  112. * #define MY_SIGNING_ATSHA204_PIN 4
  113. * #define MY_SIGNING_REQUEST_SIGNATURES
  114. * #include <MySensors.h>
  115. * ...
  116. * @endcode
  117. * For the software backed signing backend, an unconnected analog pin is required on boards that
  118. * does not provide a hardware based random generator unit to set a random seed for the
  119. * pseudo-random generator.
  120. * It is important that the pin is floating, or the output of the pseudo-random generator will be
  121. * predictable, and thus compromise the signatures. The setting is defined using
  122. * @ref MY_SIGNING_SOFT_RANDOMSEED_PIN. The same configuration possibilities exist as with the other
  123. * configuration options.
  124. *
  125. * @code{.cpp}
  126. * #define MY_SIGNING_SOFT
  127. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  128. * #define MY_SIGNING_REQUEST_SIGNATURES
  129. * #include <MySensors.h>
  130. * ...
  131. * @endcode
  132. *
  133. * An example of a node that require signatures is available in @ref SecureActuator.ino.
  134. *
  135. * <b>Thirdly</b>, if you use a signing backend and you don't use @ref MY_SIGNING_SIMPLE_PASSWD, you
  136. * need to personalize the node.
  137. *
  138. * @anchor personalization If you use the ATSHA204A (@ref MY_SIGNING_ATSHA204), before any signing
  139. * operations can be done, the device needs to be <i>personalized</i>.
  140. * This can be a daunting process as it involves irreversibly writing configurations to the device,
  141. * which cannot be undone. I have however tried to simplify the process as much as possibly by
  142. * creating a helper-sketch specifically for this purpose in @ref SecurityPersonalizer.ino
  143. * Note that you also need to do personalization for @ref MY_SIGNING_SOFT, but then the values are
  144. * stored in EEPROM.
  145. *
  146. * To personalize a ATSHA204A do the following procedure:
  147. * 1. Enable @ref GENERATE_KEYS_ATSHA204A<br>
  148. * This will lock the ATSHA204A and generate random keys for HMAC (signing) and %AES (encryption).
  149. * Copy the keys generated and replace the corresponding definitions under
  150. * "User defined key data", specifically @ref MY_HMAC_KEY and @ref MY_AES_KEY.
  151. * 2. Disable @ref GENERATE_KEYS_ATSHA204A and enable @ref PERSONALIZE_ATSHA204A<br>
  152. * This will store the HMAC key to the ATSHA204A and the %AES key to EEPROM. It will also write
  153. * a checksum of the personalization data in EEPROM to be able to detect if the data is
  154. * altered.<br>
  155. * Personalization is now complete.
  156. *
  157. * To personalize for software signing do the following procedure:
  158. * 1. Enable @ref GENERATE_KEYS_SOFT<br>
  159. * This will generate random keys for HMAC (signing) and %AES (encryption).
  160. * Copy the keys generated and replace the corresponding definitions under
  161. * "User defined key data", specifically @ref MY_HMAC_KEY and @ref MY_AES_KEY.
  162. * 2. Disable @ref GENERATE_KEYS_SOFT and enable @ref PERSONALIZE_SOFT<br>
  163. * This will store the HMAC key and the %AES key to EEPROM. It will also write
  164. * a checksum of the personalization data in EEPROM to be able to detect if the data is
  165. * altered.<br>
  166. * Personalization is now complete.
  167. *
  168. * If you want to use soft signing and you want to use whitelisting (the ability to revoke/ban
  169. * compromised nodes in the network) and your target does not provide a unique device ID, you have
  170. * to generate a unique serial and store it in EEPROM. This can be done by replacing
  171. * @ref PERSONALIZE_SOFT in step 2 above with @ref PERSONALIZE_SOFT_RANDOM_SERIAL. See the output
  172. * under "Hardware security peripherals" to determine if this is necessary.
  173. *
  174. * When you have personalized your first device after step 2 above, you can run the same sketch on
  175. * all devices in your network that needs to be personalized in a compatible manner. Pick
  176. * @ref PERSONALIZE_ATSHA204A or @ref PERSONALIZE_SOFT as needed by the hardware. When the
  177. * personalization has finished, you just program the sketch you plan to use (with the appropriate
  178. * signing flags set).
  179. *
  180. * If you are using a Raspberry PI-based gateway, personalizaion is done slightly differently:
  181. * 1. Generate keys, execute @c mysgw with arguments
  182. * * To generate HMAC key @verbatim --gen-soft-hmac-key @endverbatim
  183. * * To generate %AES key @verbatim --gen-aes-key @endverbatim
  184. * * To generate a soft serial number @verbatim --gen-soft-serial @endverbatim
  185. * 2. Update the gateway config file with the generated keys/valeus
  186. * * For HMAC key @verbatim soft_hmac_key=<DATA> @endverbatim
  187. * * For %AES key @verbatim aes_key=<DATA> @endverbatim
  188. * * For soft serial number @verbatim soft_serial_key=<DATA> @endverbatim
  189. *
  190. * You are now set and ready to use message signing in your network.
  191. * As of now, the following restrictions will be applied to your nodes:
  192. * * If a node does require signing, any unsigned message sent to the node will be rejected.
  193. * This also applies to the gateway.
  194. * * Your radio communication quality is expected to work fine (if any NACK happen on a signing
  195. * related message, it will fail, and enabling signing will put maximum strain on your RF link as
  196. * maximum sized packets are transmitted in the network). See @ref MySigningTroubleshootinggrp.
  197. * * All nodes and gateways in a network maintain a table where the signing preferences of all nodes
  198. * are stored. This is also stored in EEPROM so if a node or gateway reboots, the other nodes does
  199. * not have to retransmit a signing presentation to the node for the node to start expecting signed
  200. * messages from other nodes.<br>
  201. * * By default, the signing preferences are not "downgradeable". That is, any node that at any
  202. * point in time has indicated a signing requirement will not be able to revert this requirement at
  203. * the receiving end (except by manual erase of the EEPROM).<br>
  204. * If you for some reason need to be able to downgrade the security requirements, you can set
  205. * @ref MY_SIGNING_WEAK_SECURITY at the receiver to allow it to downgrade the security expectations
  206. * of the node in question.<br>
  207. * You then need to reset your transmitting node, to force it to transmit updated signing
  208. * preferences.
  209. *
  210. * @section MySigningwhitelisting Whitelisting and node revocation
  211. *
  212. * Consider the situation when you have set up your secure topology. We use the remotely operated
  213. * garage door as an example:
  214. * * You have a node inside your garage (considered physically inaccessible) that controls your
  215. * garage door motor.<br>
  216. * This node requires signing since you do not want an unauthorized person sending it orders to
  217. * open the door.
  218. * * You have a keyfob node with a signing backend that uses the same PSK as your door opener node.
  219. *
  220. * In this setup, your keyfob can securely transmit messages to your door node since the keyfob will
  221. * sign the messages it sends and the door node will verify that these were sent from a trusted node
  222. * (since it used the correct PSK). If the keyfob does not sign the messages, the door node
  223. * will not accept them. Optionally, your keyfob sends a signed message to your gateway (which
  224. * require signatures) and the gateway in turn sends a signed message to your garage door.
  225. *
  226. * One day your keyfob gets stolen or you lost it or it simply broke down.
  227. *
  228. * You now end up with a problem; you need some way of telling your door node that the keyfob in
  229. * question cannot be trusted any more. You could now repersonalize all your node to switch to a
  230. * different PSK but this obviously is a hassle. How do you make sure that the "rogue" keyfob can be
  231. * removed from the "trusted chain"?
  232. *
  233. * The answer to this is whitelisting. You let your door node keep a whitelist of all nodes it
  234. * trusts. If you stop trusting a particular node, you remove it from the nodes whitelist
  235. * (by uploading a new sketch), and it will no longer be able to communicate signed messages to the
  236. * door node.
  237. *
  238. * In case you want to be able to "whitelist" trusted nodes (in order to be able to revoke them in
  239. * case they are lost) you also need to take note of the serial number of the ATSHA device or the
  240. * software value stored in EEPROM. This is unique for each device. The serial number is printed
  241. * in a copy+paste friendly format by the personalizer for this purpose.<br>
  242. * The whitelist is stored on the node that require signatures. When a received message is
  243. * verified, the serial of the sender is looked up in a list stored on the receiving node, and the
  244. * corresponding serial stored in the list for that sender is then included in the signature
  245. * verification process. The list is stored as the value of the flag that enables whitelisting,
  246. * @ref MY_SIGNING_NODE_WHITELISTING.<br>
  247. *
  248. * Whitelisting is achieved by 'salting' the signature with some node-unique information known to
  249. * the receiver. In the case of @ref MY_SIGNING_ATSHA204 this is the unique serial number programmed
  250. * into the circuit. This unique number is never transmitted over the air in clear text, so Eve will
  251. * not be able to figure out a "trusted" serial by snooping on the traffic.<br>
  252. * Instead the value is hashed together with the senders NodeId into the HMAC signature to produce
  253. * the final signature. The receiver will then take the originating NodeId of the signed message and
  254. * do the corresponding calculation with the serial it has stored in it's whitelist if it finds a
  255. * matching entry in it's whitelist.
  256. *
  257. * Whitelisting is an optional alternative because it adds some code and configuration options which
  258. * might not be desirable for every user. So if you want the ability to use whitelists, you need to
  259. * enable @ref MY_SIGNING_NODE_WHITELISTING. You need to remember that the gateway will remember if
  260. * a node has presented it with a whitelisting requirement as described above, if you at some point
  261. * decide to remove the whitelist requirement.<br>
  262. * The whitelist is provided as value of the flag that enable it as follows (example is a node that
  263. * require signing as well):
  264. * @code{.cpp}
  265. * #define MY_SIGNING_ATSHA204
  266. * #define MY_SIGNING_REQUEST_SIGNATURES
  267. * #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}},{.nodeId = 2,.serial = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}}}
  268. * #include <MySensors.h>
  269. * ...
  270. * @endcode
  271. * In this example, there are two nodes in the whitelist; the gateway, and a separate node that
  272. * communicates directly with this node (with signed messages). You do not need to do anything
  273. * special for the sending nodes, apart from making sure they support signing.
  274. *
  275. * The "soft" backend of course also support whitelisting. Example:
  276. * @code{.cpp}
  277. * #define MY_SIGNING_SOFT
  278. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  279. * #define MY_SIGNING_REQUEST_SIGNATURES
  280. * #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}},{.nodeId = 2,.serial = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}}}
  281. * #include <MySensors.h>
  282. * ...
  283. * @endcode
  284. *
  285. * For a node that should transmit whitelisted messages but not receive whitelisted messages, you do
  286. * not need any special configurations:
  287. * @code{.cpp}
  288. * #define MY_SIGNING_SOFT
  289. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  290. * @endcode
  291. * Remember that you always need to select a signing backend for all nodes that communicate to a
  292. * node that require whitelisting. Also, note that a node that use whitelisting will not accept
  293. * messages from nodes that are not present in it's whitelist.
  294. * And you have to personalize all nodes that use signing with a common HMAC key but different
  295. * serial numbers (@ref MY_SIGNING_ATSHA204 always has unique serials).
  296. *
  297. * @section MySigninglimitations Known limitations
  298. *
  299. * Due to the limiting factor of our cheapest Arduino nodes, the use of diversified keys is not
  300. * implemented. That mean that all nodes in your network share the same PSK (at least the ones that
  301. * are supposed to exchange signed data). It is important to understand the implications of
  302. * this, and that is covered in the "Typical use cases" chapter below.<br>
  303. * Most importantly, if you use @ref MY_SIGNING_SOFT your PSK will be stored in EEPROM and will
  304. * therefore be accessible by anyone with physical access to your node. Therefore it is <b>NOT</b>
  305. * recommended to use @ref MY_SIGNING_SOFT on nodes that are placed in a public place or worn on
  306. * on your person (like a keyfob).<br>
  307. * Also be reminded that the strength of the signature is inversely proportional to the size of the
  308. * message. The larger the message, the weaker the signature.
  309. *
  310. * @section MySigningusecases Typical use cases
  311. *
  312. * "Securely located" in this context mean a node which is not physically publicly accessible.
  313. * Typically at least your gateway.<br>
  314. * "Public" in this context mean a node that is located outside your "trusted environment". This
  315. * includes sensors located outdoors, keyfobs etc.
  316. *
  317. * @subsection MySigninglock Securely located lock
  318. *
  319. * You have a securely located gateway and a lock somewhere inside your "trusted environment" (e.g.
  320. * inside your house door, the door to your dungeon or similar).<br>
  321. * You need to make your node require signed messages but you do not necessarily need to make your
  322. * gateway require signed messages (unless you are concerned that someone might spoof the lock
  323. * status of your lock).<br>
  324. * Configuration example for the secure lock node:<br>
  325. * @code{.cpp}
  326. * #define MY_SIGNING_ATSHA204
  327. * #define MY_SIGNING_REQUEST_SIGNATURES
  328. * #include <MySensors.h>
  329. * ...
  330. * @endcode
  331. * If you do also want your gateway to require signatures from your lock you just enable the same
  332. * (or similar if using software signing) settings in the gateway.
  333. *
  334. * @subsection MySigningpatio Patio motion sensor
  335. *
  336. * Your gateway is securely located inside your house, but your motion sensor is located outside
  337. * your house. You have for some reason elected that this node should sign the messages it send to
  338. * your gateway. You should lock the data (PSK) in this node then, because if someone were to steal
  339. * your patio motion sensor, they could rewrite the firmware and spoof your gateway to use it to
  340. * transmit a correctly signed message to your secure lock inside your house. But if you revoke your
  341. * gateway (and lock) PSK the outside sensor cannot be used for this anymore. Nor can it be changed
  342. * in order to do it in the future. You can also use whitelisting to revoke your lost node.<br>
  343. * This is an unlikely use case because there really is no reason to sign sensor values. If you for
  344. * some reason want to obfuscate sensor data, encryption is a better alternative.<br>
  345. * Configuration example for a motion sensor:<br>
  346. * @code{.cpp}
  347. * #define MY_SIGNING_SOFT
  348. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  349. * #define MY_SIGNING_REQUEST_SIGNATURES
  350. * #include <MySensors.h>
  351. * ...
  352. * @endcode
  353. *
  354. * The gateway needs to be configured with a whitelist (and it has to have an entry for all nodes
  355. * that send and/or require signed messages):<br>
  356. * @code{.cpp}
  357. * #define MY_SIGNING_SOFT
  358. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  359. * #define MY_SIGNING_REQUEST_SIGNATURES
  360. * #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = MOTION_SENSOR_ID,.serial = {0x12,0x34,0x56,0x78,0x90,0x12,0x34,0x56,0x78}}}
  361. * #include <MySensors.h>
  362. * ...
  363. * @endcode
  364. * @subsection MySigningkeyfob Keyfob for garage door opener
  365. *
  366. * Perhaps the most typical usecase for signed messages. Your keyfob should be totally locked down.
  367. * If the garage door opener is secured (and it should be) it can be unlocked. That way, if you
  368. * loose your keyfob, you can revoke the PSK in both the opener and your gateway,
  369. * thus rendering the keyfob useless without having to replace your nodes. You can also use
  370. * whitelisting to revoke your lost keyfob.<br>
  371. * Configuration example for the keyfob (keyfob will only transmit to another node and not receive
  372. * anything):<br>
  373. * @code{.cpp}
  374. * #define MY_SIGNING_ATSHA204
  375. * #include <MySensors.h>
  376. * ...
  377. * @endcode
  378. *
  379. * Configuration example for the door controller node (should require signing from anyone who wants
  380. * to control it):<br>
  381. * @code{.cpp}
  382. * #define MY_SIGNING_SOFT
  383. * #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
  384. * #define MY_SIGNING_REQUEST_SIGNATURES
  385. * #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88}},{.nodeId = KEYFOB_ID,.serial = {<FROM ATSHA ON KEYFOB>}}}
  386. * #include <MySensors.h>
  387. * ...
  388. * @endcode
  389. *
  390. * @subsection MySigningsketches Relevant sketches
  391. *
  392. * - @ref SecureActuator.ino
  393. * - @ref SecurityPersonalizer.ino
  394. *
  395. * @section MySigningtechnical The technical stuff
  396. *
  397. * The following sequence diagram illustrate how messages are passed in a MySensors network with
  398. * respect to signing:
  399. * @image html MySigning/signingsequence.png
  400. *
  401. * None of this activity is “visible” to you (as the sensor sketch implementor). All you need to do
  402. * is to set your preferences in your sketch and personalize accordingly.
  403. * That is enough to enable protection from both Eve and Mallory in your network
  404. * although if you do not also enable encryption, Eve can eavesdrop, but not do anything about,
  405. * your messages (except possibly preventing them from arriving).
  406. *
  407. * How are the messages actually affected by the signing?<br>
  408. * The following illustration shows what part of the message is signed, and where the signature is
  409. * stored:
  410. * @image html MySigning/signingillustrated1.png
  411. *
  412. * The first byte of the header is not covered by the signature, because in the network, this byte
  413. * is used to track hops in the network and therefore might change if the message is passing a relay
  414. * node. So it cannot be part of the signature, or the signature would be invalid when it arrives to
  415. * its destination. The signature also carries a byte with a signing identifier to prevent false
  416. * results from accidental mixing of incompatible signing backends in the network. Thus, the maximum
  417. * size for a payload is 29-7 bytes. Larger payloads are not possible to sign at the moment. Another
  418. * thing to consider is that the strength of the signature is inversely proportional to the payload
  419. * size.
  420. *
  421. * As for the software backend, it turns out that the ATSHA does not do “vanilla” HMAC processing.
  422. * Fortunately, Atmel has documented exactly how the circuit processes the data and hashes thus
  423. * making it possible to generate signatures that are identical to signatures generated by the
  424. * circuit.
  425. *
  426. * The signatures are calculates in the following way:
  427. * @image html MySigning/signingillustrated2.png
  428. *
  429. * Exactly how this is done can be reviewed in the source for the software backend
  430. * (MySigningAtsha204Soft.cpp) and the ATSHA204A
  431. * <a href="http://www.atmel.com/Images/Atmel-8885-CryptoAuth-ATSHA204A-Datasheet.pdf">datasheet
  432. * </a>. In the MySensors protocol, the following internal messagetypes handles signature
  433. * requirements and nonce requests:<br>
  434. * @ref I_SIGNING_PRESENTATION <br>
  435. * @ref I_NONCE_REQUEST <br>
  436. * @ref I_NONCE_RESPONSE <br>
  437. *
  438. * Also, the version field in the header has been reduced from 3 to 2 bits in order to fit a single
  439. * bit to indicate that a message is signed.
  440. *
  441. * @section MySigninggrpbackground Background and concepts
  442. *
  443. * Suppose two participants, Alice and Bob, wants to exchange a message. Alice sends a message to
  444. * Bob. In MySensors “language” Alice could be a gateway and Bob an actuator (light switch,
  445. * electronic lock, etc). But to be generic, we will substitute the term “gateway” with Alice and a
  446. * “node” with Bob (although the reverse relationship is also supported).
  447. *
  448. * Alice sends a message to Bob. This message can be heard by anyone who wants to listen (and also
  449. * by anyone that is within “hearing” distance). Normally, this is perhaps not a big issue. Nothing
  450. * Alice says to Bob may be secret or sensitive in any way. However, sometimes (or perhaps always)
  451. * Bob want to be sure that the message Bob receives actually came from Alice. In cryptography,
  452. * this is known as <i>authenticity</i>. Bob needs some way of determining that the message is
  453. * authentic from Alice, when Bob receives it. This prevents an eavesdropper, Eve, to trick Bob into
  454. * thinking it was Alice that sent a message Eve in fact transmitted. Bob also needs to know how to
  455. * determine if the message has been repeated. Eve could record a message sent by Alice that Bob
  456. * accepted and then send the same message again. Eve could also in some way prevent Bob from
  457. * receiving the message and delay it in order to permit the message to arrive to Bob at a time Eve
  458. * chooses, instead of Alice. Such an attack is known as a <b>replay attack</b>.<br>
  459. * <i>Authenticity</i> permits Bob to determine if Alice is the true sender of a message.
  460. * @image html MySigning/alicenfriends.png
  461. *
  462. * It can also be interesting for Bob to know that the message Alice sent has not been tampered with
  463. * in any way. This is the <i>integrity</i> of the message. We now introduce Mallory, who could be
  464. * intercepting the communication between Alice and Bob and replace some parts of the message but
  465. * keeping the parts that authenticate the message. That way, Bob still trusts Alice to be the
  466. * source, but the contents of the message was not the content Alice sent. Bob needs to be able to
  467. * determine that the contents of the message was not altered after Alice sent it.<br>
  468. * Mallory would in this case be a <b>man-in-the-middle</b> attacker.<br>
  469. * <i>Integrity</i> permits Bob to verify that the messages received from Alice has not been
  470. * tampered with.<br>
  471. * This is achieved by adding a <i>signature</i> to the message, which Bob can inspect to validate
  472. * that Alice is the author.
  473. * @image html MySigning/alicenfriends2.png
  474. *
  475. * The signing scheme used, needs to address both these attack scenarios. Neither Eve nor Mallory
  476. * must be permitted to interfere with the message exchange between Alice and Bob.
  477. *
  478. * The key challenge to implementing a secure signing scheme is to ensure that every signature is
  479. * different, even if the message is not. If not, <b>replay attacks</b> would be very hard to
  480. * prevent.<br>
  481. * One way of doing this is to increment some counter on the sender side and include it in the
  482. * signature. This is however predictable.<br>
  483. * A better option would be to introduce a random number to the signature. That way, it is
  484. * impossible to predict what the signature will be. The problem is, that also makes it impossible
  485. * for the receiver (Bob) to verify that the signature is valid.<br>
  486. * A solution to this is to let Bob generate the random number, keep it in memory and send it to
  487. * Alice. Alice can then use the random number in the signature calculation and send the signed
  488. * message back to Bob who can validate the signature with the random number used.
  489. * This random number is in cryptography known as a
  490. * <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce">nonce</a> or
  491. * <a href="https://en.wikipedia.org/wiki/Salt_%28cryptography%29">salt</a>.
  492. *
  493. * However, Mallory might be eavesdropping on the communication and snoop up the nonce in order to
  494. * generate a new valid signature for a different message. To counter this, both Alice and Bob keep
  495. * a secret that only they know. This secret is never transmitted over the air,
  496. * nor is it revealed to anybody. This secret is known as a
  497. * <a href="https://en.wikipedia.org/wiki/Pre-shared_key"> pre-shared key</a> (PSK).
  498. *
  499. * If Eve or Mallory are really sophisticated, he/she might use a <b>delayed replay attack</b>.
  500. * This can be done by allowing Bob to transmit a nonce to Alice. But when Alice transmits the
  501. * uniquely signed message, Mallory prevents Bob from receiving it, to a point when Mallory
  502. * decides Bob should receive it. An example of such an attack is described
  503. * <a href="http://spencerwhyte.blogspot.se/2014/03/delay-attack-jam-intercept-and-replay.html">
  504. * here</a>.<br>
  505. * This needs to be addressed as well, and one way of doing this is to have Bob keep track of time
  506. * between a transmitted nonce and a signed message to verify. If Bob is asked for a nonce, Bob
  507. * knows that a signed message is going to arrive “soon”. Bob can then decide that if the signed
  508. * message does not arrive within a predefined timeframe, Bob throws away the generated nonce and
  509. * thus makes it impossible to verify the message if it arrives late.
  510. *
  511. * The flow can be described like this:
  512. * @image html MySigning/alicenbob.png
  513. * The benefits for MySensors to support this are obvious. Nobody wants others to be able to control
  514. * or manipulate any actuators in their home.
  515. *
  516. * @section MySigninggrphow How this is done
  517. *
  518. * There exist many forms of message signature solutions to combat Eve and Mallory.<br>
  519. * Most of these solutions are quite complex in term of computations, so I elected to use an
  520. * algorithm that an external circuit is able to process. This has the added benefit of protecting
  521. * any keys and intermediate data used for calculating the signature so that even if someone were to
  522. * actually steal a sensor and disassembled it, they would not be able to extract the keys and other
  523. * information from the device.<br>
  524. * A common scheme for message signing (authenticity and integrity) is implemented using
  525. * <a href="http://en.wikipedia.org/wiki/Hash-based_message_authentication_code">HMAC</a> which in
  526. * combination with a strong <a href="http://en.wikipedia.org/wiki/Hash_function"> hash function</a>
  527. * provides a very strong level of protection.<br>
  528. * The <a href="http://www.atmel.com/devices/ATSHA204A.aspx">Atmel ATSHA204A</a> is a low-cost,
  529. * low-voltage/current circuit that provides HMAC calculation capabilities with SHA256 hashing which
  530. * is a (currently) virtually unbreakable combination. If SHA256 were to be hacked, a certain
  531. * <a href="http://en.wikipedia.org/wiki/Bitcoin">cryptocurrency</a> would immediately be rendered
  532. * worthless.<br>
  533. * The ATSHA device also contain a random number generator (RNG) which enables the generation of a
  534. * good nonce, as in, <i>non-predictable</i>.<br>
  535. * As I acknowledge that some might not want to use an additional external circuit, I have also
  536. * implemented a software version of the ATSHA device, capable of generating the same signatures as
  537. * the ATSHA device does. Because it is pure-software however, it does not provide as good nonces
  538. * (it uses the <a href="http://arduino.cc/en/reference/random">Arduino pseudo-random generator</a>)
  539. * and the HMAC key is stored in SW and is therefore readable if the memory is dumped. It also
  540. * naturally claims more flash space due to the more complex software. But for indoor
  541. * sensors/actuators this might be good enough for most people.
  542. *
  543. * @section MySigninggrpencryption Why encryption is not part of this
  544. *
  545. * Well, some could be uncomfortable with somebody being able to snoop temperatures, motion or the
  546. * state changes of locks in the environment.
  547. * Signing does <b>not</b> address these issues. Encryption is needed to prevent this.<br>
  548. * It is my personal standpoint that encryption should not be part of the MySensors “protocol”. The
  549. * reason is that a gateway and a node does not really care about messages being readable or not by
  550. * “others”. It makes more sense that such guarantees are provided by the underlying transmission
  551. * layer (RF solution in this case). It is the information transmitted over the air that needs to be
  552. * secret (if user so desires). The “trust” level on the other hand needs to go all the way into the
  553. * sketches (who might have different requirements of trust depending on the message participant),
  554. * and for this reason, it is more important (and less complicated) to ensure authenticity and
  555. * <i>integrity</i> at protocol-level as message contents is still readable throughout the protocol
  556. * stack. But as soon as the message leaves the “stack” it can be scramble into “garbage” when
  557. * transmitted over the air and then reassembled by a receiving node before being fed in “the clear”
  558. * up the stack at the receiving end.
  559. *
  560. * There are methods and possibilities to provide encryption also in software, but if this is done,
  561. * it is my recommendation that this is done after integrity- and authentication information has
  562. * been provided to the message (if this is desired). Integrity and authentication is of course not
  563. * mandatory and some might be happy with only having encryption to cover their need for security.
  564. * I, however, have only focused on <i>integrity</i> and <i>authenticity</i> while at the same time
  565. * keeping the current message routing mechanisms intact and therefore leave the matter of
  566. * <i>secrecy</i> to be implemented in the “physical” transport layer. With the <i>integrity</i> and
  567. * <i>authenticity</i> handled in the protocol it ought to be enough for a simple encryption
  568. * (nonce-less %AES with a PSK for instance) on the message as it is sent to the RF backend. Atmel
  569. * does provide such circuits as well but I have not investigated the matter further as it given the
  570. * current size of the ethernet gateway sketch is close to the size limit on an Arduino Nano, so it
  571. * will be difficult to fit this into some existing gateway designs.<br>
  572. * Also it is worth to consider that the state of a lock can just as readily be determined by simply
  573. * looking at the door in question or attempting to open it, so obfuscating this information will
  574. * not necessarily deter an attacker in any way.<br>
  575. * Nevertheless, I do acknowledge that people find the fact that all information is sent “in the
  576. * clear” even if it require some technical effort for an intruder to obtain and inspect this
  577. * information. So I do encourage the use of encrypting transport layers.<br>
  578. * This is however not covered by this implementation.<br>
  579. * This might change in the future as more powerful platforms emerge which permit more complex
  580. * security schemes and better hardware acceleration.
  581. */
  582. /** @}*/
  583. /**
  584. * @defgroup MySigninggrp MySigning
  585. * @ingroup internals
  586. * @{
  587. *
  588. * @brief API declaration for MySigning signing backend
  589. *
  590. * @see MySigninggrpPub
  591. */
  592. /**
  593. * @file MySigning.h
  594. *
  595. * @brief API declaration for MySigning signing backend
  596. */
  597. #ifndef MySigning_h
  598. #define MySigning_h
  599. #include "MySensorsCore.h"
  600. #include "drivers/ATSHA204/ATSHA204.h"
  601. #ifdef MY_SIGNING_NODE_WHITELISTING
  602. typedef struct {
  603. uint8_t nodeId; /**< @brief The ID of the node */
  604. uint8_t serial[SHA204_SERIAL_SZ]; /**< @brief Node specific serial number */
  605. } whitelist_entry_t;
  606. #endif
  607. /** @brief Helper macro to determine the number of elements in a array */
  608. #define NUM_OF(x) (sizeof(x)/sizeof(x[0]))
  609. /**
  610. * @brief Initializes signing infrastructure and associated backend.
  611. *
  612. * This function makes sure that the internal states of the signing infrastructure
  613. * is set to a known initial state.
  614. * \n@b Usage: This function should be called before any signing related operations take place.
  615. */
  616. void signerInit(void);
  617. /**
  618. * @brief Does signing specific presentation for a node.
  619. *
  620. * This function makes sure any signing related presentation info is shared with the other part.
  621. * The presentation of the gateways signing preferences is done in @ref signerProcessInternal().
  622. * \n@b Usage: This function should be called by the presentation routine of the MySensors library.
  623. * You only need to call this directly from a sketch to set up a node to node signed message exchange.
  624. * If you do call this directly from a sketch, and you at some point change your sketch to go from
  625. * requiring signing to not requiring signatures, you need to present this change to the node at least
  626. * once, so it can update its requirements tables accordingly. Or it will keep believing that this node
  627. * require signatures and attempt to send signed messages to it.
  628. *
  629. * @param msg Message buffer to use.
  630. * @param destination Node ID of the destination.
  631. */
  632. void signerPresentation(MyMessage &msg, uint8_t destination);
  633. /**
  634. * @brief Manages internal signing message handshaking.
  635. *
  636. * This function takes care of signing related message handshaking such as nonce exchange.
  637. * \n@b Usage: This function should be called by the incoming message handler before any further message
  638. * processing is performed on internal messages. This function should only be called for @ref C_INTERNAL class
  639. * messages.
  640. *
  641. * @param msg Message buffer to process.
  642. * @returns @c true if caller should stop further message processing.
  643. */
  644. bool signerProcessInternal(MyMessage &msg);
  645. /**
  646. * @brief Check timeout of verification session.
  647. *
  648. * Nonce will be purged if it takes too long for a signed message to be sent to the receiver.
  649. * \n@b Usage: This function should be called on regular intervals, typically within some process loop.
  650. *
  651. * @returns @c true if session is still valid.
  652. */
  653. bool signerCheckTimer(void);
  654. /**
  655. * @brief Get nonce from provided message and store for signing operations.
  656. *
  657. * Returns @c false if subsystem is busy processing an ongoing signing operation.<br>
  658. * Returns @c false if signing identifier found in message is not supported by the used backend.<br>
  659. * If successful, this marks the start of a signing operation at the sending side so
  660. * implementation is expected to do any necessary initializations within this call.
  661. * \n@b Usage: This function is typically called as action when receiving a @ref I_NONCE_RESPONSE
  662. * message.
  663. *
  664. * @param msg The message to get the nonce from.
  665. * @returns @c true if successful, else @c false.
  666. */
  667. bool signerPutNonce(MyMessage &msg);
  668. /**
  669. * @brief Signs provided message. All remaining space in message payload buffer is used for
  670. * signing identifier and signature.
  671. *
  672. * Nonce used for signature calculation is the one generated previously within @ref signerProcessInternal().<br>
  673. * Nonce will be cleared when this function is called to prevent re-use of nonce.<br>
  674. * Returns @c false if subsystem is busy processing an ongoing signing operation.<br>
  675. * Returns @c false if not two bytes or more of free payload space is left in provided message.<br>
  676. * This ends a signing operation at the sending side so implementation is expected to do any
  677. * deinitializations and enter a power saving state within this call.
  678. * \n@b Usage: This function is typically called as action when receiving a @ref I_NONCE_RESPONSE
  679. * message and after @ref signerPutNonce() has successfully been executed.
  680. *
  681. * @param msg The message to sign.
  682. * @returns @c true if successful, else @c false.
  683. */
  684. bool signerSignMsg(MyMessage &msg);
  685. /**
  686. * @brief Verifies signature in provided message.
  687. *
  688. * Nonce used for verification is the one previously set using @ref signerPutNonce().<br>
  689. * Nonce will be cleared when this function is called to prevent re-use of nonce.<br>
  690. * Returns @c false if subsystem is busy processing an ongoing signing operation.<br>
  691. * Returns @c false if signing identifier found in message is not supported by the used backend.<br>
  692. * This ends a signing operation at the receiving side so implementation is expected to do any
  693. * deinitializations and enter a power saving state within this call.
  694. * \n@b Usage: This function is typically called when receiving a message that is flagged as signed
  695. * and @ref MY_SIGNING_REQUEST_SIGNATURES is activated.
  696. *
  697. * @param msg The message to verify.
  698. * @returns @c true if successful, else @c false.
  699. */
  700. bool signerVerifyMsg(MyMessage &msg);
  701. /**
  702. * @brief Do a timing neutral memory comparison.
  703. *
  704. * The function behaves similar to memcmp with the difference that it will
  705. * always use the same number of instructions for a given number of bytes,
  706. * no matter how the two buffers differ and the response is either 0 or -1.
  707. *
  708. * @param a First buffer for comparison.
  709. * @param b Second buffer for comparison.
  710. * @param sz The number of bytes to compare.
  711. * @returns 0 if buffers match, -1 if they do not.
  712. */
  713. int signerMemcmp(const void* a, const void* b, size_t sz);
  714. #endif
  715. /** @}*/
  716. /**
  717. * @defgroup MySigningDebugMessages Signing related debug messages
  718. * @ingroup MySigninggrpPub
  719. * @{
  720. *
  721. * @brief Explanation of the abstract signing related debug messages
  722. *
  723. * MySigning-related log messages, format: [!]SYSTEM:SUB SYSTEM:MESSAGE
  724. * - [!] Exclamation mark is prepended in case of error or warning
  725. * - SYSTEM:
  726. * - <b>SGN</b> messages emitted by MySigning
  727. * - SUB SYSTEMS:
  728. * - SGN:<b>INI</b> from @ref signerInit
  729. * - SGN:<b>PER</b> from @ref signerInit
  730. * - SGN:<b>PRE</b> from @ref signerPresentation
  731. * - SGN:<b>SGN</b> from @ref signerSignMsg
  732. * - SGN:<b>VER</b> from @ref signerVerifyMsg
  733. * - SGN:<b>SKP</b> from @ref signerSignMsg or @ref signerVerifyMsg (skipSign)
  734. * - SGN:<b>NCE</b> from @ref signerProcessInternal (signerInternalProcessNonceRequest)
  735. * - SGN:<b>BND</b> from the signing backends
  736. *
  737. * MySigning debug log messages:
  738. *
  739. * |E| SYS | SUB | Message | Comment
  740. * |-|-----|-----|--------------------------|----------------------------------------------------------------------------
  741. * | | SGN | INI | BND OK | Backend has initialized ok
  742. * |!| SGN | INI | BND FAIL | Backend has not initialized ok
  743. * | | SGN | PER | OK | Personalization data is ok
  744. * |!| SGN | PER | TAMPERED | Personalization data has been tampered
  745. * | | SGN | PRE | SGN REQ | Signing required
  746. * | | SGN | PRE | SGN REQ,TO='node' | Tell 'node' that we require signing
  747. * | | SGN | PRE | SGN REQ,FROM='node' | Node 'node' require signing
  748. * | | SGN | PRE | SGN NREQ | Signing not required
  749. * | | SGN | PRE | SGN REQ,TO='node' | Tell 'node' that we do not require signing
  750. * | | SGN | PRE | SGN NREQ,FROM='node' | Node 'node' does not require signing
  751. * |!| SGN | PRE | SGN NREQ,FROM='node' REJ | Node 'node' does not require signing but used to (requirement remain unchanged)
  752. * | | SGN | PRE | WHI REQ | Whitelisting required
  753. * | | SGN | PRE | WHI REQ;TO='node' | Tell 'node' that we require whitelisting
  754. * | | SGN | PRE | WHI REQ,FROM='node' | Node 'node' require whitelisting
  755. * | | SGN | PRE | WHI NREQ | Whitelisting not required
  756. * | | SGN | PRE | WHI NREQ,TO='node' | Tell 'node' that we do not require whitelisting
  757. * | | SGN | PRE | WHI NREQ,FROM='node' | Node 'node' does not require whitelisting
  758. * |!| SGN | PRE | WHI NREQ,FROM='node' REJ | Node 'node' does not require whitelisting but used to (requirement remain unchanged)
  759. * | | SGN | PRE | XMT,TO='node' | Presentation data transmitted to 'node'
  760. * |!| SGN | PRE | XMT,TO='node' FAIL | Presentation data not properly transmitted to 'node'
  761. * | | SGN | PRE | WAIT GW | Waiting for gateway presentation data
  762. * |!| SGN | PRE | VER='version' | Presentation version 'version' is not supported
  763. * | | SGN | PRE | NSUP | Received signing presentation but signing is not supported
  764. * | | SGN | PRE | NSUP,TO='node' | Informing 'node' that we do not support signing
  765. * | | SGN | SGN | NCE REQ,TO='node' | Nonce request transmitted to 'node'
  766. * |!| SGN | SGN | NCE REQ,TO='node' FAIL | Nonce request not properly transmitted to 'node'
  767. * |!| SGN | SGN | NCE TMO | Timeout waiting for nonce
  768. * | | SGN | SGN | SGN | Message signed
  769. * |!| SGN | SGN | SGN FAIL | Message failed to be signed
  770. * | | SGN | SGN | NREQ='node' | 'node' does not require signed messages
  771. * | | SGN | SGN | 'sender'!='us' NUS | Will not sign because 'sender' is not 'us' (repeater)
  772. * |!| SGN | SGN | STATE | Security system in a invalid state (personalization data tampered)
  773. * |!| SGN | VER | NSG | Message was not signed, but it should have been
  774. * |!| SGN | VER | FAIL | Verification failed
  775. * | | SGN | VER | OK | Verification succeeded
  776. * | | SGN | VER | LEFT='number' | 'number' of failed verifications left in a row before node is locked
  777. * |!| SGN | VER | STATE | Security system in a invalid state (personalization data tampered)
  778. * | | SGN | SKP | MSG CMD='cmd',TYPE='type'| Message with command 'cmd' and type 'type' does not need to be signed
  779. * | | SGN | SKP | ACK CMD='cmd',TYPE='type'| ACK messages does not need to be signed
  780. * | | SGN | NCE | LEFT='number' | 'number' of nonce requests between successful verifications left before node is locked
  781. * | | SGN | NCE | XMT,TO='node' | Nonce data transmitted to 'node'
  782. * |!| SGN | NCE | XMT,TO='node' FAIL | Nonce data not properly transmitted to 'node'
  783. * |!| SGN | NCE | GEN | Failed to generate nonce
  784. * | | SGN | NCE | NSUP (DROPPED) | Ignored nonce/request for nonce (signing not supported)
  785. * | | SGN | NCE | FROM='node' | Received nonce from 'node'
  786. * | | SGN | NCE | 'sender'!='dst' (DROPPED)| Ignoring nonce as it did not come from the designation of the message to sign
  787. * |!| SGN | BND | INIT FAIL | Failed to initialize signing backend
  788. * |!| SGN | BND | PWD<8 | Signing password too short
  789. * |!| SGN | BND | PER | Backend not personalized
  790. * |!| SGN | BND | SER | Could not get device unique serial from backend
  791. * |!| SGN | BND | TMR | Backend timed out
  792. * |!| SGN | BND | SIG,SIZE,'message'>'max' | Refusing to sign 'message' because it is bigger than 'max' allowed size
  793. * | | SGN | BND | SIG WHI,ID='id' | Salting message with our 'id'
  794. * | | SGN | BND | SIG WHI,SERIAL='serial' | Salting message with our 'serial'
  795. * |!| SGN | BND | VER ONGOING | Verification failed, no ongoing session
  796. * |!| SGN | BND | VER,IDENT='identifier' | Verification failed, 'identifier' is unknown
  797. * | | SGN | BND | VER WHI,ID='sender' | 'sender' found in whitelist
  798. * | | SGN | BND | VER WHI,SERIAL='serial' | Expecting 'serial' for this sender
  799. * |!| SGN | BND | VER WHI,ID='id' MISSING | 'id' not found in whitelist
  800. * | | SGN | BND | NONCE='nonce' | Calculating signature using 'nonce'
  801. * | | SGN | BND | HMAC='hmac' | Calculated signature is 'hmac'
  802. */
  803. /** @}*/
  804. /**
  805. * @defgroup MySigningTroubleshootinggrp Signing troubleshooting
  806. * @ingroup MySigninggrpPub
  807. * @{
  808. *
  809. * @brief Typical signing related failure cases and how to solve them
  810. *
  811. * @section MySigningTroubleshootingSymptoms Symptoms and solutions
  812. *
  813. * The first thing to do if you suspect signing is causing problems, is to enable the verbose debug
  814. * flag for the signing backend. @see MY_DEBUG_VERBOSE_SIGNING
  815. *
  816. * If you are having trouble getting signing to work, please see the following troubleshooting tips.
  817. *
  818. * @subsection MySigningTroubleshootingSymptomStFail Signing fails and logs show st=fail on transmissions
  819. *
  820. * This is actually not a signing problem, although often st=fail becomes st=ok when signing is disabled.
  821. * This is by far the most commonly reported problem with signing, but the problems is not with signing,
  822. * it is with radio performance.<br>
  823. * This is a typical log which might look like a signing related issue but isn't:
  824. * @code{.unparsed}
  825. * 0;255;3;0;9;Skipping security for command 3 type 16
  826. * 0;255;3;0;9;read: 3-3-0 s=255,c=3,t=16,pt=0,l=0,sg=0:
  827. * 0;255;3;0;9;Signing backend: ATSHA204Soft
  828. * 0;255;3;0;9;SHA256: 86DEAE1DAF50D577A4E2262B33ABF9DEE05DD8FAF84F94F50900000000000000
  829. * 0;255;3;0;9;Skipping security for command 3 type 17
  830. * 0;255;3;0;9;send: 0-0-3-3 s=255,c=3,t=17,pt=6,l=25,sg=0,st=fail:86DEAE1DAF50D577A4E2262B33ABF9DEE05DD8FAF84F94F509
  831. * 0;255;3;0;9;Failed to transmit nonce!
  832. * 0;255;3;0;9;Message is not signed, but it should have been!
  833. * 0;255;3;0;9;verify fail
  834. * @endcode
  835. *
  836. * The reason for this is that when signing is used, the messages transmitted become relatively large.<br>
  837. * Because of this, the message is more sensitive to noise, and the chance for a message to get scrambled
  838. * increase with the message size. Please refer to the troubleshooting section at the MySensors forum for
  839. * information on how to improve radio performance.<br>
  840. * This is a good place to start: https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help
  841. *
  842. * @subsection MySigningTroubleshootingSymptomNonce Failed to generate nonce
  843. *
  844. * The signing backend failed to generate the nonce needed to sign a message. This indicate a hardware
  845. * problem. Please post the debug info on the forum together with a description of your hardware setup.
  846. *
  847. * @subsection MySigningTroubleshootingSymptomSign Failed to sign message
  848. *
  849. * The signing backend failed to sign the message. Typically this happens if your message is so large,
  850. * that there is no room left in the buffer to store a signature.
  851. *
  852. * @subsection MySigningTroubleshootingSymptomWrongSource Nonce did not come from the destination (XX) of the message to be signed! It came from YY
  853. *
  854. * This should not really happen. The reason for this message is that the signing backend is only capable
  855. * of handling one signed message session at any time. If for some reason multiple nodes send a nonce message to
  856. * the same node, only the nonce from a node that is the destination of the current message signing session will be
  857. * accepted. Any other nonces will be dropped. This should not happen as no node should send a nonce unless asked to,
  858. * and a node will only ask for a nonce to one destination for every signing session.<br>
  859. * If you see this message, please post the debugging details on the MySensors forum so it can be investigated further
  860. * together with a description of your setup.
  861. *
  862. * @subsection MySigningTroubleshootingSymptomNotSigned Message is not signed, but it should have been
  863. *
  864. * A node has failed to comply with the signing preferences of this node. Check that the node has received a
  865. * signing presentation message from this node. This is automatically transmitted to gateways. For other nodes,
  866. * you need to transmit the presentation from the sketch. @see signerPresentation
  867. *
  868. * @subsection MySigningTroubleshootingSymptomNotSignedGeneral "Messages do not appear to be signed but I think they should be..."
  869. *
  870. * Make sure you have enabled the flag to require signatures to require signatures and have enabled one of the signing
  871. * backends. @see MY_SIGNING_REQUEST_SIGNATURES @see MY_SIGNING_ATSHA204 @see MY_SIGNING_SOFT
  872. *
  873. * @subsection MySigningTroubleshootingSymptomNotWorkingWhitelisting Signature verification failed!
  874. *
  875. * Make sure both source and destination of the signed message has undergone @ref personalization with the same HMAC key.<br>
  876. * Also, if whitelisting is used, make sure the proper serial is paired with the proper node ID at the destination.
  877. * Whitelisting preferences are communicated with the signing presentation (done automatically from nodes to gateway but
  878. * has to be explicitly done by sketch for node to node communication). @see signerPresentation
  879. */
  880. /** @}*/