summaryrefslogtreecommitdiff
path: root/versign.py
blob: aa406dfe7582fbca706f86a7eceda430ce9e523e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)'