neodark
Posts: 3
Joined: Fri May 17, 2019 9:32 am

Protect python code to prevent copy

Fri May 17, 2019 9:40 am

Hi, I have developed an python automation code.... and my question is


Is any way to "protect" the code to prevent that any user can get the micro SD card and read and/or copy the code to replicate on more raspberrys?

Thanks!!

Andyroo
Posts: 2956
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Protect python code to prevent copy

Fri May 17, 2019 11:46 am

If the user has physical access to the Pi then no.

There is no hardware encryption chip built into the Pi and if I remember correctly the serial number can be changed as can the MAC address.

The SD card can be copied very simply - in fact the best tool comes with the Pi in the standard software.

You have to look at external means of protection by using a USB key or a web site that tracks activations. It may still be possible to edit the python and remove this though. Best to use something like Nuitka to convert to C and compile it.

Remember if you are commercially selling software some of the licences in Linux may require you to copy their licences and the Foundation has rules about trademarks and branding https://www.raspberrypi.org/trademark-rules/
Need Pi spray - these things are breeding in my house...

User avatar
thagrol
Posts: 1479
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Protect python code to prevent copy

Fri May 17, 2019 11:53 am

neodark wrote:
Fri May 17, 2019 9:40 am
Is any way to "protect" the code to prevent that any user can get the micro SD card and read and/or copy the code to replicate on more raspberrys?
Almost certainly not. Even if you could do something at the file level, the SD card could still be imaged or your python code could be extracted from RAM once it has been loaded.

Or your code could be opened in a text editor and cut 'n' pasted into a new file.

Python is not a suitable language if this sort of thing is a major concern.

You could look into what the big boys do: unique product keys, online activation, only running if a particular item of hardware is present, ...
Whether that's worth the extar effort and cost is up to you.

And whether python as a langue is secure enough to do this, I don't know.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

User avatar
thagrol
Posts: 1479
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Protect python code to prevent copy

Fri May 17, 2019 11:57 am

Andyroo wrote:
Fri May 17, 2019 11:46 am
There is no hardware encryption chip built into the Pi and if I remember correctly the serial number can be changed as can the MAC address.
The serial number is in the OTP so can't be reprogrammed but it may be possible to spoof it, I don't know. MAC address is derived from the serial number but, as you say, can be spoofed. Plus not every Pi has one and there are duplicate serial numbers in the wild.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

User avatar
rpdom
Posts: 14151
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Protect python code to prevent copy

Fri May 17, 2019 12:18 pm

thagrol wrote:
Fri May 17, 2019 11:57 am
Andyroo wrote:
Fri May 17, 2019 11:46 am
There is no hardware encryption chip built into the Pi and if I remember correctly the serial number can be changed as can the MAC address.
The serial number is in the OTP so can't be reprogrammed but it may be possible to spoof it, I don't know.
It is possible to spoof the serial number if is read from /proc/cpuinfo, but if you go low-level and access it using the mailbox method (probably requires some C code or similar) it would be very difficult to fake.
Signature is on holiday.

Andyroo
Posts: 2956
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Protect python code to prevent copy

Fri May 17, 2019 12:24 pm

The MPG2 licences are based on serial numbers thinking about it but I’m sure there was a thread where a set of duplicated SD cards gave issues of duplicated serial numbers. DuckDuck is not good for me today to find it though :cry:

There is an article https://www.zymbit.com/securing-raspberry-pi/ on securing the Pi - their dongles are about £33 but you still have the language issue with python.
Need Pi spray - these things are breeding in my house...

Brandon92
Posts: 769
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Protect python code to prevent copy

Fri May 17, 2019 11:23 pm

Maybe this link will give you some information. But I'm not an expert on this topic.

https://wiki.python.org/moin/Asking%20f ... %20code%3F

BeauSlim
Posts: 30
Joined: Mon Jul 31, 2017 10:02 am

Re: Protect python code to prevent copy

Sat May 18, 2019 6:44 am

The first question to ask in a situation like this is, "Why?" Is your code actually worth protecting?

Compiling to binary and using obfuscators along with a net-linked license key scheme will stop non-technical users from casually copying your software, but any motivated geek will be able to decompile your code and crack your licensing, no matter what language you write it in.

Depending on your prospective customer base (i.e. business vs consumer), spending time and energy on properly written contracts, license agreements, registered copyrights, and patents might be more important than trying to hide your code.

User avatar
thagrol
Posts: 1479
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Protect python code to prevent copy

Sat May 18, 2019 9:05 am

BeauSlim wrote:
Sat May 18, 2019 6:44 am
Depending on your prospective customer base (i.e. business vs consumer), spending time and energy on properly written contracts, license agreements, registered copyrights, and patents might be more important than trying to hide your code.
Or do whaat many in the open source world do: charge for support not software
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Return to “General discussion”