11 USAGE = '''cam [<OPTIONS>] <COMMAND> [<ARG>...]
12 CAM v2.0 - (c)2012 by <ale@incal.net>
13 A Certification Authority manager for complex situations.
17 init [<RSA_CRT> [<DSA_CRT>]]
18 Initialize the environment and create a new CA certificate
19 (you can also import your own existing certificates)
22 Create (or re-create) the certificates corresponding
29 List all known certificates
32 Dump all the certificate-related files of this TAG
35 Should be run weekly from a cron job to warn you if some
36 certificates are about to expire (controlled by the 'warning_days'
37 parameter in the 'global' section of the configuration)
39 The configuration file consists of a ini-style file, with one 'ca'
40 section that specifies global CA parameters, and more sections for
41 each tag with certificate-specific information. See the examples for
42 more details on how to write your own configuration.
46 def find_cert(certs, name):
50 raise Exception('Certificate "%s" not found' % name)
54 parser = optparse.OptionParser(usage=USAGE)
55 parser.add_option('-d', '--debug', dest='debug', help='Be verbose',
57 parser.add_option('-c', '--config', dest='config', help='Config file')
58 opts, args = parser.parse_args()
60 parser.error('Must specify --config')
62 parser.error('Must specify a command')
65 logging.getLogger().setLevel(opts.debug and logging.DEBUG or logging.INFO)
67 global_config, ca, certs = config.read_config(opts.config)
69 cmd, args = args[0], args[1:]
76 parser.error('Wrong number of arguments')
77 ca.generate(find_cert(certs, args[0]))
82 parser.error('Wrong number of arguments')
83 c = find_cert(certs, args[0])
84 print c.public_key_file
85 print c.private_key_file
87 for cert in sorted(certs, key=lambda x: x.name):
88 print cert.name, cert.cn, cert.get_expiration_date()
91 warning_time = 8640000 * int(global_config.get('warning_days', 15))
93 exp = cert.get_expiration_date()
94 if exp and (exp - now) < warning_time:
95 print '%s (%s) is about to expire.' % (cert.name, cert.cn)
97 parser.error('unknown command "%s"' % cmd)
107 logging.exception('uncaught exception')
111 if __name__ == '__main__':
112 sys.exit(main_wrapper())