You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
3.0 KiB

#!/usr/bin/env python
"""
I started writing this, and then quickly realized it would take a really long
to actually download the whole strong set this way. Then I began searching for
how to sync from key servers, which lead me to regular static key server dumps:
ftp://ftp.prato.linux.it/pub/keyring/ - Generated every Wednesday
http://keys.niif.hu/keydump/ - Generated every Monday
http://key-server.de/dump - Generated every Friday
ftp://key-server.de/dump (anonymous) - Generated every Friday
http://keyserver.borgnet.us/dump - Generated every Sunday
Right now this script is in a semi-broken state, but I decided to leave it
here anyway.
"""
import sys, time, subprocess
cwd = sys.path[0]
sys.path.append(cwd+'/lib/python-gnupg')
import gnupg
class TrollWoT_DownloadWoT:
def __init__(self, gpg, keyserver = 'pool.sks-keyservers.net'):
self.gpg = gpg
self.keyserver = keyserver
self.imported_keyids = []
keys = self.gpg.list_keys()
fingerprints = []
for key in keys:
fingerprints.append(key['fingerprint'])
self.add_keyids(fingerprints)
print 'already have {0} keys in keyring'.format(len(self.imported_keyids))
def download(self, keyids):
keyids_to_recv = []
for keyid in keyids:
if keyid not in self.imported_keyids:
keyids_to_recv.append(keyid)
print '* downloading {0} keyids: {1}'.format(len(keyids_to_recv), keyids_to_recv)
res = self.gpg.recv_keys(self.keyserver, ''.join(keyids_to_recv))
self.add_keyids(res.fingerprints)
sig_keyids = self.list_sigs(res.fingerprints)
if len(sig_keyids) > 0:
self.download(sig_keyids)
def add_keyids(self, fingerprints):
for fp in fingerprints:
keyid = fp[-16:]
if keyid not in self.imported_keyids:
self.imported_keyids.append(keyid)
def list_sigs(self, fingerprints):
keyids = []
for fp in fingerprints:
keyids.append(fp[-16:])
keyids = ' '.join(keyids)
sig_keyids = []
gpg_output = subprocess.check_output('gpg --homedir {0} --with-colons --fixed-list-mode --list-sigs {1}'.format(self.gpg.homedir, keyids), shell=True)
for line in gpg_output.split('\n'):
if line[0:4] == 'sig:':
parts = line.split(':')
keyid = parts[4]
userid = parts[8]
if userid != '[User ID not found]':
sig_keyids.append(keyid)
return sig_keyids
if __name__ == '__main__':
start_time = time.time()
print 'Download the strong set, starting with 5C17616361BD9F92422AC08BB4D25A1E99999697'
gpg = gnupg.GPG(homedir=cwd+'/homedir_download_strong_set', verbose=False)
download_wot = TrollWoT_DownloadWoT(gpg)
download_wot.download(['5C17616361BD9F92422AC08BB4D25A1E99999697'])
end_time = time.time()
time_diff = int(end_time - start_time)
print '{0} keys imported, took {1} seconds'.format(len(download_wot.imported_keyids), time_diff)