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':
37 # create custom config file
39 openssl_conf_template,
42 default_days = ca['default_days'],
43 country = d2get(info, ca, 'country'),
44 org = d2get(info, ca, 'org'),
45 ou = d2get(info, ca, 'ou', ''),
47 email = d2get(info, ca, 'email')))
49 # create dsa parameters
50 openssl('dsaparam', '-out', dsa_parms_file, '1024')
53 openssl('req', '-batch', '-new', '-keyout', rsa_key_file,
54 '-config', conf_file, '-nodes', '-out', csr_file)
55 openssl('req', '-batch', '-new', '-newkey', 'dsa:' + dsa_parms_file,
56 '-keyout', dsa_key_file, '-nodes',
57 '-config', conf_file, '-out', dsa_csr_file)
60 altnames = [ x.strip() for x in info['alt_names'].split(',') ]
62 for i in range(len(altnames)):
63 altnames_s += 'DNS.%d=%s\n' % (i + 1, altnames[i])
68 ca_base_url = ca['base_url'],
69 alt_names = altnames_s))
72 openssl('ca', '-days', ca['default_days'],
73 '-config', conf_file, '-batch',
74 '-policy', 'policy_anything',
78 openssl('ca', '-days', ca['default_days'],
79 '-config', conf_file, '-batch',
80 '-policy', 'policy_anything',
83 '-infiles', dsa_csr_file)
84 f = open(public_crt_file, 'w')
85 f.write(open(crt_file, 'r').read())
86 f.write(open(dsa_crt_file, 'r').read())
89 # create single-file file
90 f = open(sf_file, 'w')
91 f.write(open(crt_file, 'r').read())
92 f.write(open(dsa_crt_file, 'r').read())
93 f.write(open(rsa_key_file, 'r').read())
94 f.write(open(dsa_key_file, 'r').read())
97 logging.info('created certificate %s [%s]' % (tag, info['cn']))
110 ''' % (tag, info['cn'], ', '.join(altnames),
111 rsa_key_file, dsa_key_file, public_crt_file, sf_file)