3
\$\begingroup\$

I have developed some code on a STM32F7 uC which I would like to protect to be used by third parties without my consent. The thing is, if I give a company a .hex file, they can flash as much units they want without paying a license fee.

For a prototype hardware, I just can program a fix UUID that is checked with the controllers UUID at the start to prevent that, but I don't think that is a very safe way, since it can easly be found and replaced in the .hex file.

So, how can I give access to a company to use my firmware with license fee and ensure, the firmware is protected to misuse?

\$\endgroup\$
4
  • \$\begingroup\$ Will the firmware be programmed only once by using JTAG/SWD or is the firmware upgradeable by end users via some interface, and which interface, USB or serial etc? \$\endgroup\$
    – Justme
    Commented Dec 22, 2021 at 7:48
  • \$\begingroup\$ Hi Justme, the firmware will be only programmed once, there is at the moment no bootloader planed. \$\endgroup\$ Commented Dec 22, 2021 at 7:52
  • \$\begingroup\$ What about the factory built-in bootloader? And what is the programming interface? Any other communication interface? If you don't use a bootloader of any kind, you must then make the PC programming software yourself to allow programming of chips with certain UUID, but you would have to get the list of UUIDs first so perhaps save the UUIDs and stop programming after 100 different UUIDs. A bootloader or USB or serial interface would just help as it enables the programming to just not depend on the PC and burning the firmware unencrypted. \$\endgroup\$
    – Justme
    Commented Dec 22, 2021 at 8:06
  • \$\begingroup\$ Are you sure your software is important enough to care about that? Important enough that the company you're selling it to is willing to jump through hoops to for it? If it is, you should probably have your company hire a lawyer to help with the negotiations. If not, put a high enough price on it that you don't need to count individual units and pick a buyer that's sufficiently reputable. \$\endgroup\$
    – ilkkachu
    Commented Dec 22, 2021 at 17:39

6 Answers 6

5
\$\begingroup\$

This is not a new problem, and solutions do exist. There are two main ones I would look at:

The first is having a secure flashing solution (like this) which is specifically designed for this sort of solution (i.e. you dont trust your factory). As far as I can tell, it does everything you want

The second is to have a secure ic, like A1006TL. Your firmware communicates with this, and uses the result to do something fundamental (for example, your bootloader communicates with this and decrypts the rest of the program). This probably could be circumvented eventually, but may provide some measure of security depending on how you design the system.

\$\endgroup\$
4
  • \$\begingroup\$ I assume OP wants to give only firmware to the end user, not the hardware of any sort. Then it's the problem. \$\endgroup\$
    – NStorm
    Commented Dec 22, 2021 at 11:18
  • \$\begingroup\$ The secure flashing solution from segger seems a really good thing and exactly what I'm looking at. The only part I don't can read about is, if the option bytes of the microcontroller can also be set after flashing to ensure, the manufacturer cannot read out the firmware after that. Or how is the firmware protected from readout with this segger device? \$\endgroup\$ Commented Dec 22, 2021 at 12:30
  • \$\begingroup\$ What I found out is, that the secure flashing solution from segger works only with the newest versions of the STM32 familiy (L5, H7). Seems like there is no possibility to use the SFI feature for secure flashing on a stm32F7 \$\endgroup\$ Commented Dec 22, 2021 at 14:37
  • \$\begingroup\$ @HansPeterLoft as others have said, without some other communication channel that your "opponent" (the other party) doesnt directly control (like authenticating with your server, or preprogramming a bootloader), there's basically nothing you can do thats "theoretically" secure. There are all sorts of obfuscations you could perform to greatly increase the effort required to circumvent, so you could look into these. You may also want to look into having the firmware pre-programmed by ST (cost and lead time unknown) \$\endgroup\$
    – BeB00
    Commented Dec 23, 2021 at 0:17
4
\$\begingroup\$

There is no safe way as long as you don't have your hands on the hardware before. Even if you add some sort of code encryption based on UUID, you will have to include an algo to decrypt this in your firmware and it can be reverse engineered. I.e. only you can do is to make it harder this way. But it still always leaves a possibility to reverse engineer it. It's so called "Security through obscurity".

At least as long as your end device doesn't have some sort of Internet functions, where you can rely some authentication/authorization things on your servers.

Anther real way is to implement and install a bootloader at the read protected area first. But this bootloader shouldn't be disclosed to make it safe. I.e. you have to program it on your own first and send MCU to your client. You just can't send HEX to end user.

Anyways, as long as you have MCU first - you can simply enable readout protection and that should be enough for most projects if you aren't planning in updating it. But that way you have to pre-program and sell it with hardware.

There is also some sort of security/authentication IC exists on the market (ATSHA204A for example) which sometimes have a properties of safe challenge-response identification. You can include this in your device design (i.e. add another security IC to the PCB). That way your customer can build complete hardware with that IC. Next either you derive encryption key based on some sort of it's identification or you provide a first stage firmware (HEX) to authenticate that device. It depends on how exact IC works and we aren't talking about exact part here, out of scope of this question. Next, once you've have the encryption key, you can assemble your actual end firmware encrypted with that key. Which will only be able to decrypt and ran paired with that particular security IC based on some sort of crypto methods. But that really involves pretty good knowledge of cryptography and how such things works. Also add some additional work for your customer.

\$\endgroup\$
3
\$\begingroup\$

(I am not a lawyer)

