Skip to content

Commit c73ad2c

Browse files
authored
Merge pull request #377 from glitchim/patch-1
Makes x509.py timezone-aware
2 parents 46f38f8 + 03524ba commit c73ad2c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: requests_toolbelt/adapters/x509.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from cryptography.hazmat.primitives.serialization import Encoding
1515
from cryptography.hazmat.backends import default_backend
1616

17-
from datetime import datetime
17+
from datetime import datetime, timezone
1818
from requests.adapters import HTTPAdapter
1919
import requests
2020

@@ -149,8 +149,8 @@ def _check_version(self):
149149
def check_cert_dates(cert):
150150
"""Verify that the supplied client cert is not invalid."""
151151

152-
now = datetime.utcnow()
153-
if cert.not_valid_after < now or cert.not_valid_before > now:
152+
now = datetime.now(timezone.utc)
153+
if cert.not_valid_after_utc < now or cert.not_valid_before_utc > now:
154154
raise ValueError('Client certificate expired: Not After: '
155155
'{:%Y-%m-%d %H:%M:%SZ} '
156156
'Not Before: {:%Y-%m-%d %H:%M:%SZ}'

0 commit comments

Comments
 (0)