Skip to content

Instantly share code, notes, and snippets.

@yuvadm
Created January 13, 2016 10:46
Show Gist options
  • Save yuvadm/a5d196a5f6bbc0404d93 to your computer and use it in GitHub Desktop.
Save yuvadm/a5d196a5f6bbc0404d93 to your computer and use it in GitHub Desktop.
Unwrap gov.il signed documents
from base64 import b64decode
from os import listdir
from sys import argv
from xml.dom.minidom import parse
def unsign(filenames):
for f in filenames:
try:
dom = parse(f)
except IOError:
print('File %s not found' % f)
continue
docid = f.split('.')[0]
signed_info = dom.getElementsByTagName('gov.il:SignedInfo')[0]
data = signed_info.childNodes[0].childNodes[0].data
orig_filename = signed_info.childNodes[1].childNodes[0].childNodes[0].data
outfile = '[%s] %s' % (docid, orig_filename)
with open(outfile, 'wb') as out:
out.write(b64decode(data))
if __name__ == '__main__':
if len(argv) < 2:
print('Usage: python unsign.py <filename> [filename] ...')
exit(-1)
unsign(argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment