I recently started with a domotic project, I began creating a lock opening with a RFID currently I'm trying improving the code (I took from http://forum.arduino.cc/index.php?topic=256260)

but I have some question about the security of this system (or any in the domotic way).

First, I know any system is 100% secure. starting from there, I was thinking, what happens if someone known that the system is built in the arduino platform and has some knowlege about it, that person can create a sketch, upload to the board and make "opening" all the pings?, they will have access to that room or thing I'm protecting (or trying). This is just a excercise, I don't want to go in depth about the external security that the board/system must have.

So, searching topics about it, I didn't find anything to help in the solution of this theoretical problem. I read some articles about the bootloader and I think, the solution can be there, I know Arduino is a openSource solution, but I think it doesn't mean insecure, so I think some kind of system who check a key before to load a sketch can help. It can have a default key, who can be used to the developing process, and other key (any) who must be verified, in the current sketch.

I'll try to explain it a little better:

Developing Mode Bootloader [No Key] -----> can upload any sketch

Production Mode Bootloader[check mode] -----> [Sketch with the secure key] [Upload New sketch] -----> Bootloader[check the key in the new sketch with the key in the current sketch] (allow or block access, according as appropriate)

I don't have deep knowledge in criptography or bootloading, so I don't know if it's corret solution. I saw there are some way to "download" the code of the board (in a bin), I don't know if with this way the key will be exposed.

can someone tell me if this basic security would be helpful? if it's, can be possible to implement? how? Will the key be exposed in the bin (in case of download)?

  • 1
    Just make sure no one has access to the Arduino. By e.g. Placing it in the room you've locked with it :-). Once people have access to it, all bets are off. They might even replace the arduino entirely, negating any write protection you have added. People could also hack your developer PC and alter the compiler to create a backdoor in all your sketches. True Software security is pretty much impossible
    – Gerben
    Commented Sep 13, 2014 at 9:53
  • Thanks Gerben, that is why I started saying about a system isn't 100% secure. But you have some good point, the question is thinking with a specific scenario, 1. they don't have much time to replace a new arduino, they only have access to a usb port. But really, having new point of view always helps to improve some things, even if they're too obvious.
    – GEPD
    Commented Sep 13, 2014 at 17:29

2 Answers 2


First of all, a quick rule that you should follow... It is called Kerckhoffs's principle. Wikipedia states it as this:

A cryptosystem should be secure even if everything about the system, except the key, is public knowledge.

So, you're never going to reach "full security."

If the attacker can physically access your Arduino, all bets are off. They can upload new code, replace the Arduino, or just simply rewire your circuit so the door opens.

Also, they may be able to remove the RFID module and replace it with another Arduino board that sends random data in the right format hundreds or thousands of times a second. If they find the key code, they can make a new RFID tag with that ID. Thus, it is essential to keep that ID private.

So here's what you should do (in this scenario, password = RFID key's ID):

  • Make sure they can touch or access as little as possible. If you can, embed the RFID receiver inside a wall so they don't know where the receiver is and would have to break the wall to access it. If they break the wall, they could break the door, so this isn't necessarily a major security flaw. Of course, remember the sensitivity of your receiver.
  • Obfuscate your code: If you do something where you combine only certain bits/bytes of a few different strings to get a passcode to be compared to the sensor value. Of course, the compiler will remove most of this in an attempt to optimize your code. Note that this isn't actual security, just making the intruder having to do more work. A lot of people discourage this since it gives you a false sense of security, but I encourage it because it will take a little bit longer to hack into your application if they get your code. Remember that at any time they can use Serial.println(finalPasswordHere);.
  • If you're really worried, hash it. AVR chips probably don't have enough power to do advanced hashes like SHA-512. There seems to be a few MD5 hash algorithms for Arduino. MD5 isn't really secure with only a few digits, but if you have a 30 character hash that would take a long time to brute-force it. Add a salt with a ton of random characters (ex: lsjJK399!$%^&flk2) that aren't normally found in lookup tables. You'd combine the salt and the ID for the tag into one hash and put that in the code. Then, you'd hard code that hash into the main code. When you want to check if the ID being scanned is correct, you'd hash it with the salt and then compare that to the known hash. If you have more than one ID in the system, it's a good idea to have a different salt for each.
  • Annonomus Penguin, thanks for that detailed answer. It's a good start, Is truth that never going to reach a "full security", but also is truth you can always keep improving something already done. the three point are very important and useful, the last one very useful at level of code, I'm trying to asking myself some dumb/obvious topics who can be improved, in this kind of situation the time is gold, so one second of a dumb layer of security can really be a difference thanks again.
    – GEPD
    Commented Sep 13, 2014 at 18:02

A major factor in digital security is physical security. If you want a secure system you have to keep the bad guys from being able to connect wires and such.

If you have your Arduino inside a secure box inside your locked house, and it is not connected to the internet, the only way an intruder will be able to access it is to get into your house. Once inside the house you should require a second, higher level of security to unlock the Arduino's enclosure and muck with it.

If the Arduino is inside your house and an intruder doesn't have physical access to it, they can't install new apps on it or do ANYTHING with bootloaders.

If you don't use encryption of some sort you will not have very good security.

You can build an RFID or NFC system that uses a challenge-response scheme with encryption.

Something like this: When the house detects a unique RFID identifier, it generates a random number and encrypts it with that key's public encryption key. It sends the encrypted number to the key, which decrypts it using it's private key, then re-encrypts it with the house's public key and sends it back. The house decrypts the number, verifies that it is the correct number, and only then unlocks the door. The house is programmed to time out pretty quickly if it doesn't receive the correct key, to avoid brute force cracking of the encryption.

You also want a system where after a modest number of wrong responses, the system locks out for a couple of minutes.

With crypto, it doesn't matter if an intruder captures the RFID/NFC communication between the house and the key. What's sent is a one-time, encrypted code. Without the encryption keys, the intruder can't do anything with that data. It just looks like noise.

Even better is to add second factor authentication like a numeric code the user has to type, some sort of biometric scan, etc.

The above requires a fair amount of smarts in the key. There are RFID chips out there that have built-in crypto support. I don't know how good they are however. You either need hardware crypto support or a pretty high powered chip (ARM or better) to do crypto in a pocket sized device.

  • Thanks Duncan, I imagine a system like a Crypto have to be very effective in terms of encryptation. What I'm trying to make, is a excercise to go step by step, and think things too obviuos and try to improve it it's possible, a set of poor and obviuos security layers, can make a difference. I'll make some test with that random number with public/private keys, It can be a huge difference, this combined with some real time alerts can be very useful
    – GEPD
    Commented Sep 13, 2014 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.