From c3a2716985604564d46bc5367cf0be5e45d7f14a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 11 Apr 2014 15:42:54 -0400 Subject: [PATCH] Store full path immediately Allows to query .key and .cert to e used to find the files on the system directly w/o having to know what path was previously used to initialize the class. Signed-off-by: Simo Sorce --- ipsilon/tools/certs.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ipsilon/tools/certs.py b/ipsilon/tools/certs.py index a4b0f11..3a60488 100755 --- a/ipsilon/tools/certs.py +++ b/ipsilon/tools/certs.py @@ -34,21 +34,20 @@ class Certificate(object): self.path = os.getcwd() def generate(self, prefix, subject): - self.key = '%s.key' % prefix - self.cert = '%s.pem' % prefix + self.key = os.path.join(self.path, '%s.key' % prefix) + self.cert = os.path.join(self.path, '%s.pem' % prefix) self.subject = '/CN=%s' % subject command = ['openssl', 'req', '-x509', '-batch', '-days', '1825', '-newkey', 'rsa:2048', '-nodes', '-subj', self.subject, - '-keyout', os.path.join(self.path, self.key), - '-out', os.path.join(self.path, self.cert)] + '-keyout', self.key, '-out', self.cert] proc = Popen(command) proc.wait() def get_cert(self): if not self.cert: - raise NameError('Invalid certificate name: %s' % self.cert) - with open(os.path.join(self.path, self.cert), 'r') as f: + raise ValueError('Certificate unavailable') + with open(self.cert, 'r') as f: cert = f.readlines() #poor man stripping of BEGIN/END lines -- 2.20.1