I'm developing a product with simple Cortex-M MCU (with no OS on board, firmware on bare metal) and internet connectivity via external module.
How do I make it secure? More specifically, how do I protect the data that is sent to and from the remote server?

My thoughts are:

  1. I can't assume that firmware can be protected; since all users will have physical access to it - they eventually will find a way to dump it. Flash-read protection won't work, encrypting the flash won't prevent dumping it from RAM or something else.
  2. Using external encrypted flash/eeprom won't work for the same reasons.
  3. Relying on HTTPS on the external chip won't be enough because external module is connected to the MCU via UART and can easily be sniffed or tampered.

I have very basic understanding of cryptography but I know that I shouldn't invent my own, so I presume I'll have to encrypt all the data that is sent to the server by some well-known public key crypto. Probably using session keys. But that still requires using one master secret key on the device and I don't know how to store it securely due to 1).

Any ideas? Is there a well-known bulletproof solution?

Or I should just generate random keys for every device (not derived from device ID or anything like that)? So if one device is compromised it won't affect the whole network - and that's about it?

UPD: Clarification - I don't want to allow device owner to impersonate other devices and upload false data (about other devices) to the database.


2 Answers 2


If the issue is that you don't want any device to impersonate others, the problem is simple, and already solved. Just look at every single online service that have users and don't want one user to access data belonging to other user: authentication.

You must use TLS, this is the first point. Without TLS you are building a castle on the sand.

Second: have a sign-up routine that your devices will follow when they connect for the first time and don't have a key pair yet: generate a new one, send to the server. Any time later that the device sends anything, it need to sign the data with its key, so the server knows it's legit.

An attacker will only be able to impersonate devices he owns, or can physically access, and there's no way around this. But they cannot impersonate any other, even with access to your database.

  • Seems legit. But that also means that I'll have to use TLS with plain HTTP; my current hardware doesn't support TLS/SSL/HTTPS - only http, tcp or udp - so I'll have to do TLS 'by hand'. Will it still be advisable to use TLS or are there some simpler methods?
    – Amomum
    Oct 14, 2018 at 17:34
  • You can use mbed.com/en/technologies/security/mbed-tls to add TLS support to your project. The samples even have a TLS client ready to use. And a server too.
    – ThoriumBR
    Oct 15, 2018 at 1:36

More specifically, how do I protect the data that is sent to and from the remote server?

I'm not sure if I properly understood your question. But I understand the above part that you just want to protect the data in transit between client and server. In this case HTTPS (or plain TLS) is enough. This will automatically use different encryption keys for different TLS sessions (where TLS session will have the same lifetime as the TCP connection unless session resume is used) so the risk you imagine of having the same encryption key on all devices does not exist.

But HTTPS or TLS will not protect against somebody who has physical access to the device and intercepts the data there before encryption and after decryption. It only protects the data in transit.

  • Exactly, so I want to know how can I keep the data secure when user has physical access to device.
    – Amomum
    Oct 13, 2018 at 20:33
  • @Amomum: If you have sensitive data on the device in plain (i.e. not encrypted) since they were either created there or they are needed there for doing some computations, then you need to protect these internals of the device against physical access. As you realized yourself: your hardware does not provide this protection. Thus you would need to get hardware which is more tamper resistent. That's why smartcards and similar devices with sensitive data are specifically protected so that they rather break instead of revealing the secrets. Oct 13, 2018 at 20:39
  • Let's say I can't change current hardware - what's the best I can do?
    – Amomum
    Oct 13, 2018 at 20:45
  • @Amomum: What is the best is hard to say without knowing more about the specific use case, i.e. why the IoT device needs the sensitive data in the first place and what are the risks if the attacker gets access to specific data or can modify the data in a specific way or just corrupt the data. The best is probably to keep sensitive data off the device and thus far away from the attacker. Others ways might be to obfuscate what's going on or just to have a useful strategy to deal with a compromise of the data. Oct 13, 2018 at 21:20
  • Device can access remote database; it doesn't actually hold any sensetive data. I guess my main concern is that attacker should not be able to imitate other devices and rewrite their database entries - if he has physical access to his own device. I suppose that if every device will have it's own long and random secret key that is not derived from device ID - that should be enough to mitigate this particular problem?
    – Amomum
    Oct 13, 2018 at 22:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .