Hello,
I have an Arduino Nano plugged to an HC-12, inside my house. Let's call this one "board H", like House.
I have an other Arduino Nano + HC-12, close to my garage door. Let's call this one "board G", like Garage.
H receives data from the internet, encrypts it, and forwards it to its HC-12, which is paired with HC-12 at board G.
G receives the encrypted data from H, decrypts the data, and processes it.
Data looks like this:
<encrypted_data_45sd4f65s4df65s4d> (what board H sends through serialsoftware)
encrypted_data_45sd4f65s4df65s4d (board G picks anything in between < and > tags)
doOpenGarageDoor (board G decrypts data and does the necessary thing to open the garage door).
As you can see, eventhough the data that is being transmitted/receives over the air is encrypted and does not make any sens to a malicious actor, it can be replayed by that actor as is, in order to open the door.
What do I need to do to secure this? What would the transmitted data look like?
Right now i'm thinking an RTC module (DS3231) so I can put an encrypted timestamp along the data in order to invalidate it after x seconds has passed. I dont quite like that option because the module needs a little battery, which would require maintenance (the box with the arduinos are sealed/waterproofed)
Geez no time to read that now. But off the top of my head, if G sends a random encrypted message to H, H decrypts and returns it to G, G can be sure that it was sent by H if it was decrypted successfully. Bad actor B can't decrypt G's message and so can only respond with the last exchange pair. But it's expired, G won't accept any previous decryptions because they don't match.
It's not the greatest security to expose both a message and its crypt, but unless your garage is full of gold bars, it's not a big deal.
Nice. I believe that's how car key fobs actually work. I forgot about this option.
Have you ever heard of an existing implementation/library for the arduino? I do not want to reinvent the wheel, plus the part with the sliding window exceeds my skills in C programming. Do I need a sliding window anyway for the sequence number? Since I only have 1 transmitter (HC-12 at board H) and 1 receiver (HC-12 at board G).
Unrelated: out of curiosity, how does it work if you have 2 transmitters (let's say 2 car key fobs) and 1 receiver (the car)? If you use the same car key fob during a few months, the sequence number might reach 12345, but the other car key fob in the drawer stayed at 123. I you decide to now use the second car key fob, do you have to press the "unlock car" button as many times as necessary in to catch up how late you are in the sequence?
As a simple solution, you could encrypt a uint16 into your transmission. That gets incremented by 1 every transmission as suggested in #2. You can skip the sliding window and accept any message as genuine if the decrypted uint16 is greater than the uint16 value from the previous transmission. That would give you 65,535 transmissions before you have to handle a rollover. Probably enough to see out the lifetime of the garage door.