OSDN Git Service

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