Skip to content

Commit

Permalink
Merge pull request #377 from glitchim/patch-1
Browse files Browse the repository at this point in the history
Makes x509.py timezone-aware
  • Loading branch information
sigmavirus24 authored Apr 11, 2024
2 parents 46f38f8 + 03524ba commit c73ad2c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions requests_toolbelt/adapters/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.backends import default_backend

from datetime import datetime
from datetime import datetime, timezone
from requests.adapters import HTTPAdapter
import requests

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

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

0 comments on commit c73ad2c

Please sign in to comment.