From: Brian Dolbec Date: Sat, 27 Jul 2013 12:43:34 +0000 (-0700) Subject: Add keyserver config option X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e27dfb1acd82f3559c91d03d36302a98fa3f14a7;p=gentoo-keys.git Add keyserver config option --- diff --git a/etc/gkeys.conf b/etc/gkeys.conf index 5b91597..46d45aa 100644 --- a/etc/gkeys.conf +++ b/etc/gkeys.conf @@ -3,6 +3,10 @@ [MAIN] +# keyserver: server to use to obtain the keys from +keyserver: pool.sks-keyservers.net + + # keysdir: base directory to store the binary keyrings and data keysdir: /var/lib/gentoo diff --git a/gkeys/config.py b/gkeys/config.py index 96b4aee..fe78dec 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -61,6 +61,7 @@ class GKeysConfig(GPGConfig): self.defaults['known-keysfile'] = '%(keysdir)s/knownkeys' self.defaults['release-seedfile'] = '%(configdir)s/release.seeds' self.defaults['dev-seedfile'] = '%(configdir)s/developer.seeds' + self.defaults['keyserver'] = 'pool.sks-keyservers.net' diff --git a/gkeys/lib.py b/gkeys/lib.py index a97b7e7..66e27dc 100644 --- a/gkeys/lib.py +++ b/gkeys/lib.py @@ -16,6 +16,7 @@ with gentoo-keys specific convienience functions. ''' +import os from os.path import join as pjoin from pyGPG.gpg import GPG @@ -33,38 +34,52 @@ class GkeysGPG(GPG): @param keydir: string, the path to the keydir to be used for all operations. ''' - GPG.__init__(self, config) + GPG.__init__(self, config, logger) self.config = config self.basedir = keydir self.keydir = None - self.task = None - self.task_value = None + self.server = None - def set_keypath(self, keyring, task=None): + def set_keyserver(self, server=None): + '''Set the keyserver and add the --keyserver option to the gpg defaults + ''' + if self.server and not server: + return + self.server = server or self.config['keyserver'] + self.config.options['gpg_defaults'] = self.config.defaults['gpg_defaults'][:] + logger.debug("keyserver: %s" % (self.server)) + server_value = ['--keyserver', self.server] + self.config.options['gpg_defaults'].extend(server_value) + logger.debug("self.config.options['gpg_defaults']: %s" + % (self.config.options['gpg_defaults'])) + return + + + def set_keyring(self, keyring, task, reset=True): + '''Sets the keyring to use as well as related task options + ''' logger.debug("keydir: %s, keyring: %s" % (self.keydir, keyring)) - self.task = task - keypath = pjoin(self.keydir, keyring) + if reset: + self.config.options['tasks'][task] = self.config.defaults['tasks'][task][:] # --keyring file | Note that this adds a keyring to the current list. # If the intent is to use the specified keyring alone, # use --keyring along with --no-default-keyring. - self.task_value = ['--no-default-keyring', '--keyring', keypath] - task.extend(self.task_value) + task_value = ['--no-default-keyring', '--keyring', keyring] + self.config.options['tasks'][task].extend(task_value) + logger.debug("set_keyring: New task options: %s" %str(self.config.options['tasks'][task])) return - def reset_task(self): - if self.task: - for item in self.task_value: - self.task.remove(item) - self.task = None - self.task_value = None - - - def set_keydir(self, keydir): + def set_keydir(self, keydir, task, reset=True): logger.debug("basedir: %s, keydir: %s" % (self.basedir, keydir)) - self.task = task self.keydir = pjoin(self.basedir, keydir) + self.task = task + if reset: + self.config.options['tasks'][task] = self.config.defaults['tasks'][task][:] + task_value = ['--homedir', self.keydir] + self.config.options['tasks'][task].extend(task_value) + logger.debug("set_keydir: New task options: %s" %str(self.config.options['tasks'][task])) return @@ -74,7 +89,11 @@ class GkeysGPG(GPG): @param gkey: GKEY namedtuple with (name, keyid/longkeyid, keydir, fingerprint,) ''' - self.set_keydir(gkey.keydir) + self.set_keyserver() + self.set_keydir(gkey.keydir, 'recv-keys', reset=True) + self.set_keyring('pubring.gpg', 'recv-keys', reset=False) + if not os.path.exists(self.keydir): + os.makedirs(self.keydir, mode=0700) # prefer the longkeyid if available #logger.debug("LIB: add_key; keyids %s, %s" @@ -89,7 +108,7 @@ class GkeysGPG(GPG): for keyid in keyids: logger.debug("LIB: add_key; final keyids" + keyid) logger.debug("** Calling runGPG with Running 'gpg %s --recv-keys %s' for: %s" - % (' '.join(self.config['tasks']['recv-keys']), + % (' '.join(self.config.get_key('tasks', 'recv-keys')), keyid, gkey.name) ) result = self.runGPG(task='recv-keys', inputfile=keyid) @@ -149,13 +168,12 @@ class GkeysGPG(GPG): if '--with-colons' in self.config['tasks']['list-keys']: self.config['tasks']['list-keys'].remove('--with-colons') - self.set_keydir(keydir) + self.set_keydir(keydir, 'list-keys') logger.debug("** Calling runGPG with Running 'gpg %s --list-keys %s'" % (' '.join(self.config['tasks']['list-keys']), keydir) ) - result = self.runGPG(task='list-keys') + result = self.runGPG(task='list-keys', inputfile=keydir) logger.info('GPG return code: ' + str(result.returncode)) - #self.reset_task() return result