chiark / gitweb /
keys/tripe-keys.in: Only warn if all master keys are expired.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 12 Jul 2013 09:32:11 +0000 (10:32 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 12 Jul 2013 09:43:34 +0000 (10:43 +0100)
Otherwise you get pestered throughout the rollover period.

keys/tripe-keys.in

index ad8671e..47a4417 100644 (file)
@@ -498,22 +498,34 @@ def cmd_clean(args):
 ###--------------------------------------------------------------------------
 ### Commands: check
 
-def cmd_check(args):
+def check_key(k):
   now = T.time()
   thresh = int(conf['kx-warn-days']) * 86400
-  for krf in ['master', 'keyring.pub']:
-    if not OS.path.exists(krf): continue
-    kr = C.KeyFile(krf)
-    for k in kr.itervalues():
-      if k.exptime == C.KEXP_FOREVER: continue
-      elif k.exptime == C.KEXP_EXPIRE: left = -1
-      else: left = k.exptime - now
-      if left < 0:
-        print "key `%s' HAS EXPIRED" % k.tag
-      elif left < thresh:
-        if left >= 86400: n, u, uu = left // 86400, 'day', 'days'
-        else: n, u, uu = left // 3600, 'hour', 'hours'
-        print "key `%s' EXPIRES in %d %s" % (k.tag, n, n == 1 and u or uu)
+  if k.exptime == C.KEXP_FOREVER: return None
+  elif k.exptime == C.KEXP_EXPIRE: left = -1
+  else: left = k.exptime - now
+  if left < 0:
+    return "key `%s' HAS EXPIRED" % k.tag
+  elif left < thresh:
+    if left >= 86400: n, u, uu = left // 86400, 'day', 'days'
+    else: n, u, uu = left // 3600, 'hour', 'hours'
+    return "key `%s' EXPIRES in %d %s" % (k.tag, n, n == 1 and u or uu)
+  else:
+    return None
+
+def cmd_check(args):
+  if OS.path.exists('keyring.pub'):
+    for k in C.KeyFile('keyring.pub').itervalues():
+      whinge = check_key(k)
+      if whinge is not None: print whinge
+  if OS.path.exists('master'):
+    whinges = []
+    for k in C.KeyFile('master').itervalues():
+      whinge = check_key(k)
+      if whinge is None: break
+      whinges.append(whinge)
+    else:
+      for whinge in whinges: print whinge
 
 ###--------------------------------------------------------------------------
 ### Commands: mtu