Back to home page

LXR

 
 

    


0001 #
0002 # Makefile for the linux kernel signature checking certificates.
0003 #
0004 
0005 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
0006 
0007 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
0008 
0009 $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
0010 
0011 # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
0012 $(obj)/system_certificates.o: $(obj)/x509_certificate_list
0013 
0014 # Cope with signing_key.x509 existing in $(srctree) not $(objtree)
0015 AFLAGS_system_certificates.o := -I$(srctree)
0016 
0017 quiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
0018       cmd_extract_certs  = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
0019 
0020 targets += x509_certificate_list
0021 $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
0022         $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
0023 endif
0024 
0025 clean-files := x509_certificate_list .x509.list
0026 
0027 ifeq ($(CONFIG_MODULE_SIG),y)
0028 ###############################################################################
0029 #
0030 # If module signing is requested, say by allyesconfig, but a key has not been
0031 # supplied, then one will need to be generated to make sure the build does not
0032 # fail and that the kernel may be used afterwards.
0033 #
0034 ###############################################################################
0035 ifndef CONFIG_MODULE_SIG_HASH
0036 $(error Could not determine digest type to use from kernel config)
0037 endif
0038 
0039 redirect_openssl        = 2>&1
0040 quiet_redirect_openssl  = 2>&1
0041 silent_redirect_openssl = 2>/dev/null
0042 
0043 # We do it this way rather than having a boolean option for enabling an
0044 # external private key, because 'make randconfig' might enable such a
0045 # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
0046 ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
0047 $(obj)/signing_key.pem: $(obj)/x509.genkey
0048         @$(kecho) "###"
0049         @$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
0050         @$(kecho) "###"
0051         @$(kecho) "### If this takes a long time, you might wish to run rngd in the"
0052         @$(kecho) "### background to keep the supply of entropy topped up.  It"
0053         @$(kecho) "### needs to be run as root, and uses a hardware random"
0054         @$(kecho) "### number generator if one is available."
0055         @$(kecho) "###"
0056         $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
0057                 -batch -x509 -config $(obj)/x509.genkey \
0058                 -outform PEM -out $(obj)/signing_key.pem \
0059                 -keyout $(obj)/signing_key.pem \
0060                 $($(quiet)redirect_openssl)
0061         @$(kecho) "###"
0062         @$(kecho) "### Key pair generated."
0063         @$(kecho) "###"
0064 
0065 $(obj)/x509.genkey:
0066         @$(kecho) Generating X.509 key generation config
0067         @echo  >$@ "[ req ]"
0068         @echo >>$@ "default_bits = 4096"
0069         @echo >>$@ "distinguished_name = req_distinguished_name"
0070         @echo >>$@ "prompt = no"
0071         @echo >>$@ "string_mask = utf8only"
0072         @echo >>$@ "x509_extensions = myexts"
0073         @echo >>$@
0074         @echo >>$@ "[ req_distinguished_name ]"
0075         @echo >>$@ "#O = Unspecified company"
0076         @echo >>$@ "CN = Build time autogenerated kernel key"
0077         @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
0078         @echo >>$@
0079         @echo >>$@ "[ myexts ]"
0080         @echo >>$@ "basicConstraints=critical,CA:FALSE"
0081         @echo >>$@ "keyUsage=digitalSignature"
0082         @echo >>$@ "subjectKeyIdentifier=hash"
0083         @echo >>$@ "authorityKeyIdentifier=keyid"
0084 endif
0085 
0086 $(eval $(call config_filename,MODULE_SIG_KEY))
0087 
0088 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
0089 ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
0090 X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
0091 endif
0092 
0093 # GCC PR#66871 again.
0094 $(obj)/system_certificates.o: $(obj)/signing_key.x509
0095 
0096 targets += signing_key.x509
0097 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
0098         $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
0099 endif