public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/, gkeys/gkeys/
Date: Mon,  5 Jan 2015 23:12:36 +0000 (UTC)	[thread overview]
Message-ID: <1420496076.1e10ed38ab63229a1dabb7d77ec386977e3a1ce5.dolsen@gentoo> (raw)

commit:     1e10ed38ab63229a1dabb7d77ec386977e3a1ce5
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  4 03:29:52 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Jan  5 22:14:36 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=1e10ed38

gkeys: Add pub_keyid property to GKEY

Actions like spec-check used keyid property which resulted in double processing and output since now all subkey fingerprints are in the fingerprint field.

Add keys field to remaining places for seedhandling
Fix add_key for the new GKEY.keys field
Add cross saving fingerprints to the new keys field

---
 gkeys-ldap/gkeyldap/actions.py |  1 +
 gkeys-ldap/gkeyldap/search.py  |  2 ++
 gkeys/gkeys/actions.py         | 26 +++++++++++++++-----------
 gkeys/gkeys/base.py            |  2 +-
 gkeys/gkeys/gkey.py            |  6 ++++++
 gkeys/gkeys/lib.py             |  4 ++--
 gkeys/gkeys/seed.py            |  4 ++--
 gkeys/gkeys/seedhandler.py     | 27 ++++++++++++++++++---------
 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):


             reply	other threads:[~2015-01-05 23:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-05 23:12 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-05 23:12 [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/, gkeys/gkeys/ Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420496076.1e10ed38ab63229a1dabb7d77ec386977e3a1ce5.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox