Created
January 13, 2016 10:46
-
-
Save yuvadm/a5d196a5f6bbc0404d93 to your computer and use it in GitHub Desktop.
Unwrap gov.il signed documents
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
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