-
Notifications
You must be signed in to change notification settings - Fork 0
IOT
You can indeed use this system to send messages from arduino to arduino. Since the arduino has very little memory we use a stripped down version of the sendContainer / MessageData.
it looks like this - the length in bytes:
- options -1 (clues how the next bits should be interpreted)
- sender -16
- receiver - 16
- mId - 4 (counter)
- (command) type - 1
- mlen - 2
- payload - 0 to 65000
- signature - 64 (optional)
usually the payload is also encrypted end to end so the payload internally looks like this
- crypto header - 20+ 16
- actual payload - length of real payload padded to next 4 bytes
All of this is encrypted with libhydrogen since it is the only library smal enought to fit on the arduino. If you have sufficient memory and cpu power please us the normal ssl webscoket since it is easier to use and develop with.
You might ask yourself why signature is optional and how this is determined. This as well is because the total header size with encryption header is already 76 bytes for end to end encrypted messages and additional 36 for a total of 112 bytes when sent encrypted to the server.
However this could already be too much for the arduino considering you also need an encryption key and state as well as the library and don't forget your own code.
So how do enable/disable signature?
You do it by setting the 8th bit of the options to 1/0. Obviously you will have to prepend the payload with the signature if you do this.
message options by byte backwards [87654321]:
- : signature yes/no
- cyphersuite first 2 bit number
- cyphersuite second 2 bit number
- Not assigned
- Not assigned
- Not assigned
- Protocol update
- Protocol update
cyphersuites are
- (0) libhydrogen
- (1) libsodium
- (0b10) libsignal
- (0b11) Not assigned
Then there is a predifined set of commands
// 0x setup/security
-
0x01 client hello
-
0x02 server hello
-
0x03 choosen cypher/setup
-
0x04 finish // encrypted server // end to end
-
0x05 continue server session
-
0x06 key upload
-
0x07 request public key
-
0x08 public key(s) (for setup)
-
0x09 session setup
// 1x,2x messages
-
0x10 normal msg (lite)
-
0x11 received (either side confirms)
-
0x12 receiver received
-
0x13 receiver has seen
-
0x17 store data /message
-
0x18 get data/message
-
0x19 receive data/message
-
0x20 group message
// 3x general flow
- 0x30 login
- 0x31 logout
- 0x32 register
// 4x errors
- 0x40 rate limit exceeded
- 0x41 pass_token
// 0x5x media flow
- 0x50 file (specified in the payload)
- 0x51 png
- 0x52 jpg
- 0x53 gif
- 0x54 mp3
- 0x55 wav
- 0x56 mp4
- 0x57 executable
// 0x6x sensors
- 0x60 temperature
- 0x61 brightness
- 0x62 water amount
- 0x63 loudness
- 0x64 speed
- 0x65 location (GPS)
// 0x7x extentions
- 0x70 type encrypted within the payload
additionally there is 1 byte in the encypted payload indicating content type if command type is message
- x01 message
- x02 image
- x03 audio
Libhydrogen session setup
graph LR;
B -- keys 0x06 --> cloud
A[User A mobile] -- get key 0x07 --> cloud
cloud -- keys 0x08 --> A
A -- setup 0x09 --> cloud
cloud -- setup 0x09 --> B
A -- message 0x10 --> cloud
cloud -- message 0x10 --> B