1 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
3 from subprocess import Popen
8 class Certificate(object):
10 def __init__(self, path=None):
17 self.path = os.getcwd()
19 def generate(self, prefix, subject):
20 self.key = os.path.join(self.path, '%s.key' % prefix)
21 self.cert = os.path.join(self.path, '%s.pem' % prefix)
22 self.subject = '/CN=%s' % subject
24 'req', '-x509', '-batch', '-days', '1825',
25 '-newkey', 'rsa:2048', '-nodes', '-subj', self.subject,
26 '-keyout', self.key, '-out', self.cert]
30 def import_cert(self, certfile, keyfile):
36 raise ValueError('Certificate unavailable')
37 with open(self.cert, 'r') as f:
40 # poor man stripping of BEGIN/END lines
41 if cert[0] == '-----BEGIN CERTIFICATE-----\n':
43 if cert[-1] == '-----END CERTIFICATE-----\n':
46 return string.join(cert)