I would recommend looking into getting a lawyer to draft up a binding contract for your licensing agreement. Unfortunately that will mean the onus on you to ensure they are keeping to the contract. Again, IANAL, but I'd imagine this would also include Non Disclosure Agreements as well to discourage them from sharing your files with others as well. The encryption stuff will go so far, but you really want to have a strong licensing agreement in place so if they decide to skip paying you, you can go after them for breach of contract.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Although I dont have that much experience on the legal side, I would say that if you can get the technical side right, its probably much better. The legal route can be long, complicated, and expensive, with no certainty of success, and if you win, no certainty of payment. If you can stop infringement in the first place, that sounds like a much better option to me. Of course, having an agreement in place is important, but make sure your legal spending is commensurate with a) the value of the deal altogether and b) the complexity of the deal. \$\endgroup\$
    – BeB00
    Commented Dec 23, 2021 at 5:19
  • 1
    \$\begingroup\$ i.e dont spend 50k on legal advice to protect 150k of revenue \$\endgroup\$
    – BeB00
    Commented Dec 23, 2021 at 5:19
1
\$\begingroup\$

So, how can I give access to a company to use my firmware with license fee and ensure, the firmware is protected to misuse?

You provide a hex file for a bootloader, this bootloader also turns on readout protection.

You then provide an PC application that programs the chip via said bootloader, but before doing so, it checks some server you run if that UUI is allowed to be programmed. And checks the signature of the encrypted binary you're flashing to see if it has been tampered and if it's allowed to be programmed in that device. Or adds the UID/Binary combination to the database of programmed devices. So you can bill them for it.

Of course, this won't be perfect. That's very hard, Apple can't even do that.

How far do you want to go? How far do you need to go?

Caution: ST's UUID is just the wafer number and coordinates. Easily predictable.

\$\endgroup\$
10
  • \$\begingroup\$ Stm32s have been hacked. There’s some open source hardware that will cause it to bypass the security fuse and allow access to the code. So how much effort do you want to expend in locking it down? \$\endgroup\$
    – Kartman
    Commented Dec 22, 2021 at 10:41
  • 2
    \$\begingroup\$ @Kartman increasing the hurdle always reduced the likelihood of someone doing it. Was the F7 hacked as well? ST is probably getting better with each generation of devices as well. F1 and F0 families I found references for. \$\endgroup\$
    – Arsenal
    Commented Dec 22, 2021 at 11:01
  • \$\begingroup\$ I also thought the F7 is secure and the hack is only on F1 and F0 \$\endgroup\$ Commented Dec 22, 2021 at 12:34
  • \$\begingroup\$ @HansPeterLoft Expect all parts in development from before release of the CVE (2018) to be compromised. This includes the F7 (2015). Peripheral reuse is high in these parts. If the IP in the firmware is this crucial, invest in better measures or more security oriented parts. But first write down what you want to protect from and why. And what the costs is if you don't vs if you do. Inspiration. \$\endgroup\$
    – Jeroen3
    Commented Dec 22, 2021 at 12:44
  • \$\begingroup\$ The main theoretical issue here is that they can just tamper with the bootloader before they flash it, or sniff the comms with the bootloader. Fundamentally, at some point the chip needs to be able to decrypt the firmware, but has no intrinsic secure method for doing so. Therefore at some point, somehow, you have to give it a way to do so, and if you didn't program that on the chip before giving it to them, then whatever you do is "breakable". Now ofc "breakable" is relative, but any solution here would be breakable as in "picking a very complicated lock", as opposed to "brute forceing AES" \$\endgroup\$
    – BeB00
    Commented Dec 23, 2021 at 5:26
1
\$\begingroup\$

To stop easy attacks, it is enough to hide the UUID multiple times in the firmware in ways that are difficult to find. All of these can be changed, but it takes a skilled programmer a couple of hours to find them.

Here are some common tricks:

  1. Calculate checksum of the UUID and compare against that. There are many different checksum algorithms that you can use. That way the UUID itself will not be visible in hex file.

  2. XOR the UUID with some important initialization variables of your program. For example, if you have uint32_t init_command = 0x12345678;, change it to 0x12345678 ^ DEVICE_UUID at compile-time. Then at runtime have the code do init_command ^= read_uuid(); before using it. The software will fail in mysterious ways if used with wrong UUID.

  3. The read_uuid() function can be easy to find by the UUID address it reads. You can calculate the address at runtime, and also use DMA to disguise the access. On STM32, debugger watchpoints do not get triggered on DMA access.

  4. Have the code disable debugger interface on boot. Have multiple hidden checks throughout the code that change the behavior if debugger pins are active - for example crash it early or in random ways.

All of these are just slow-downs, but programmer time is expensive and your license cost is hopefully more affordable than breaking the protection.

\$\endgroup\$
1
  • \$\begingroup\$ Just a security through obscurity as was already noted before. \$\endgroup\$
    – NStorm
    Commented Dec 22, 2021 at 18:57
0
\$\begingroup\$

The oldskool dongle:

You can put a cheap micro somewhere on your board, with unreadable firmware, that replies to a challenge from the main micro. So the main micro's firmware can be updated by the user, it contains only a public key which is not secret, and the secret key is in the small micro that won't be updated.

The main firmware could also be encrypted by a key stored in the small micro for extra security.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I assume OP wants to give only firmware to the end user, not the hardware of any sort. Then it's the problem. \$\endgroup\$
    – NStorm
    Commented Dec 22, 2021 at 11:18

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.