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',
35 def get_fingerprint(self, digest='sha1'):
36 if os.path.exists(self.public_key_file):
37 output = openssl_wrap.run('x509', '-in', self.public_key_file,
38 '-noout', '-fingerprint', '-%s' % digest)
39 m = re.search(r'=(.*)$', output)
44 def get_expiration_date(self):
45 if os.path.exists(self.public_key_file):
46 output = openssl_wrap.run('x509', '-in', self.public_key_file,
48 m = re.search(r'notAfter=(.*)', output)
50 return time.mktime(time.strptime(m.group(1),
51 '%b %d %H:%M:%S %Y %Z'))
56 return self.get_expiration_date() > now