aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gkeys-ldap/gkeyldap/actions.py1
-rw-r--r--gkeys-ldap/gkeyldap/search.py2
-rw-r--r--gkeys/gkeys/actions.py26
-rw-r--r--gkeys/gkeys/base.py2
-rw-r--r--gkeys/gkeys/gkey.py6
-rw-r--r--gkeys/gkeys/lib.py4
-rw-r--r--gkeys/gkeys/seed.py4
-rw-r--r--gkeys/gkeys/seedhandler.py27
8 files changed, 47 insertions, 25 deletions
diff --git a/gkeys-ldap/gkeyldap/actions.py b/gkeys-ldap/gkeyldap/actions.py
index 1c499aa..45fff09 100644
--- a/gkeys-ldap/gkeyldap/actions.py
+++ b/gkeys-ldap/gkeyldap/actions.py
@@ -181,6 +181,7 @@ class Actions(object):
# drop keyid and longkeyid
keyinfo.pop('keyid', None)
keyinfo.pop('longkeyid', None)
+ keyinfo['keys'] = keyinfo['fingerprint']
return keyinfo
return None
diff --git a/gkeys-ldap/gkeyldap/search.py b/gkeys-ldap/gkeyldap/search.py
index 1bce9e1..c13527f 100644
--- a/gkeys-ldap/gkeyldap/search.py
+++ b/gkeys-ldap/gkeyldap/search.py
@@ -64,5 +64,7 @@ class LdapSearch(object):
for entry in results:
info = entry[1]
key_value = info[key][0]
+ if key_value in ['fingerprint']:
+ _dict['keys'] = info
_dict[key_value] = info
return _dict
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 6f8fa11..b63f3f1 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -272,13 +272,17 @@ class Actions(object):
'''Add or replace a key in the selected seed file'''
handler = SeedHandler(self.logger, self.config)
gkeys = self.listseed(args)[1]
- if not args.nick or not args.name or not args.fingerprint:
- return (False, ["Provide a nickname, a name and a fingerprint."])
+ if not args.nick or not args.name or not args.keys or not args.keydir:
+ return (False, ["Provide a nickname, a name and a public key fingerprint (-K, --keys)."])
+ if not args.fingerprint:
+ args.fingerprint = args.keys
+ if args.uid is None:
+ args.uid = []
gkey = handler.new(args, checkgkey=True)
if not gkey:
return (False, ["Failed to create a valid GKEY instance.",
"Check for invalid data entries"])
- if len(gkeys) == 0:
+ if len(gkeys[1]) == 0:
self.logger.debug("ACTIONS: installkey; now adding gkey: %s" % str(gkey))
success = self.seeds.add(getattr(gkey, 'nick'), gkey)
if success:
@@ -499,12 +503,12 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Checking keys...')
for gkey in sorted(keyresults):
- self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keyid))
+ self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.pub_keyid))
self.output('',
- "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.keyid)) +
+ "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.pub_keyid)) +
"\n ==============================================")
self.logger.debug("ACTIONS: checkkey; gkey = %s" % str(gkey))
- for key in gkey.keyid:
+ for key in gkey.pub_keyid:
results[gkey.name] = self.gpg.check_keys(gkey.keydir, key)
if results[gkey.name].expired:
failed['expired'].append("%s <%s>: %s" % (gkey.name, gkey.nick, key))
@@ -547,12 +551,12 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Checking keys...')
for gkey in sorted(keyresults):
- self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keyid))
+ self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keys))
self.output('',
- "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.keyid)) +
+ "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.pub_keyid)) +
"\n ==============================================")
self.logger.debug("ACTIONS: speccheck; gkey = %s" % str(gkey))
- for key in gkey.keyid:
+ for key in gkey.keys:
results = self.gpg.speccheck(gkey.keydir, key)
for g in results:
pub_pass = {}
@@ -990,8 +994,8 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Refreshig keys...')
for gkey in sorted(keyresults):
- self.logger.info("Refreshig key %s, %s" % (gkey.nick, gkey.keyid))
- self.output('', " %s: %s" % (gkey.name, ', '.join(gkey.keyid)))
+ self.logger.info("Refreshig key %s, %s" % (gkey.nick, gkey.pub_keyid))
+ self.output('', " %s: %s" % (gkey.name, ', '.join(gkey.pub_keyid)))
#self.output('', " ===============")
self.logger.debug("ACTIONS: refreshkey; gkey = %s" % str(gkey))
results[gkey.keydir] = self.gpg.refresh_key(gkey)
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 9d47fe0..05946c2 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -186,7 +186,7 @@ class CliBase(object):
@staticmethod
def _option_uid(parser=None):
- parser.add_argument('-u', '--uid', dest='uid', nargs='*', default=None,
+ parser.add_argument('-u', '--uid', dest='uid', nargs='+', default=None,
help='The user ID, gpg key uid')
diff --git a/gkeys/gkeys/gkey.py b/gkeys/gkeys/gkey.py
index 130a5d5..a305804 100644
--- a/gkeys/gkeys/gkey.py
+++ b/gkeys/gkeys/gkey.py
@@ -45,6 +45,12 @@ class GKEY(namedtuple('GKEY', ['nick', 'name', 'keydir', 'keys', 'fingerprint',
@property
+ def pub_keyid(self):
+ '''Keyid is a substring value of the keys fingerprints'''
+ return ['0x' + x[-16:] for x in self.keys]
+
+
+ @property
def pretty_print(self):
'''Pretty printing a GKEY'''
gkey = {
diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 6bb3d5b..6020322 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -136,14 +136,14 @@ class GkeysGPG(GPG):
ensure_dirs(str(self.keydir), mode=mode)
self.set_keyseedfile(trap_errors=False)
results = []
- for fingerprint in gkey.fingerprint:
+ for fingerprint in gkey.keys:
self.logger.debug("LIB: add_key; adding fingerprint " + fingerprint)
self.logger.debug("** Calling runGPG with Running 'gpg %s --recv-keys %s' for: %s"
% (' '.join(self.config.get_key('tasks', 'recv-keys')),
fingerprint, gkey.name))
result = self.runGPG(task='recv-keys', inputfile=fingerprint)
self.logger.info('GPG return code: ' + str(result.returncode))
- if result.fingerprint in gkey.fingerprint:
+ if result.fingerprint in gkey.keys:
result.failed = False
message = "Fingerprints match... Import successful: "
message += "%s, fingerprint: %s" % (gkey.nick, fingerprint)
diff --git a/gkeys/gkeys/seed.py b/gkeys/gkeys/seed.py
index 15c9e2c..7d9ae4e 100644
--- a/gkeys/gkeys/seed.py
+++ b/gkeys/gkeys/seed.py
@@ -139,9 +139,9 @@ class Seeds(object):
keys = kwargs
result = self.seeds
for key in keys:
- if key in ['fingerprint', 'keyid']:
+ if key in ['fingerprint', 'keys', 'keyid']:
kwargs[key] = [x.replace(' ', '').upper() for x in kwargs[key]]
- if key in ['fingerprint']:
+ if key in ['fingerprint', 'keys', 'uid']:
result = {dev: gkey for dev, gkey in list(result.items()) if kwargs[key][0] in getattr(gkey, key)}
elif key in ['keyid']:
searchids = [x.lstrip('0X') for x in kwargs[key]]
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index 9540ee0..600ac35 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -48,12 +48,12 @@ class SeedHandler(object):
@staticmethod
def build_gkeydict(args):
keyinfo = {}
- for attr in GKEY._fields + ('keyid',):
+ for attr in GKEY._fields:
try:
value = getattr(args, attr)
if attr == 'name' and value:
value = " ".join(value)
- if value:
+ if value is not None:
keyinfo[attr] = value
except AttributeError:
pass
@@ -171,21 +171,30 @@ class SeedHandler(object):
try:
args['keydir'] = args.get('keydir', args['nick'])
fprs = []
- if args['fingerprint']:
- for fpr in args['fingerprint']:
+ keys = []
+ if args['keys'] or args['fingerprint']:
+ for fpr in args['keys']:
is_good, fingerprint = self._check_fingerprint_integrity(fpr)
if is_good:
- fprs.append(fingerprint)
+ keys.append(fingerprint)
else:
- self.logger.error('Bad fingerprint from command line args: %s' % fpr)
+ self.logger.error('Bad key from command line args: %s' % fpr)
if is_good:
- args['fingerprint'] = fprs
+ args['keys'] = keys
+ for fpr in args['fingerprint']:
+ is_good, fingerprint = self._check_fingerprint_integrity(fpr)
+ if is_good:
+ fprs.append(fingerprint)
+ else:
+ self.logger.error('Bad fingerprint from command line args: %s' % fpr)
+ if is_good:
+ args['fingerprint'] = fprs
except KeyError:
self.logger.error('GPG fingerprint not found.')
is_good = False
if not is_good:
- self.logger.error('A valid fingerprint '
- 'was not found for %s' % args['name'])
+ self.logger.error('An invalid key or fingerprint '
+ 'was found for %s' % args['name'])
return args, is_good
def _check_fingerprint_integrity(self, fpr):