+def cmd_init(global_config, ca, certs, args):
+ ca.create()
+
+
+def cmd_gen(global_config, ca, certs, args):
+ if len(args) < 1:
+ print 'Nothing to do.'
+ for tag in args:
+ ca.generate(find_cert(certs, tag))
+
+
+def cmd_gencrl(global_config, ca, certs, args):
+ ca.gencrl()
+
+
+def cmd_files(global_config, ca, certs, args):
+ if len(args) < 1:
+ print 'Nothing to do.'
+ for tag in args:
+ c = find_cert(certs, tag)
+ print c.public_key_file
+ print c.private_key_file
+
+
+def cmd_list(global_config, ca, certs, args):
+ now = time.time()
+ for cert in sorted(certs, key=lambda x: x.name):
+ expiry = cert.get_expiration_date()
+ state = 'OK'
+ expiry_str = ''
+ if not expiry:
+ state = 'MISSING'
+ else:
+ if expiry < now:
+ state = 'EXPIRED'
+ expiry_str = time.strftime('%Y/%m/%d', time.gmtime(expiry))
+ print cert.name, cert.cn, state, expiry_str
+
+
+def cmd_fingerprint(global_config, ca, certs, args):
+ if len(args) > 0:
+ certs = [find_cert(certs, x) for x in args]
+ for cert in certs:
+ print cert.name, cert.cn
+ print ' SHA1:', cert.get_fingerprint('sha1')
+ print ' MD5:', cert.get_fingerprint('md5')
+
+
+def cmd_check(global_config, ca, certs, args):
+ now = time.time()
+ warning_time = 86400 * int(global_config.get('warning_days', 15))
+ retval = 0
+ for cert in certs:
+ exp = cert.get_expiration_date()
+ if exp and (exp - now) < warning_time:
+ print '%s (%s) is about to expire.' % (cert.name, cert.cn)
+ retval = 1
+ return retval
+
+
+cmd_table = {
+ 'init': cmd_init,
+ 'gen': cmd_gen,
+ 'gencrl': cmd_gencrl,
+ 'files': cmd_files,
+ 'list': cmd_list,
+ 'fp': cmd_fingerprint,
+ 'fingerprint': cmd_fingerprint,
+ 'check': cmd_check,
+}
+
+