Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Remove two-digit-year variants from certificate validity date decodin…
Browse files Browse the repository at this point in the history
…g. Fixes Issue #461
  • Loading branch information
bear committed Sep 2, 2017
1 parent e9ecf1c commit 1c259fb
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions sleekxmpp/xmlstream/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,11 @@ def extract_dates(raw_cert):

not_before = validity.getComponentByName('notBefore')
not_before = str(not_before.getComponent())
not_before = datetime.strptime(not_before, '%Y%m%d%H%M%SZ')

not_after = validity.getComponentByName('notAfter')
not_after = str(not_after.getComponent())

if isinstance(not_before, GeneralizedTime):
not_before = datetime.strptime(not_before, '%Y%m%d%H%M%SZ')
else:
not_before = datetime.strptime(not_before, '%y%m%d%H%M%SZ')

if isinstance(not_after, GeneralizedTime):
not_after = datetime.strptime(not_after, '%Y%m%d%H%M%SZ')
else:
not_after = datetime.strptime(not_after, '%y%m%d%H%M%SZ')
not_after = datetime.strptime(not_after, '%Y%m%d%H%M%SZ')

return not_before, not_after

Expand Down

1 comment on commit 1c259fb

@ruferp
Copy link

@ruferp ruferp commented on 1c259fb Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is just reversing the problem it seems.

Before, it only worked when the time format returned by getComponent() was 'utcTime' (2 digit year)
Now, it only works when the time format returned by getComponent() is 'generalTime' (4 digit year)

tomstarstuck suggested using asDateTime:
not_before = not_before.getComponent().asDateTime
not_before = not_before.astimezone(pytz.UTC).replace(tzinfo = None)

This worked for me:
not_before_is_gt = not_before.getName() == 'generalTime'
not_before = str(not_before.getComponent())
if not_before_is_gt: not_before = datetime.strptime(not_before, '%Y%m%d%H%M%SZ')
...

Of course, milage may depend on which version of pyasn1 one is using...

Please sign in to comment.