0001-mozilla-certdata2pem.py-make-cryptography-module-opt.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From bf18b564122e8f976681a2398862fde1eafd84ba Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  3. Date: Thu, 6 Jan 2022 23:15:00 +0100
  4. Subject: [PATCH] mozilla/certdata2pem.py: make cryptography module optional
  5. The Python cryptography module is only used to verify if trusted
  6. certificates have expired, but this is only a warning. For some build
  7. systems and distributions, providing Python cryptography is costly,
  8. especially since it's now partly written in Rust.
  9. As the check is only a warning, it's anyway going to be overlooked by
  10. most people. This commit changes the check to be optional: if the
  11. cryptography Python module is there, we perform the check, otherwise
  12. the check is skipped.
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  14. ---
  15. mozilla/certdata2pem.py | 18 ++++++++++--------
  16. 1 file changed, 10 insertions(+), 8 deletions(-)
  17. diff --git a/mozilla/certdata2pem.py b/mozilla/certdata2pem.py
  18. index ede23d4..a6261f8 100644
  19. --- a/mozilla/certdata2pem.py
  20. +++ b/mozilla/certdata2pem.py
  21. @@ -28,9 +28,6 @@ import sys
  22. import textwrap
  23. import io
  24. -from cryptography import x509
  25. -
  26. -
  27. objects = []
  28. # Dirty file parser.
  29. @@ -122,11 +119,16 @@ for obj in objects:
  30. if not obj['CKA_LABEL'] in trust or not trust[obj['CKA_LABEL']]:
  31. continue
  32. - cert = x509.load_der_x509_certificate(obj['CKA_VALUE'])
  33. - if cert.not_valid_after < datetime.datetime.now():
  34. - print('!'*74)
  35. - print('Trusted but expired certificate found: %s' % obj['CKA_LABEL'])
  36. - print('!'*74)
  37. + try:
  38. + from cryptography import x509
  39. +
  40. + cert = x509.load_der_x509_certificate(obj['CKA_VALUE'])
  41. + if cert.not_valid_after < datetime.datetime.now():
  42. + print('!'*74)
  43. + print('Trusted but expired certificate found: %s' % obj['CKA_LABEL'])
  44. + print('!'*74)
  45. + except ImportError:
  46. + pass
  47. bname = obj['CKA_LABEL'][1:-1].replace('/', '_')\
  48. .replace(' ', '_')\
  49. --
  50. 2.33.1