Created
March 25, 2020 08:55
-
-
Save mherrmann/94c2e0f0d936e4fd596302ac47e3f66a to your computer and use it in GitHub Desktop.
digistore python validate thank you page
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
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