fix: use utcnow() to check certificate validity #151
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Symptom:
Using the certificates generated using ./create_certs.sh, 'make run-secc' with TLS and PNC enabled, would fail in the CertificateInstallationReq handling:
ERROR 2022-10-21 14:37:20,294 - iso15118.shared.security (977): CertNotYetValidError: Signature verification failed while checking certificate chain
Issue:
The cryptography Certificate object represents the validity period of the certificate in UTC. https://cryptography.io/en/latest/x509/reference/#cryptography.x509.Certificate
However, security.py is comparing cert.not_valid_before to the local time, and as a result, the certificate is reported invalid for those of us in zones earlier than GMT.
Fix:
Use datetime.utcnow() instead of datetime.now() to get the current time