#!/bin/python2 import web from time import sleep import hashlib import hmac urls = ( '/', 'index' ) class crypto: def __init__(self): self.key = "bummbamm" def insecure_compare(self, hmac_arg, filename, key): print hmac_arg print filename com_hmac = hmac.new(key, filename, hashlib.sha1).digest() com_hmac = com_hmac.encode("hex") print com_hmac for i in range(len(hmac_arg)): if hmac_arg[i] == com_hmac[i]: sleep(0.05) else: break return 200 class index(): def GET(self): cry = crypto() print cry.key f = web.input() back = f["file"] + " : " + f["signature"] cry.insecure_compare(f["signature"], f["file"], cry.key) print f return back if __name__ == "__main__": app = web.application(urls, globals()) app.run()