在Python中使用时间戳作为许可证过期时间安全吗?
我在我的图形用户界面(GUI)Python代码中插入了以下几行
if time.time() > 1408492800: # 20-Aug-2014 at midnight
disp("licence expired!")
else:
root = Tk()
app = App(root)
root.mainloop()
这样做安全吗?有没有其他方法可以防止人们在8月20日之后使用这段代码?还有没有其他人可能找到解决办法呢?
我忘了说,我打算在Windows系统下编译这个。
2 个回答
0
time模块使用的是系统时钟,所以用户可以通过改变他们的系统时钟来绕过你的应用程序。这实际上很可能是用户在他们的许可证到期后会尝试的第一件事。
为了防止用户绕过你的检查,你需要去检查一个可信的远程服务器上的时间。这个服务器可以是你自己搭建的,也可以是其他可信的远程服务器,只要它能在请求时提供准确的时间就行。
0
我想我找到了解决自己问题的一个不错的方法,使用了以下这篇帖子,适用于Python 2.7。你可以在这里查看这篇帖子:用Python获取网页内容?。同时,我还使用了这个网页应用:http://just-the-time.appspot.com/?f=%Y%m%d,%20seconds%20since%20the%20epoch:%20%t,具体做法如下:
# find the current time
try:
pagina = urllib.urlopen('http://just-the-time.appspot.com/?f=%Y%m%d,%20seconds%20since%20the%20epoch:%20%t')
tempo = pagina.read()
real_time = tempo[35:48]
except IOError:
exit()
if (time.time() > 1408492800) or (float(real_time) > 1408492800): # 20 August 2014 at 00:00
disp("License expired!")
else:
root = Tk()
app = App(root)
root.mainloop()