@@ -238,12 +238,12 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
238238 )
239239
240240 now = utcnow ()
241- if _cert . not_valid_after < now :
241+ if self . _not_valid_after ( _cert ) < now :
242242 raise AWSValidationException (
243243 "The certificate has expired, is not valid."
244244 )
245245
246- if _cert . not_valid_before > now :
246+ if self . _not_valid_before ( _cert ) > now :
247247 raise AWSValidationException (
248248 "The certificate is not in effect yet, is not valid."
249249 )
@@ -256,6 +256,22 @@ def validate_certificate(self) -> cryptography.x509.base.Certificate:
256256 )
257257 return _cert
258258
259+ def _not_valid_after (
260+ self , _cert : cryptography .x509 .base .Certificate
261+ ) -> datetime .datetime :
262+ try :
263+ return _cert .not_valid_after_utc .replace (tzinfo = None )
264+ except AttributeError :
265+ return _cert .not_valid_after
266+
267+ def _not_valid_before (
268+ self , _cert : cryptography .x509 .base .Certificate
269+ ) -> datetime .datetime :
270+ try :
271+ return _cert .not_valid_before_utc .replace (tzinfo = None )
272+ except AttributeError :
273+ return _cert .not_valid_before
274+
259275 def validate_chain (self ) -> None :
260276 try :
261277 for cert_armored in self .chain .split (b"-\n -" ):
@@ -267,12 +283,12 @@ def validate_chain(self) -> None:
267283 )
268284
269285 now = utcnow ()
270- if self ._cert . not_valid_after < now :
286+ if self ._not_valid_after ( self . _cert ) < now :
271287 raise AWSValidationException (
272288 "The certificate chain has expired, is not valid."
273289 )
274290
275- if self ._cert . not_valid_before > now :
291+ if self ._not_valid_before ( self . _cert ) > now :
276292 raise AWSValidationException (
277293 "The certificate chain is not in effect yet, is not valid."
278294 )
@@ -325,8 +341,8 @@ def describe(self) -> Dict[str, Any]:
325341 0
326342 ].value ,
327343 "KeyAlgorithm" : key_algo ,
328- "NotAfter" : datetime_to_epoch (self ._cert . not_valid_after ),
329- "NotBefore" : datetime_to_epoch (self ._cert . not_valid_before ),
344+ "NotAfter" : datetime_to_epoch (self ._not_valid_after ( self . _cert ) ),
345+ "NotBefore" : datetime_to_epoch (self ._not_valid_before ( self . _cert ) ),
330346 "Serial" : str (self ._cert .serial_number ),
331347 "SignatureAlgorithm" : self ._cert .signature_algorithm_oid ._name .upper ().replace (
332348 "ENCRYPTION" , ""
0 commit comments