From 03524ba3e9b3fb8364fff3e25edce53fbcaef06d Mon Sep 17 00:00:00 2001 From: glitchim <166491323+glitchim@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:42:37 +0200 Subject: [PATCH] Make x509.py timezone aware And remove not_valid_after/not_valid_before deprecation warning --- requests_toolbelt/adapters/x509.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requests_toolbelt/adapters/x509.py b/requests_toolbelt/adapters/x509.py index aff3770..21df66c 100644 --- a/requests_toolbelt/adapters/x509.py +++ b/requests_toolbelt/adapters/x509.py @@ -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 @@ -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}'