Skip to content

Instantly share code, notes, and snippets.

@jbowes
Created July 12, 2012 14:15
Show Gist options
  • Save jbowes/3098392 to your computer and use it in GitHub Desktop.
Save jbowes/3098392 to your computer and use it in GitHub Desktop.
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