Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Makefile for the linux kernel signature checking certificates.
  4. #
  5. obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
  6. obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
  7. ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
  8. obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
  9. else
  10. obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
  11. endif
  12. ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
  13. $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
  14. # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
  15. $(obj)/system_certificates.o: $(obj)/x509_certificate_list
  16. # Cope with signing_key.x509 existing in $(srctree) not $(objtree)
  17. AFLAGS_system_certificates.o := -I$(srctree)
  18. quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
  19. cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
  20. targets += x509_certificate_list
  21. $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
  22. $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
  23. endif # CONFIG_SYSTEM_TRUSTED_KEYRING
  24. clean-files := x509_certificate_list .x509.list
  25. ifeq ($(CONFIG_MODULE_SIG),y)
  26. ###############################################################################
  27. #
  28. # If module signing is requested, say by allyesconfig, but a key has not been
  29. # supplied, then one will need to be generated to make sure the build does not
  30. # fail and that the kernel may be used afterwards.
  31. #
  32. ###############################################################################
  33. ifndef CONFIG_MODULE_SIG_HASH
  34. $(error Could not determine digest type to use from kernel config)
  35. endif
  36. redirect_openssl = 2>&1
  37. quiet_redirect_openssl = 2>&1
  38. silent_redirect_openssl = 2>/dev/null
  39. # We do it this way rather than having a boolean option for enabling an
  40. # external private key, because 'make randconfig' might enable such a
  41. # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
  42. ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
  43. $(obj)/signing_key.pem: $(obj)/x509.genkey
  44. @$(kecho) "###"
  45. @$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
  46. @$(kecho) "###"
  47. @$(kecho) "### If this takes a long time, you might wish to run rngd in the"
  48. @$(kecho) "### background to keep the supply of entropy topped up. It"
  49. @$(kecho) "### needs to be run as root, and uses a hardware random"
  50. @$(kecho) "### number generator if one is available."
  51. @$(kecho) "###"
  52. $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
  53. -batch -x509 -config $(obj)/x509.genkey \
  54. -outform PEM -out $(obj)/signing_key.pem \
  55. -keyout $(obj)/signing_key.pem \
  56. $($(quiet)redirect_openssl)
  57. @$(kecho) "###"
  58. @$(kecho) "### Key pair generated."
  59. @$(kecho) "###"
  60. $(obj)/x509.genkey:
  61. @$(kecho) Generating X.509 key generation config
  62. @echo >$@ "[ req ]"
  63. @echo >>$@ "default_bits = 4096"
  64. @echo >>$@ "distinguished_name = req_distinguished_name"
  65. @echo >>$@ "prompt = no"
  66. @echo >>$@ "string_mask = utf8only"
  67. @echo >>$@ "x509_extensions = myexts"
  68. @echo >>$@
  69. @echo >>$@ "[ req_distinguished_name ]"
  70. @echo >>$@ "#O = Unspecified company"
  71. @echo >>$@ "CN = Build time autogenerated kernel key"
  72. @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
  73. @echo >>$@
  74. @echo >>$@ "[ myexts ]"
  75. @echo >>$@ "basicConstraints=critical,CA:FALSE"
  76. @echo >>$@ "keyUsage=digitalSignature"
  77. @echo >>$@ "subjectKeyIdentifier=hash"
  78. @echo >>$@ "authorityKeyIdentifier=keyid"
  79. endif # CONFIG_MODULE_SIG_KEY
  80. $(eval $(call config_filename,MODULE_SIG_KEY))
  81. # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
  82. ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
  83. X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
  84. endif
  85. # GCC PR#66871 again.
  86. $(obj)/system_certificates.o: $(obj)/signing_key.x509
  87. targets += signing_key.x509
  88. $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
  89. $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
  90. endif # CONFIG_MODULE_SIG