From dbd6861ec6e35b1ce8862303ca16021e86276a7d Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Tue, 16 Jul 2013 18:52:30 -0700 Subject: [PATCH] Change to make keys install to individual directories. Git has no options to set the git keydir or keyring. Must set GNUPGHOME env variable to the desired keydir before calling git log --show-signature to verify commits. --- gkeyldap/search.py | 6 ++--- gkeys/actions.py | 14 +++++------ gkeys/cli.py | 10 ++++---- gkeys/config.py | 4 ++-- gkeys/lib.py | 60 ++++++++++++++++++++++++++-------------------- 5 files changed, 51 insertions(+), 43 deletions(-) diff --git a/gkeyldap/search.py b/gkeyldap/search.py index f7d2045..92471df 100644 --- a/gkeyldap/search.py +++ b/gkeyldap/search.py @@ -21,9 +21,9 @@ gkey2ldap_map = { 'name': 'cn', 'keyid': 'gpgkey', 'longkeyid': 'gpgkey', - # map the uid to keyring, since we want - # dev keyrings to be separate from each other - 'keyring': 'uid', + # map the uid to keydir, since we want + # dev keydir to be separate from each other + 'keydir': 'uid', 'fingerprint': 'gpgfingerprint' } # Sanity check they are in sync diff --git a/gkeys/actions.py b/gkeys/actions.py index 9873362..7efcd44 100644 --- a/gkeys/actions.py +++ b/gkeys/actions.py @@ -190,25 +190,25 @@ class Actions(object): #failed = [] print(" GPG output:") for key in keyresults: - if not key.keyring and not args.nick == '*': - self.logger.debug("ACTIONS: listkey; NO keyring... Ignoring") + if not key.keydir and not args.nick == '*': + self.logger.debug("ACTIONS: listkey; NO keydir... Ignoring") return {"Failed: No keyid's found for %s" % key.name : ''} - self.logger.debug("ACTIONS: listkey; listing keyring:" - + str(key.keyring)) - results[key.name] = self.gpg.list_keys(key.keyring) + self.logger.debug("ACTIONS: listkey; listing keydir:" + + str(key.keydir)) + results[key.name] = self.gpg.list_keys(key.keydir) if self.config.options['print_results']: print(results[key.name].output) self.logger.debug("data output:\n" + str(results[key.name].output)) #for result in results[key.name].status.data: - #print("key desired:", key.name, ", keyring listed:", + #print("key desired:", key.name, ", keydir listed:", #result) #self.logger.debug("data record: " + str(result)) else: return results return {'done': True} else: - return {"No keyrings to list": False} + return {"No keydirs to list": False} def addkey(self, args): diff --git a/gkeys/cli.py b/gkeys/cli.py index d34ed4d..46344f9 100644 --- a/gkeys/cli.py +++ b/gkeys/cli.py @@ -67,12 +67,12 @@ class Main(object): be hazardous to your system!''') # actions parser.add_argument('action', choices=actions, nargs='?', - default='listseeds', help='Add to seed file or keyring') + default='listseeds', help='List the seeds in the file') # options parser.add_argument('-c', '--config', dest='config', default=None, help='The path to an alternate config file') parser.add_argument('-d', '--dest', dest='destination', default=None, - help='The destination seed file or keyring for move, copy operations') + help='The destination seed file or keydir for move, copy operations') parser.add_argument('-f', '--fingerprint', dest='fingerprint', default=None, help='The fingerprint of the the key') parser.add_argument('-N', '--name', dest='name', default=None, @@ -83,9 +83,9 @@ class Main(object): help='The keyid of the the key') parser.add_argument('-l', '--longkeyid', dest='longkeyid', default=None, help='The longkeyid of the the key') - parser.add_argument('-r', '--keyring', - choices=['release', 'dev', 'overlays'], dest='keyring', default=None, - help='The keyring to use or update') + parser.add_argument('-r', '--keydir', + choices=['release', 'dev', 'overlays'], dest='keydir', default=None, + help='The keydir to use or update') parser.add_argument('-s', '--seeds', choices=['release', 'dev'], dest='seeds', default=None, help='The seeds file to use or update') diff --git a/gkeys/config.py b/gkeys/config.py index 043f84f..96b4aee 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -97,11 +97,11 @@ class GKeysConfig(GPGConfig): class GKEY(namedtuple('GKEY', ['nick', 'name', 'keyid', 'longkeyid', - 'keyring', 'fingerprint'])): + 'keydir', 'fingerprint'])): '''Class to hold the relavent info about a key''' field_types = {'nick': str, 'name': str, 'keyid': list, - 'longkeyid': list, 'keyring': str, 'fingerprint': list} + 'longkeyid': list, 'keydir': str, 'fingerprint': list} field_separator = "|" list_separator = ":" __slots__ = () diff --git a/gkeys/lib.py b/gkeys/lib.py index 0420f7c..a97b7e7 100644 --- a/gkeys/lib.py +++ b/gkeys/lib.py @@ -30,12 +30,13 @@ class GkeysGPG(GPG): '''class init function @param config: GKeysConfig config instance to use - @param keyring: string, the path to the keydir to be used + @param keydir: string, the path to the keydir to be used for all operations. ''' GPG.__init__(self, config) self.config = config - self.keydir = keydir + self.basedir = keydir + self.keydir = None self.task = None self.task_value = None @@ -60,13 +61,20 @@ class GkeysGPG(GPG): self.task_value = None + def set_keydir(self, keydir): + logger.debug("basedir: %s, keydir: %s" % (self.basedir, keydir)) + self.task = task + self.keydir = pjoin(self.basedir, keydir) + return + + def add_key(self, gkey): - '''Add the specified key to the specified keyring + '''Add the specified key to the specified keydir @param gkey: GKEY namedtuple with - (name, keyid/longkeyid, keyring, fingerprint,) + (name, keyid/longkeyid, keydir, fingerprint,) ''' - self.set_keypath(gkey.keyring, self.config['tasks']['recv-keys']) + self.set_keydir(gkey.keydir) # prefer the longkeyid if available #logger.debug("LIB: add_key; keyids %s, %s" @@ -105,60 +113,60 @@ class GkeysGPG(GPG): return results - def del_key(self, gkey, keyring): - '''Delete the specified key to the specified keyring + def del_key(self, gkey, keydir): + '''Delete the specified key in the specified keydir @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint) ''' return [] - def del_keyring(self, keyring): - '''Delete the specified key to the specified keyring + def del_keydir(self, keydir): + '''Delete the specified keydir ''' return [] - def update_key(self, gkey, keyring): - '''Update the specified key in the specified keyring + def update_key(self, gkey, keydir): + '''Update the specified key in the specified keydir @param key: tuple of (name, keyid, fingerprint) - @param keyring: the keyring to add the key to + @param keydir: the keydir to add the key to ''' return [] - def list_keys(self, keyring): - '''List all keys in the specified keyring or - all key in all keyrings if keyring=None + def list_keys(self, keydir): + '''List all keys in the specified keydir or + all keys in all keydir if keydir=None - @param keyring: the keyring to add the key to + @param keydir: the keydir to list the keys for ''' - if not keyring: - logger.debug("LIB: list_keys(), invalid keyring parameter: %s" - % str(keyring)) + if not keydir: + logger.debug("LIB: list_keys(), invalid keydir parameter: %s" + % str(keydir)) return [] if '--with-colons' in self.config['tasks']['list-keys']: self.config['tasks']['list-keys'].remove('--with-colons') - self.set_keypath(keyring, self.config['tasks']['list-keys']) + self.set_keydir(keydir) logger.debug("** Calling runGPG with Running 'gpg %s --list-keys %s'" - % (' '.join(self.config['tasks']['list-keys']), keyring) + % (' '.join(self.config['tasks']['list-keys']), keydir) ) - result = self.runGPG(task='list-keys', inputfile=keyring) + result = self.runGPG(task='list-keys') logger.info('GPG return code: ' + str(result.returncode)) - self.reset_task() + #self.reset_task() return result - def list_keyrings(self): - '''List all available keyrings + def list_keydirs(self): + '''List all available keydirs ''' return [] def verify_key(self, gkey): - '''verify the specified key from the specified keyring + '''verify the specified key from the specified keydir @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint) ''' -- 2.26.2