我正在用Python开发一款软件,它将分发给我雇主的客户。我的雇主想用一个有时间限制的许可证文件来限制软件的使用。
如果我们分发.py文件甚至.pyc文件,将很容易(反编译和)删除检查许可证文件的代码。
另一个方面是,我的雇主不希望我们的客户读到代码,担心代码可能被窃取,或者至少是“新颖的想法”。
有什么好办法来解决这个问题吗?
我正在用Python开发一款软件,它将分发给我雇主的客户。我的雇主想用一个有时间限制的许可证文件来限制软件的使用。
如果我们分发.py文件甚至.pyc文件,将很容易(反编译和)删除检查许可证文件的代码。
另一个方面是,我的雇主不希望我们的客户读到代码,担心代码可能被窃取,或者至少是“新颖的想法”。
有什么好办法来解决这个问题吗?
当前回答
保护代码的唯一可靠方法是在您控制的服务器上运行它,并为您的客户机提供与该服务器接口的客户机。
其他回答
虽然没有完美的解决方案,但可以做到以下几点:
将一些关键的启动代码移到本地库中。 在本机库中执行许可证检查。
如果要删除对本机代码的调用,程序无论如何都不会启动。如果它没有被删除,那么许可证将被强制执行。
虽然这不是一个跨平台的或纯python的解决方案,但它可以工作。
“有没有解决这个问题的好办法?”不。没有什么可以防止逆向工程。甚至DVD机器上的固件也被逆向工程,AACS加密密钥被暴露。这还是不顾DMCA规定的刑事犯罪。
由于没有任何技术方法可以阻止客户阅读您的代码,所以您必须应用普通的商业方法。
Licenses. Contracts. Terms and Conditions. This still works even when people can read the code. Note that some of your Python-based components may require that you pay fees before you sell software using those components. Also, some open-source licenses prohibit you from concealing the source or origins of that component. Offer significant value. If your stuff is so good -- at a price that is hard to refuse -- there's no incentive to waste time and money reverse engineering anything. Reverse engineering is expensive. Make your product slightly less expensive. Offer upgrades and enhancements that make any reverse engineering a bad idea. When the next release breaks their reverse engineering, there's no point. This can be carried to absurd extremes, but you should offer new features that make the next release more valuable than reverse engineering. Offer customization at rates so attractive that they'd rather pay you to build and support the enhancements. Use a license key which expires. This is cruel, and will give you a bad reputation, but it certainly makes your software stop working. Offer it as a web service. SaaS involves no downloads to customers.
如果我们关注软件许可,我建议看看我在这里写的另一个Stack Overflow答案,以获得如何构建许可密钥验证系统的灵感。
GitHub上有一个开源库,可以帮助您进行许可证验证。
你可以通过pip安装许可来安装它,然后添加以下代码:
pubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
res = Key.activate(token="WyIyNTU1IiwiRjdZZTB4RmtuTVcrQlNqcSszbmFMMHB3aWFJTlBsWW1Mbm9raVFyRyJd",\
rsa_pub_key=pubKey,\
product_id=3349, key="ICVLD-VVSZR-ZTICT-YKGXL", machine_code=Helpers.GetMachineCode())
if res[0] == None not Helpers.IsOnRightMachine(res[0]):
print("An error occured: {0}".format(res[1]))
else:
print("Success")
你可以在这里阅读更多关于RSA公钥等配置方式的信息。
发布.pyc文件有它的问题-它们与创建它们时使用的python版本以外的任何其他python版本都不兼容,这意味着您必须知道产品将运行的系统上运行的python版本。这是一个非常有限的因素。
不要依赖混淆。正如你的正确结论,它提供的保护非常有限。 更新:这里有一个论文的链接,它在Dropbox中逆向工程混淆的python代码。操作码重映射方法是一个很好的障碍,但显然它是可以被击败的。
相反,正如许多海报所提到的那样:
不值得花时间进行逆向工程(你的软件这么好,花钱是有意义的) 如果可行的话,让他们签订合同并进行许可证审核。
或者,就像强大的Python IDE WingIDE所做的那样:放弃代码。没错,把代码送出去,让人们回来进行升级和支持。