Last active
January 4, 2022 09:03
-
-
Save ObjectBoxPC/b721b15d9ec197bc3980b0efa31353aa to your computer and use it in GitHub Desktop.
Dump payload from a SMART Health Card https://smarthealth.cards/
This file contains 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
# This code is dedicated to the public domain under | |
# Creative Commons CC0 1.0 Universal <https://creativecommons.org/publicdomain/zero/1.0/> | |
import base64 | |
import json | |
import sys | |
import zlib | |
shc = input() | |
SHC_PREFIX = "shc:/" | |
def get_numbers(digits): | |
for i in range(0, len(digits), 2): | |
yield int(digits[i:i+2]) | |
if not shc.startswith(SHC_PREFIX): | |
print("Invalid: Does not start with required prefix") | |
sys.exit(1) | |
shc_digits = shc[len(SHC_PREFIX):] | |
if "/" in shc_digits: | |
print("Unsupported: Multi-segment code") | |
sys.exit(1) | |
if len(shc_digits) % 2 != 0: | |
print("Invalid: Odd number of digits") | |
sys.exit(1) | |
jwt_text = "".join(chr(x + 45) for x in get_numbers(shc_digits)) | |
jwt_components = jwt_text.split(".") | |
payload_component = jwt_components[1] | |
padded_base64_payload = payload_component + ("=" * (4 - len(payload_component) % 4)) | |
compressed_payload = base64.urlsafe_b64decode(padded_base64_payload) | |
payload = zlib.decompress(compressed_payload, wbits=-15) | |
print(json.dumps(json.loads(payload.decode("UTF-8")), indent="\t")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment