6 from templates import *
13 info = cfg2dict(cfg, tag)
15 conf_file = getpath('conf', tag)
16 rsa_key_file = getpath('rsa_key', tag)
17 dsa_key_file = getpath('dsa_key', tag)
18 dsa_parms_file = getpath('dsa_parms', tag)
19 csr_file = getpath('rsa_csr', tag)
20 dsa_csr_file = getpath('dsa_csr', tag)
21 ext_file = getpath('ext', tag)
22 public_crt_file = getpath('public_crt', tag)
23 crt_file = getpath('rsa_crt', tag)
24 dsa_crt_file = getpath('dsa_crt', tag)
25 sf_file = getpath('singlefile', tag)
27 if os.path.exists(public_crt_file):
29 if expired(getcertdate(public_crt_file)):
30 print 'Certificate has expired. Ready to re-generate.'
33 ans = raw_input('This certificate seems to exist already (in %s).\nAre you really sure that you want to re-create it? [y/N] ' % crt_file)
34 if not ans or ans[0].lower() != 'y':
36 print 'Revoking previous certificate...'
37 openssl('ca', '-config', conf_file,
38 '-revoke', public_crt_file)
41 # create custom config file
43 openssl_conf_template,
46 default_days = ca['default_days'],
47 country = d2get(info, ca, 'country'),
48 org = d2get(info, ca, 'org'),
49 ou = d2get(info, ca, 'ou', ''),
51 email = d2get(info, ca, 'email')))
53 # create dsa parameters
54 openssl('dsaparam', '-out', dsa_parms_file, '1024')
57 openssl('req', '-batch', '-new', '-keyout', rsa_key_file,
58 '-config', conf_file, '-nodes', '-out', csr_file)
59 openssl('req', '-batch', '-new', '-newkey', 'dsa:' + dsa_parms_file,
60 '-keyout', dsa_key_file, '-nodes',
61 '-config', conf_file, '-out', dsa_csr_file)
64 altnames = [ x.strip() for x in info['alt_names'].split(',') ]
66 for i in range(len(altnames)):
67 altnames_s += 'DNS.%d=%s\n' % (i + 1, altnames[i])
72 ca_base_url = ca['base_url'],
73 alt_names = altnames_s))
76 openssl('ca', '-days', ca['default_days'],
77 '-config', conf_file, '-batch',
78 '-policy', 'policy_anything',
82 openssl('ca', '-days', ca['default_days'],
83 '-config', conf_file, '-batch',
84 '-policy', 'policy_anything',
87 '-infiles', dsa_csr_file)
88 f = open(public_crt_file, 'w')
89 f.write(open(crt_file, 'r').read())
90 f.write(open(dsa_crt_file, 'r').read())
93 # create single-file file
94 f = open(sf_file, 'w')
95 f.write(open(crt_file, 'r').read())
96 f.write(open(dsa_crt_file, 'r').read())
97 f.write(open(rsa_key_file, 'r').read())
98 f.write(open(dsa_key_file, 'r').read())
101 logging.info('created certificate %s [%s]' % (tag, info['cn']))
114 ''' % (tag, info['cn'], ', '.join(altnames),
115 rsa_key_file, dsa_key_file, public_crt_file, sf_file)