Created
April 6, 2016 21:17
-
-
Save gdestuynder/6c264ad132383a74309131af0665cfc7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import sys | |
import os | |
import subprocess | |
def getfp(userid): | |
data=subprocess.check_output(['gpg', '--fingerprint',userid]) | |
data=data.decode('ascii', 'ignore') | |
fp=data.split('fingerprint')[1].split('\n')[0].split('=')[1] | |
fp='0x'+fp.replace(' ', '') | |
return fp | |
with open(sys.argv[1]) as fd: | |
raw=fd.read() | |
lista=raw.split('gpg: ') | |
listb = {} | |
again=False | |
for i in lista: | |
if not i.startswith('encrypted'): | |
continue | |
print(i) | |
userid='0x'+i.split('ID 0x')[1].split(',')[0].strip('\n') | |
try: | |
usermail=i.split('>')[-2].split('<')[-1] | |
except IndexError: | |
os.system('gpg --recv-key '+userid) | |
usermail=userid | |
again=True | |
listb[usermail]=userid | |
if again: | |
print("Please export the file again, i imported missing keys") | |
sys.exit(1) | |
out = '' | |
for i in listb: | |
print(i, getfp(listb[i])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment