Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeyldap/
Date: Sun, 10 Nov 2013 01:01:16
Message-Id: 1384031848.e03d9b800d54c7d36ce72821761debc479c0a318.dol-sen@gentoo
1 commit: e03d9b800d54c7d36ce72821761debc479c0a318
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 8 04:41:26 2013 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Sat Nov 9 21:17:28 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=e03d9b80
7
8 Add more checks moving them to idividual functions.
9
10 Improve error messages and unify output for both logs and terminal output.
11
12 ---
13 gkeyldap/actions.py | 64 +++++++++++++++++++++++++++++++++++++++--------------
14 1 file changed, 48 insertions(+), 16 deletions(-)
15
16 diff --git a/gkeyldap/actions.py b/gkeyldap/actions.py
17 index 70a2ad1..ee5efd9 100644
18 --- a/gkeyldap/actions.py
19 +++ b/gkeyldap/actions.py
20 @@ -11,6 +11,7 @@
21 """
22
23 import os
24 +import re
25
26 from gkeys.config import GKEY
27 from gkeys.seed import Seeds
28 @@ -54,6 +55,7 @@ class Actions(object):
29 self.output = output
30 self.logger = logger
31 self.seeds = None
32 + self.fingerprint_re = re.compile('[0-9A-Fa-f]{40}')
33
34
35 def ldapsearch(self, args):
36 @@ -193,12 +195,15 @@ class Actions(object):
37 else:
38 value = values
39 if 'undefined' in values:
40 - self.logger.error('%s = "undefined" for %s, %s'
41 - %(field, info['uid'][0], info['cn'][0]))
42 + self.logger.error('ERROR in ldap info for: %s, %s'
43 + %(info['uid'][0],info['cn'][0]))
44 + self.logger.error(' %s = "undefined"' %(field))
45 keyinfo.append(value)
46 except KeyError:
47 - self.logger.error("Missing %s (%s) for %s, %s"
48 - %(field, x, info['uid'][0], info['cn'][0]))
49 + self.logger.error('ERROR in ldap info for: %s, %s'
50 + %(info['uid'][0],info['cn'][0]))
51 + self.logger.error(' MISSING or EMPTY ldap field ' +
52 + '[%s] GPGKey field [%s]' %(field, x))
53 if x in ['keyid', 'longkeyid']:
54 keyid_missing = True
55 keyinfo.append(None)
56 @@ -207,18 +212,45 @@ class Actions(object):
57 gpgkey = info[gkey2ldap_map['longkeyid']]
58 except KeyError:
59 gpgkey = 'Missing from ldap info'
60 - self.logger.error("A valid keyid or longkeyid was not found for")
61 - self.logger.error("developer: %s, %s : gpgkey = %s"
62 - %(info['uid'][0], info['cn'][0], gpgkey))
63 + self.logger.error('ERROR in ldap info for: %s, %s'
64 + %(info['uid'][0],info['cn'][0]))
65 + self.logger.error(' A valid keyid or longkeyid was not found '
66 + "%s : gpgkey = %s" %(info['cn'][0], gpgkey))
67 else:
68 - for x in [2, 3]:
69 - if not keyinfo[x]:
70 - continue
71 - for y in keyinfo[x]:
72 - index = len(y.lstrip('0x'))
73 - if y.lstrip('0x') not in [x[-index:] for x in keyinfo[5]]:
74 - self.logger.error('GPGKey and/or fingerprint error in' +
75 - ' ladap info for: ' + info['uid'][0])
76 - self.logger.error(str(keyinfo))
77 + if keyinfo[5]: # fingerprints exist check
78 + self._check_fingerprint_integrity(info, keyinfo)
79 + self._check_id_fingerprint_match(info, keyinfo)
80 return keyinfo
81
82 +
83 + def _check_id_fingerprint_match(self, info, keyinfo):
84 + for x in [2, 3]:
85 + # skip blank id field
86 + if not keyinfo[x]:
87 + continue
88 + for y in keyinfo[x]:
89 + index = len(y.lstrip('0x'))
90 + if y.lstrip('0x').lower() not in [x[-index:].lower() for x in keyinfo[5]]:
91 + self.logger.error('ERROR in ldap info for: %s, %s'
92 + %(info['uid'][0],info['cn'][0]))
93 + self.logger.error(' ' + str(keyinfo))
94 + self.logger.error(' GPGKey id %s not found in the '
95 + % y.lstrip('0x') + 'listed fingerprint(s)')
96 + return
97 +
98 +
99 + def _check_fingerprint_integrity(self, info, keyinfo):
100 + for x in keyinfo[5]:
101 + # check fingerprint integrity
102 + if len(x) != 40:
103 + self.logger.error('ERROR in ldap info for: %s, %s'
104 + %(info['uid'][0],info['cn'][0]))
105 + self.logger.error(' GPGKey incorrect fingerprint ' +
106 + 'length (%s) for fingerprint: %s' %(len(x), x))
107 + continue
108 + if not self.fingerprint_re.match(x):
109 + self.logger.error('ERROR in ldap info for: %s, %s'
110 + %(info['uid'][0],info['cn'][0]))
111 + self.logger.error(' GPGKey: Non hexadecimal digits in ' +
112 + 'fingerprint for fingerprint: ' + x)
113 + return