Skip to content

Instantly share code, notes, and snippets.

@mherrmann
Created March 25, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mherrmann/94c2e0f0d936e4fd596302ac47e3f66a to your computer and use it in GitHub Desktop.
Save mherrmann/94c2e0f0d936e4fd596302ac47e3f66a to your computer and use it in GitHub Desktop.
digistore python validate thank you page
from hashlib import sha512
from urllib.parse import parse_qs, unquote
def is_digistore_query_valid(qs, thankyou_page_key):
qs_dict = {key: unquote(value[0]) for key, value in parse_qs(qs).items()}
expected_sha = qs_dict.pop('sha_sign')
sha_string = ''
for key, value in sorted(qs_dict.items()):
sha_string += f'{key}={value}{thankyou_page_key}'
m = sha512()
m.update(sha_string.encode('utf-8'))
actual_sha = m.digest().hex().upper()
return actual_sha == expected_sha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment