Makefile 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. # We do it this way rather than having a boolean option for enabling an
  30. # external private key, because 'make randconfig' might enable such a
  31. # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
  32. ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
  33. $(obj)/signing_key.pem: $(obj)/x509.genkey
  34. @echo "###"
  35. @echo "### Now generating an X.509 key pair to be used for signing modules."
  36. @echo "###"
  37. @echo "### If this takes a long time, you might wish to run rngd in the"
  38. @echo "### background to keep the supply of entropy topped up. It"
  39. @echo "### needs to be run as root, and uses a hardware random"
  40. @echo "### number generator if one is available."
  41. @echo "###"
  42. openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
  43. -batch -x509 -config $(obj)/x509.genkey \
  44. -outform PEM -out $(obj)/signing_key.pem \
  45. -keyout $(obj)/signing_key.pem 2>&1
  46. @echo "###"
  47. @echo "### Key pair generated."
  48. @echo "###"
  49. $(obj)/x509.genkey:
  50. @echo Generating X.509 key generation config
  51. @echo >$@ "[ req ]"
  52. @echo >>$@ "default_bits = 4096"
  53. @echo >>$@ "distinguished_name = req_distinguished_name"
  54. @echo >>$@ "prompt = no"
  55. @echo >>$@ "string_mask = utf8only"
  56. @echo >>$@ "x509_extensions = myexts"
  57. @echo >>$@
  58. @echo >>$@ "[ req_distinguished_name ]"
  59. @echo >>$@ "#O = Unspecified company"
  60. @echo >>$@ "CN = Build time autogenerated kernel key"
  61. @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
  62. @echo >>$@
  63. @echo >>$@ "[ myexts ]"
  64. @echo >>$@ "basicConstraints=critical,CA:FALSE"
  65. @echo >>$@ "keyUsage=digitalSignature"
  66. @echo >>$@ "subjectKeyIdentifier=hash"
  67. @echo >>$@ "authorityKeyIdentifier=keyid"
  68. endif
  69. $(eval $(call config_filename,MODULE_SIG_KEY))
  70. # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
  71. ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
  72. X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
  73. endif
  74. # GCC PR#66871 again.
  75. $(obj)/system_certificates.o: $(obj)/signing_key.x509
  76. targets += signing_key.x509
  77. $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
  78. $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
  79. endif