fix cryptography DeprecationWarning (#6790)

* fix cryptography DeprecationWarning

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Maximilian Hils 2024-04-09 10:14:52 +02:00 committed by GitHub
parent 1b44691d33
commit 11a086805c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -33,6 +33,9 @@
([#6767](https://github.com/mitmproxy/mitmproxy/pull/6767), @txrp0x9)
* The "save body" feature now also includes WebSocket messages.
([#6767](https://github.com/mitmproxy/mitmproxy/pull/6767), @txrp0x9)
* Fix compatibility with older cryptography versions and silence a DeprecationWarning on Python <3.11.
([#6790](https://github.com/mitmproxy/mitmproxy/pull/6790), @mhils)
## 07 March 2024: mitmproxy 10.2.4

View File

@ -100,16 +100,23 @@ class Cert(serializable.Serializable):
@property
def notbefore(self) -> datetime.datetime:
# type definitions haven't caught up with new API yet.
return self._cert.not_valid_before_utc # type: ignore
try:
# type definitions haven't caught up with new API yet.
return self._cert.not_valid_before_utc # type: ignore
except AttributeError: # pragma: no cover
# cryptography < 42.0
return self._cert.not_valid_before.replace(tzinfo=datetime.timezone.utc)
@property
def notafter(self) -> datetime.datetime:
return self._cert.not_valid_after_utc # type: ignore
try:
return self._cert.not_valid_after_utc # type: ignore
except AttributeError: # pragma: no cover
return self._cert.not_valid_after.replace(tzinfo=datetime.timezone.utc)
def has_expired(self) -> bool:
if sys.version_info < (3, 11): # pragma: no cover
return datetime.datetime.utcnow() > self._cert.not_valid_after
return datetime.datetime.now(datetime.timezone.utc) > self.notafter
return datetime.datetime.now(datetime.UTC) > self.notafter
@property