5 from cam import openssl_wrap
8 def _parse_alt_names(s):
15 return [x.strip() for x in parts if x]
20 def __init__(self, ca, name, config):
23 self.cn = config['cn']
24 self.ou = config.get('ou', '')
25 self.days = config.get('days')
27 self.alt_names = _parse_alt_names(config.get('alt_names'))
28 if self.cn not in self.alt_names:
29 self.alt_names.insert(0, self.cn)
30 self.public_key_file = os.path.join(ca.basedir, 'public', 'certs',
32 self.private_key_file = os.path.join(ca.basedir, 'private',
36 return os.path.exists(self.public_key_file)
38 def get_fingerprint(self, digest='sha1'):
40 output = openssl_wrap.run('x509', '-in', self.public_key_file,
41 '-noout', '-fingerprint', '-%s' % digest)
42 m = re.search(r'=(.*)$', output)
47 def get_expiration_date(self):
49 output = openssl_wrap.run('x509', '-in', self.public_key_file,
51 m = re.search(r'notAfter=(.*)', output)
53 return time.mktime(time.strptime(m.group(1),
54 '%b %d %H:%M:%S %Y %Z'))
59 return self.get_expiration_date() > now