I am looking to sell some software that I have written in Python. My interface allows the user to submit their license key and save it locally. The program revolves around one button in the interface which runs the program. My idea was to create a HTTPS API (probably using Flask since I know how to use it) on an AWS EC2 server. Then, whenever the user clicks the button to run the server, the program retrieves their locally stored license key and makes a GET request to the server. The server then checks for the existence of that key in the database, and if it exists then it returns True, otherwise it returns False. Then the local program will run the program if True is returned, otherwise it will tell the user that their key is invalid.
I am aware that this is not particularly secure. The main reason I see is that with Python, the user can just go into my .py file and set the boolean to always be True, or just remove the check entirely. And so, I thought I might be able to combat that by using py2exe, although unpy2exe exists. pyarmor also seems like an option, but I think some tools might exist to crack it such as this one.
Even if I am able to prevent the user from accessing the code, is it not possible for them to change the response from the server and change it to True? Even if it is HTTPS?
I also have the issue that I would only like the user to be able to use my program on one computer at a time. I thought of storing their MAC address, but I know that can be easily spoofed, so I'm not really sure how to go about implementing that.
Some might say that this is going overboard, and if someone wants to crack my software then they will do so. However, this program will be quite expensive and will be sold into a market in which cracking is quite common. Therefore, I would really like to do my best to make it as difficult as possible.
So, does anyone know how I could create a secure licensing system for my program? At least just a general outline would be extremely helpful.
Thanks.
EDIT: With regards to securely generating license keys, how is something like this if I make sure it doesn't already exist?
from base64 import b64encode
from os import urandom
random_bytes = urandom(32)
license = b64encode(random_bytes).decode('utf-8')
EDIT2: Surely there must be some sort of industry standard for licensing software, regardless of whether or not it is coded in Python? How do they do it?