summaryrefslogtreecommitdiff
path: root/src/leap/common/certs.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2015-05-20 18:39:10 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-05-21 17:41:06 -0300
commit00bfb22368c788bfc5de458e9159ee73cf3e66c7 (patch)
tree80cdcc784123ceb926cd7d96b6c8377ab5eb7977 /src/leap/common/certs.py
parent60bcc511b5d715b4921645cad6c82adfacf7ec24 (diff)
[bug] get certificate times as UTC, add tests
The certificate validity times were converted to local time and later on compared with UTC time, which caused the certificate not being updated at the right times. Add tests to be sure this is not happenning again. Add a joint pem file for the existing cert and key files to ease test. - Resolves: #6994
Diffstat (limited to 'src/leap/common/certs.py')
-rw-r--r--src/leap/common/certs.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/leap/common/certs.py b/src/leap/common/certs.py
index 4fe563b..db513f6 100644
--- a/src/leap/common/certs.py
+++ b/src/leap/common/certs.py
@@ -128,22 +128,23 @@ def is_valid_pemfile(cert):
return can_load_cert_and_pkey(cert)
-def get_cert_time_boundaries(certfile):
+def get_cert_time_boundaries(certdata):
"""
- Returns the time boundaries for the certificate saved in certfile
+ Return the time boundaries for the given certificate.
+ The returned values are UTC/GMT time.struct_time objects
- :param certfile: path to certificate
- :type certfile: str
+ :param certdata: the certificate contents
+ :type certdata: str
:rtype: tuple (from, to)
"""
- cert = get_cert_from_string(certfile)
+ cert = get_cert_from_string(certdata)
leap_assert(cert, 'There was a problem loading the certificate')
fromts, tots = (cert.get_notBefore(), cert.get_notAfter())
- from_, to_ = map(
- lambda ts: time.gmtime(time.mktime(dateparse(ts).timetuple())),
- (fromts, tots))
+ from_ = dateparse(fromts).timetuple()
+ to_ = dateparse(tots).timetuple()
+
return from_, to_