import M2Crypto.RSA import M2Crypto.EVP import time, sys import base64, cgi str = sys.argv[1] data = cgi.parse_qs(str) ts = int(data['ts'][0]) user = data['user'][0] signature = base64.urlsafe_b64decode(data['signature'][0]) data = '%d:%s' % (ts, user) algo = 'sha256' digest = M2Crypto.EVP.MessageDigest(algo) digest.update(data) digval = digest.final() key = M2Crypto.RSA.load_pub_key('rsa.pub') try: if key.verify(digval, signature, algo = algo): print 'OKAY' else: print 'FAIL' except: print 'FAIL (hard)'