Makefile 3.7 KB

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