Skip to content

Commit

Permalink
Compatibility fix for PyCA cryptography 42.0.0
Browse files Browse the repository at this point in the history
Cryptography 42.0.0 introduced two new abstract properties
`not_valid_before_utc` and `not_valid_after_utc`, which are non-naive UTC
variants of the `not_valid_before` and `not_valid_after` properties.

The old properties are deprecated. The change also modifies tests to
handle the new `_utc` variants.

Fixes: #345

Signed-off-by: Rob Crittenden <[email protected]>
  • Loading branch information
rcritten committed Jan 20, 2025
1 parent 3ec547e commit 1bdd735
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ipahealthcheck/ipa/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def check(self):

now = datetime.now(tz=timezone.utc)
# Older versions of IPA provide naive timestamps
notafter = cert.not_valid_after.replace(tzinfo=timezone.utc)
notafter = cert.not_valid_after_utc

if now > notafter:
yield Result(self, constants.ERROR,
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def check(self):
for cert in ca_certs:
subject = DN(cert.subject)
subject = str(subject).replace('\\;', '\\3b')
dt = cert.not_valid_after.replace(tzinfo=timezone.utc)
dt = cert.not_valid_after_utc
if dt < now:
logger.debug("%s is expired", subject)
yield Result(self, constants.CRITICAL,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ipa_certfile_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, not_valid_after, serial_number=1):
self.subject = 'CN=RA AGENT'
self.issuer = 'CN=ISSUER'
self.serial_number = serial_number
self.not_valid_after = not_valid_after
self.not_valid_after_utc = not_valid_after


class TestIPACertificateFile(BaseTest):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ipa_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def subject(self):
return self.subj

@property
def not_valid_after(self):
def not_valid_after_utc(self):
return self.not_after


Expand Down

0 comments on commit 1bdd735

Please sign in to comment.