diff --git a/sleekxmpp/xmlstream/cert.py b/sleekxmpp/xmlstream/cert.py index ae82cac83..6cc4047bb 100644 --- a/sleekxmpp/xmlstream/cert.py +++ b/sleekxmpp/xmlstream/cert.py @@ -1,5 +1,5 @@ import logging -from datetime import datetime, timedelta +from datetime import datetime, timedelta, tzinfo # Make a call to strptime before starting threads to # prevent thread safety issues. @@ -32,6 +32,17 @@ class CertificateError(Exception): pass +class UTC(tzinfo): + def utcoffset(self, dt): + return timedelta(0) + def tzname(self, dt): + return "UTC" + def dst(self, dt): + return timedelta(0) + +utc = UTC() + + def decode_str(data): encoding = 'utf-16-be' if isinstance(data, BMPString) else 'utf-8' return bytes(data).decode(encoding) @@ -107,12 +118,12 @@ def extract_dates(raw_cert): validity = tbs.getComponentByName('validity') not_before = validity.getComponentByName('notBefore') - not_before = str(not_before.getComponent()) - not_before = datetime.strptime(not_before, '%Y%m%d%H%M%SZ') + not_before = not_before.getComponent().asDateTime + not_before = not_before.astimezone(utc).replace(tzinfo = None) not_after = validity.getComponentByName('notAfter') - not_after = str(not_after.getComponent()) - not_after = datetime.strptime(not_after, '%Y%m%d%H%M%SZ') + not_after = not_after.getComponent().asDateTime + not_after = not_after.astimezone(utc).replace(tzinfo = None) return not_before, not_after