self.basedir = basedir
self.config = {'basedir': basedir, 'default_days': '365', 'ou': 'CA',
'days': '3650', 'country': 'XX', 'crl_url': '',
- 'bits': '4096'}
+ 'signature_algorithm': 'sha256', 'bits': '2048'}
self.config.update(config)
self.files = _CAFiles(basedir,
conf='conf/ca.conf',
self.basedir, self.files.conf,
'ca', '-keyfile', self.files.private_key,
'-key', self._getpw(),
+ '-md', self.config['signature_algorithm'],
'-extensions', 'v3_ca', '-out', self.files.public_key,
'-days', self.config.get('days', self.config['default_days']),
'-selfsign', '-infiles', csr_file)
'-key', self._getpw())
self.gencrl()
+ def verify(self, path):
+ log.info('verifying certificate %s', path)
+ args = ['verify', '-CAfile', self.files.public_key, path]
+ try:
+ openssl_wrap.run(*args, CAROOT=os.path.abspath(self.basedir))
+ except openssl_wrap.CommandError:
+ return False
+ return True
+
def generate(self, cert):
self._update_config()
expiry = cert.get_expiration_date()
if expiry and expiry > time.time():
- log.warn('certificate is still valid, revoking previous version')
+ log.warn('certificate is still valid')
+
+ if cert.exists():
+ log.warn('revoking previous version')
self.revoke(cert)
log.info('generating new certificate %s', cert.name)
openssl_wrap.run_with_config(
self.basedir, conf_file,
'req', '-new', '-keyout', cert.private_key_file,
+ '-' + self.config['signature_algorithm'],
'-nodes', '-out', csr_file)
os.chmod(cert.private_key_file, 0600)
openssl_wrap.run_with_config(
self.basedir, conf_file,
'ca', '-days', conf['days'],
'-key', self._getpw(),
+ '-md', self.config['signature_algorithm'],
'-policy', 'policy_anything', '-out', cert.public_key_file,
'-extfile', ext_file, '-infiles', csr_file)
finally: