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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From a4e468a2a0afa80df174831c2f422184820bb0fa 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. [Steve: refreshed to apply on ca-certificates version 20230311]
  15. Signed-off-by: Steve Hay <me@stevenhay.com>
  16. ---
  17. mozilla/certdata2pem.py | 17 ++++++++++-------
  18. 1 file changed, 10 insertions(+), 7 deletions(-)
  19. diff --git a/mozilla/certdata2pem.py b/mozilla/certdata2pem.py
  20. index 4df86a2..3a6d7dc 100644
  21. --- a/mozilla/certdata2pem.py
  22. +++ b/mozilla/certdata2pem.py
  23. @@ -28,8 +28,6 @@ import sys
  24. import textwrap
  25. import io
  26. -from cryptography import x509
  27. -
  28. objects = []
  29. @@ -122,11 +120,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(bytes(obj['CKA_VALUE']))
  33. - if cert.not_valid_after < datetime.datetime.utcnow():
  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(bytes(obj['CKA_VALUE']))
  41. + if cert.not_valid_after < datetime.datetime.utcnow():
  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.30.2