Created
June 19, 2011 03:53
-
-
Save elricstorm/1033742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import sys | |
import base64 | |
import urllib | |
from M2Crypto import BIO, RSA, EVP | |
pem = """-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCt8WGFD2HH1sHbdtrZ0MspHueVDb2vjk2G11qLoxZiTehfRTmlKivFMkdC/4PMtF73Z4kjHDr+7lU9b4DmkcNyZ03DsrRtudY9cGWh0cYCCsODjScjSCKpfTPUj/3Rxe6hcqhfIWw3XuduaALBnT31NR499Qodp859RnBpuwSieQIDAQAB-----END PUBLIC KEY-----""" | |
bio = BIO.MemoryBuffer(pem) | |
rsa = RSA.load_pub_key_bio(bio) | |
pubkey = EVP.PKey() | |
pubkey.assign_rsa(rsa) | |
if len(sys.argv) == 2: | |
qs = sys.argv[1]; | |
signature= base64.decodestring(urllib.unquote(re.match(r".*signature=([Verify signature^&]*).*",qs).group(1))) | |
qs = re.compile("signature=[Verify signature^&]*").sub("signature=",qs) | |
print "\nUsing the following publickey:" | |
print pem | |
print "\nVerifying the signature of the following query string:" | |
print "[" + qs + "]" | |
pubkey.reset_context(md='sha1') | |
pubkey.verify_init() | |
pubkey.verify_update(qs) | |
if pubkey.verify_final(signature) == 1: | |
print "\nRESULT:signature is valid" | |
sys.exit(0) | |
else: | |
print "\nRESULT:could not verify signature" | |
sys.exit(1) | |
else: | |
print "must specify the querystring as an argument" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment