Skip to content

Commit

Permalink
Make x509.py timezone aware
Browse files Browse the repository at this point in the history
And remove not_valid_after/not_valid_before deprecation warning
  • Loading branch information
glitchim authored Apr 11, 2024
1 parent 46f38f8 commit 03524ba
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 03524ba

Please sign in to comment.