Created
July 12, 2012 14:15
-
-
Save jbowes/3098392 to your computer and use it in GitHub Desktop.
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
import base64 | |
import zlib | |
import json | |
def decompress_payload(payload): | |
""" | |
Certificate payloads arrive in base64 encoded zlib compressed strings | |
of JSON. | |
This method decodes, de-compressed, parses the JSON and returns the | |
resulting dict. | |
""" | |
decoded = base64.decodestring(payload) | |
f = open("output", 'w') | |
f.write(decoded) | |
f.close() | |
decompr = zlib.decompressobj() | |
x = 0 | |
y = 100 | |
while y < len(decoded): | |
print decompr.decompress(decoded[x:y]) | |
x = y | |
y += 100 | |
# decompressed = zlib.decompress(decoded) | |
# print "Decompressed:" | |
# print decompressed | |
# return json.loads(decompressed) | |
payload = open("b64", 'r').read() | |
decompress_payload(payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment