code protection

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
alsar
Posts: 5
Joined: Thu Feb 27, 2020 2:51 am

code protection

Post by alsar » Thu Feb 27, 2020 3:04 am

I've planned ESP32 with Micropython for a product.By any means can I protect the code ?
At present I'm using PIC microcontroller where code protection is easily done.Is it possible with Micropython on ESP32?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: code protection

Post by jimmo » Thu Feb 27, 2020 3:32 am

This has been discussed a few times on the forum and there are a couple of github issues.

The simple answer is that your best option right now is to freeze your Python code into the firmware image. This will not prevent someone being able to copy the firmware to another device, but it will be moderately effective at preventing anyone from reading your Python code.

(i.e. what I'm saying here is that as long as the device only has the bytecode for your program (either in the form of .mpy files or frozen into the firmware), then there's no "good" way of turning that back into useful Python code).

But if you need to prevent someone from being able to access the bytecode, then the more complicated answer is that:
- There's no simple equivalent of the PIC's readout protection (because the flash is external, so you can always read hte flash directly).
- You can encrypt the flash, I'm unsure of how well this is supported from MicroPython.
- None of this really matters if the user is able to access the REPL or execute Python code on the device -- they can access the memory mapped flash easily via Python.

To make this really work, you need signed firmware, secure boot, no ability for a user to run arbritrary code, etc.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: code protection

Post by Roberthh » Thu Feb 27, 2020 4:25 am

The ESP32 flash encryption is supported by Pycom. It is , if not all, controlled by the make process.
P.S. I did not look into the details of the ESP32 encryption feature, and how this fits to the option of MicroPython of being able to upload scripts.

alsar
Posts: 5
Joined: Thu Feb 27, 2020 2:51 am

Re: code protection

Post by alsar » Thu Feb 27, 2020 10:12 am

Thank you for the prompt replies.
Would be helpful if any link to freeze Python code into the firmware image.
Thanks once again

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: code protection

Post by jimmo » Thu Feb 27, 2020 12:22 pm

There was a recent thread discussing this here: viewtopic.php?f=2&t=7830#p44697 and also here viewtopic.php?f=16&t=7850#p44764

Post Reply