Makefile 4.2 KB

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