Skip to contentSkip to conversation

Add support for embedding public key in platform's dtb

PATCH Superseded Sughosh Ganu 5 participants 27 messages Apr 7, 2021 – May 8, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Add support for embedding public key in platform's dtb

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into the
platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44 ++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule authentication is enabled

Enable building of the crypto helper functions used during capsule authentication by selecting IMAGE_SIGN_INFO.

---

This was not detected when support for capsule auth was added to the qemu arm64 platform. This is because the platform includes CONFIG_FIT_SIGNATURE which selects IMAGE_SIGN_INFO.

 lib/efi_loader/Kconfig | 1 +
 1 file changed, 1 insertion(+)
lib/efi_loader/Kconfig +1 -0
index e44f004f3f..0b99d7c774 100644
@@ -173,6 +173,7 @@ config EFI_CAPSULE_AUTHENTICATE
 	select X509_CERTIFICATE_PARSER
 	select PKCS7_MESSAGE_PARSER
 	select PKCS7_VERIFY
+	select IMAGE_SIGN_INFO
 	default n
 	help
 	  Select this option if you want to enable capsule
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/5 efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule authentication is enabled

Quoted 4 lines · Sughosh Ganu

Enable building of the crypto helper functions used during capsule authentication by selecting IMAGE_SIGN_INFO.

Quoted 23 lines

---

This was not detected when support for capsule auth was added to the qemu arm64 platform. This is because the platform includes CONFIG_FIT_SIGNATURE which selects IMAGE_SIGN_INFO.

 lib/efi_loader/Kconfig | 1 +
 1 file changed, 1 insertion(+)
lib/efi_loader/Kconfig +1 -0
index e44f004f3f..0b99d7c774 100644
@@ -173,6 +173,7 @@ config EFI_CAPSULE_AUTHENTICATE
 	select X509_CERTIFICATE_PARSER
 	select PKCS7_MESSAGE_PARSER
 	select PKCS7_VERIFY
+	select IMAGE_SIGN_INFO
 	default n
 	help
 	  Select this option if you want to enable capsule
#3 lore raw

PATCH 2/5 efi_loader: Kconfig: Add symbols for embedding the public key into the platform's dtb

In reply to Sughosh Ganu

Add config options EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are to be used for embedding the public key to be used for capsule authentication into the platform's device tree.

The embedding of the public key would take place during the platform build process.

---
 lib/efi_loader/Kconfig | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/efi_loader/Kconfig +15 -0
index 0b99d7c774..de3083a979 100644
@@ -179,6 +179,21 @@ config EFI_CAPSULE_AUTHENTICATE
 	  Select this option if you want to enable capsule
 	  authentication
 
+config EFI_PKEY_DTB_EMBED
+	bool "Embed the public key in the Device Tree"
+	default n
+	depends on EFI_CAPSULE_AUTHENTICATE
+	help
+	  Select this option if the public key used for capsule
+	  authentication is to be embedded into the platform's
+	  device tree.
+
+config EFI_PKEY_FILE
+	string "Public Key esl file to be embedded into the Device Tree"
+	help
+	  Specify the absolute path of the public key esl file that is
+	  to be embedded in the platform's device tree.
+
 config EFI_CAPSULE_FIRMWARE_FIT
 	bool "FMP driver for FIT image"
 	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/5 efi_loader: Kconfig: Add symbols for embedding the public key into the platform's dtb

Quoted 17 lines · Sughosh Ganu

Add config options EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are to be used for embedding the public key to be used for capsule authentication into the platform's device tree.

The embedding of the public key would take place during the platform build process.

---
  lib/efi_loader/Kconfig | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
lib/efi_loader/Kconfig +0 -0
index 0b99d7c774..de3083a979 100644

lib/efi_loader/Kconfig config EFI_CAPSULE_AUTHENTICATE · line 184

Quoted 6 lines
lib/efi_loader/Kconfig +3 -0
@@ -179,6 +179,21 @@ config EFI_CAPSULE_AUTHENTICATE
  	  Select this option if you want to enable capsule
  	  authentication
 
+config EFI_PKEY_DTB_EMBED
+	bool "Embed the public key in the Device Tree"
+	default n

"default n" has no effect. So this line is superfluous.

But shouldn't this be default=y and tested via Python tests?

lib/efi_loader/Kconfig config EFI_CAPSULE_AUTHENTICATE · line 192

Quoted 8 lines
lib/efi_loader/Kconfig +8 -0
+	depends on EFI_CAPSULE_AUTHENTICATE
+	help
+	  Select this option if the public key used for capsule
+	  authentication is to be embedded into the platform's
+	  device tree.
+
+config EFI_PKEY_FILE
+	string "Public Key esl file to be embedded into the Device Tree"

Please, provide a default value (e.g. "eficapsule.esl") that we can rely on in our Python tests.

Best regards

Heinrich

Quoted 8 lines
lib/efi_loader/Kconfig +4 -0
+	help
+	  Specify the absolute path of the public key esl file that is
+	  to be embedded in the platform's device tree.
+
  config EFI_CAPSULE_FIRMWARE_FIT
  	bool "FMP driver for FIT image"
  	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
#5 lore raw

PATCH 3/5 efi_capsule: Add a weak function to check whether capsule authentication is enabled

In reply to Sughosh Ganu

Define a weak function which checks if the environment variable capsule_authentication_enabled has been set, for enabling capsule authentication. Other platforms might have a different mechanism to determine this, and would then define their own platform specific function.

---
 board/emulation/common/qemu_capsule.c | 6 ------
 lib/efi_loader/efi_capsule.c          | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
board/emulation/common/qemu_capsule.c +0 -6
index 5cb461d52b..6b8a87022a 100644
@@ -41,9 +41,3 @@ int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
 
 	return 0;
 }
-
-bool efi_capsule_auth_enabled(void)
-{
-	return env_get("capsule_authentication_enabled") != NULL ?
-		true : false;
-}
lib/efi_loader/efi_capsule.c +6 -0
index 0cfff0daf7..1423b675c8 100644
@@ -218,6 +218,12 @@ __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
 	return 0;
 }
 
+__weak bool efi_capsule_auth_enabled(void)
+{
+	return env_get("capsule_authentication_enabled") ?
+		true : false;
+}
+
 efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_size,
 				      void **image, efi_uintn_t *image_size)
 {
Signature · 1 line
2.17.1
#6 lore raw

PATCH 3/5 efi_capsule: Add a weak function to check whether capsule authentication is enabled

Quoted 5 lines · Sughosh Ganu

Define a weak function which checks if the environment variable capsule_authentication_enabled has been set, for enabling capsule authentication. Other platforms might have a different mechanism to determine this, and would then define their own platform specific function.

I cannot yet understand the concrete need for such a function.

Is there any Linaro customer who actually needs it? What is the use case?

Best regards

Heinrich

Quoted 39 lines
---
  board/emulation/common/qemu_capsule.c | 6 ------
  lib/efi_loader/efi_capsule.c          | 6 ++++++
  2 files changed, 6 insertions(+), 6 deletions(-)
board/emulation/common/qemu_capsule.c +0 -6
index 5cb461d52b..6b8a87022a 100644
@@ -41,9 +41,3 @@ int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
 
  	return 0;
  }
-
-bool efi_capsule_auth_enabled(void)
-{
-	return env_get("capsule_authentication_enabled") != NULL ?
-		true : false;
-}
lib/efi_loader/efi_capsule.c +6 -0
index 0cfff0daf7..1423b675c8 100644
@@ -218,6 +218,12 @@ __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
  	return 0;
  }
 
+__weak bool efi_capsule_auth_enabled(void)
+{
+	return env_get("capsule_authentication_enabled") ?
+		true : false;
+}
+
  efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_size,
  				      void **image, efi_uintn_t *image_size)
  {
#7 lore raw

PATCH 3/5 efi_capsule: Add a weak function to check whether capsule authentication is enabled

Quoted 11 lines · Heinrich Schuchardt
Quoted 5 lines · Sughosh Ganu

Define a weak function which checks if the environment variable capsule_authentication_enabled has been set, for enabling capsule authentication. Other platforms might have a different mechanism to determine this, and would then define their own platform specific function.

I cannot yet understand the concrete need for such a function.

Is there any Linaro customer who actually needs it? What is the use case?

This point was discussed in another mail thread[1]. I will be dropping the additional knob, so this weak function will go away.

-sughosh

[1] - https://lists.denx.de/pipermail/u-boot/2021-April/446694.html

Quoted 50 lines

Best regards

Heinrich

Review

Quoted 8 lines
---
  board/emulation/common/qemu_capsule.c | 6 ------
  lib/efi_loader/efi_capsule.c          | 6 ++++++
  2 files changed, 6 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/board/emulation/common/qemu_capsule.c

board/emulation/common/qemu_capsule.c int efi_get_public_key_data(void **pkey, efi_uintn_t

Quoted 4 lines

index 5cb461d52b..6b8a87022a 100644

board/emulation/common/qemu_capsule.c +0 -0
@@ -41,9 +41,3 @@ int efi_get_public_key_data(void **pkey, efi_uintn_t

*pkey_len)

lib/efi_loader/efi_capsule.c __weak int efi_get_public_key_data(void **pkey,

Quoted 14 lines
board/emulation/common/qemu_capsule.c +0 -6
      return 0;
  }
-
-bool efi_capsule_auth_enabled(void)
-{
-     return env_get("capsule_authentication_enabled") != NULL ?
-             true : false;
-}
lib/efi_loader/efi_capsule.c +0 -0
index 0cfff0daf7..1423b675c8 100644
@@ -218,6 +218,12 @@ __weak int efi_get_public_key_data(void **pkey,

efi_uintn_t *pkey_len)

lib/efi_loader/efi_capsule.c __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)

Quoted 10 lines
lib/efi_loader/efi_capsule.c +6 -0
      return 0;
  }
 
+__weak bool efi_capsule_auth_enabled(void)
+{
+     return env_get("capsule_authentication_enabled") ?
+             true : false;
+}
+
  efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t

capsule_size,

lib/efi_loader/efi_capsule.c __weak int efi_get_public_key_data(void **pkey, · line 228

Quoted 1 line
lib/efi_loader/efi_capsule.c +0 -0
                                    void **image, efi_uintn_t

*image_size)

Quoted 2 lines
lib/efi_loader/efi_capsule.c +0 -0
  {
#8 lore raw

PATCH 4/5 efi_capsule: Add a weak function to get the public key needed for capsule authentication

In reply to Sughosh Ganu

Define a weak function which would be used in the scenario where the public key is stored on the platform's dtb. This dtb is concatenated with the u-boot binary during the build process. Platforms which have a different mechanism for getting the public key would define their own platform specific function.

---
 lib/efi_loader/efi_capsule.c | 38 ++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
lib/efi_loader/efi_capsule.c +34 -4
index 1423b675c8..fc5e1c0856 100644
@@ -14,10 +14,13 @@
 #include <mapmem.h>
 #include <sort.h>
 
+#include <asm/global_data.h>
 #include <crypto/pkcs7.h>
 #include <crypto/pkcs7_parser.h>
 #include <linux/err.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 static const efi_guid_t efi_guid_firmware_management_capsule_id =
 		EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
@@ -210,11 +213,38 @@ const efi_guid_t efi_guid_capsule_root_cert_guid =
 
 __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
 {
-	/* The platform is supposed to provide
-	 * a method for getting the public key
-	 * stored in the form of efi signature
-	 * list
+	/*
+	 * This is a function for retrieving the public key from the
+	 * platform's device tree. The platform's device tree has been
+	 * concatenated with the u-boot binary.
+	 * If a platform has a different mechanism to get the public
+	 * key, it can define it's own function.
 	 */
+	const void *fdt_blob = gd->fdt_blob;
+	const void *blob;
+	const char *cnode_name = "capsule-key";
+	const char *snode_name = "signature";
+	int sig_node;
+	int len;
+
+	sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
+	if (sig_node < 0) {
+		EFI_PRINT("Unable to get signature node offset\n");
+		return -FDT_ERR_NOTFOUND;
+	}
+
+	blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len);
+
+	if (!blob || len < 0) {
+		EFI_PRINT("Unable to get capsule-key value\n");
+		*pkey = NULL;
+		*pkey_len = 0;
+		return -FDT_ERR_NOTFOUND;
+	}
+
+	*pkey = (void *)blob;
+	*pkey_len = len;
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 4/5 efi_capsule: Add a weak function to get the public key needed for capsule authentication

Quoted 5 lines · Sughosh Ganu

Define a weak function which would be used in the scenario where the public key is stored on the platform's dtb. This dtb is concatenated with the u-boot binary during the build process. Platforms which have a different mechanism for getting the public key would define their own platform specific function.

Storing the public key in U-Boot's dtb is reasonable. But what is the use case for a weak function?

Best regards

Heinrich

Quoted 68 lines
---
  lib/efi_loader/efi_capsule.c | 38 ++++++++++++++++++++++++++++++++----
  1 file changed, 34 insertions(+), 4 deletions(-)
lib/efi_loader/efi_capsule.c +34 -4
index 1423b675c8..fc5e1c0856 100644
@@ -14,10 +14,13 @@
  #include <mapmem.h>
  #include <sort.h>
 
+#include <asm/global_data.h>
  #include <crypto/pkcs7.h>
  #include <crypto/pkcs7_parser.h>
  #include <linux/err.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
  const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
  static const efi_guid_t efi_guid_firmware_management_capsule_id =
  		EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
@@ -210,11 +213,38 @@ const efi_guid_t efi_guid_capsule_root_cert_guid =
 
  __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
  {
-	/* The platform is supposed to provide
-	 * a method for getting the public key
-	 * stored in the form of efi signature
-	 * list
+	/*
+	 * This is a function for retrieving the public key from the
+	 * platform's device tree. The platform's device tree has been
+	 * concatenated with the u-boot binary.
+	 * If a platform has a different mechanism to get the public
+	 * key, it can define it's own function.
  	 */
+	const void *fdt_blob = gd->fdt_blob;
+	const void *blob;
+	const char *cnode_name = "capsule-key";
+	const char *snode_name = "signature";
+	int sig_node;
+	int len;
+
+	sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
+	if (sig_node < 0) {
+		EFI_PRINT("Unable to get signature node offset\n");
+		return -FDT_ERR_NOTFOUND;
+	}
+
+	blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len);
+
+	if (!blob || len < 0) {
+		EFI_PRINT("Unable to get capsule-key value\n");
+		*pkey = NULL;
+		*pkey_len = 0;
+		return -FDT_ERR_NOTFOUND;
+	}
+
+	*pkey = (void *)blob;
+	*pkey_len = len;
+
  	return 0;
  }
 
#10 lore raw

PATCH 4/5 efi_capsule: Add a weak function to get the public key needed for capsule authentication

Quoted 10 lines · Heinrich Schuchardt
Quoted 5 lines · Sughosh Ganu

Define a weak function which would be used in the scenario where the public key is stored on the platform's dtb. This dtb is concatenated with the u-boot binary during the build process. Platforms which have a different mechanism for getting the public key would define their own platform specific function.

Storing the public key in U-Boot's dtb is reasonable. But what is the use case for a weak function?

This point was discussed in another mail thread[1].

-sughosh

[1] - https://lists.denx.de/pipermail/u-boot/2021-April/446694.html

Quoted 74 lines

Best regards

Heinrich

Quoted 68 lines
---
  lib/efi_loader/efi_capsule.c | 38 ++++++++++++++++++++++++++++++++----
  1 file changed, 34 insertions(+), 4 deletions(-)
lib/efi_loader/efi_capsule.c +34 -4
index 1423b675c8..fc5e1c0856 100644
@@ -14,10 +14,13 @@
  #include <mapmem.h>
  #include <sort.h>
 
+#include <asm/global_data.h>
  #include <crypto/pkcs7.h>
  #include <crypto/pkcs7_parser.h>
  #include <linux/err.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
  const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
  static const efi_guid_t efi_guid_firmware_management_capsule_id =
              EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
@@ -210,11 +213,38 @@ const efi_guid_t efi_guid_capsule_root_cert_guid =
 
  __weak int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
  {
-     /* The platform is supposed to provide
-      * a method for getting the public key
-      * stored in the form of efi signature
-      * list
+     /*
+      * This is a function for retrieving the public key from the
+      * platform's device tree. The platform's device tree has been
+      * concatenated with the u-boot binary.
+      * If a platform has a different mechanism to get the public
+      * key, it can define it's own function.
       */
+     const void *fdt_blob = gd->fdt_blob;
+     const void *blob;
+     const char *cnode_name = "capsule-key";
+     const char *snode_name = "signature";
+     int sig_node;
+     int len;
+
+     sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
+     if (sig_node < 0) {
+             EFI_PRINT("Unable to get signature node offset\n");
+             return -FDT_ERR_NOTFOUND;
+     }
+
+     blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len);
+
+     if (!blob || len < 0) {
+             EFI_PRINT("Unable to get capsule-key value\n");
+             *pkey = NULL;
+             *pkey_len = 0;
+             return -FDT_ERR_NOTFOUND;
+     }
+
+     *pkey = (void *)blob;
+     *pkey_len = len;
+
      return 0;
  }
 
#11 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

In reply to Sughosh Ganu

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
 Makefile | 10 ++++++++++
 1 file changed, 10 insertions(+)
Makefile +10 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
 quiet_cmd_lzma = LZMA    $@
 cmd_lzma = lzma -c -z -k -9 $< > $@
 
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+	-D $@
+
 cfg: u-boot.cfg
 
 quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
 PHONY += dtbs
 dtbs: dts/dt.dtb
 	@:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+	$(Q)$(MAKE) $(build)=dts dtbs
+	$(call cmd,mkeficapsule)
+else
 dts/dt.dtb: u-boot
 	$(Q)$(MAKE) $(build)=dts dtbs
+endif
 
 quiet_cmd_copy = COPY    $@
       cmd_copy = cp $< $@
Signature · 1 line
2.17.1
#12 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

Quoted 15 lines · Sughosh Ganu

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 7 lines
Makefile +4 -0
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+	-D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D. Please, update tools/mkeficapsule.c before using these. A man-page for mkeficapsule in doc/usage/ would be helpful.

$ tools/mkeficapsule --help
Usage: mkeficapsule [options] <output file>
Options:
         --fit <fit image>       new FIT image file
         --raw <raw image>       new raw image file
         --index <index>         update image index
         --instance <instance>   update hardware instance
         --public-key <key file> public key esl file
         --dtb <dtb file>        dtb file
         --overlay               the dtb file is an overlay
         --help                  print a help message

Best regards

Heinrich

Quoted 19 lines
Makefile +6 -0
  cfg: u-boot.cfg
 
  quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
  PHONY += dtbs
  dtbs: dts/dt.dtb
  	@:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+	$(Q)$(MAKE) $(build)=dts dtbs
+	$(call cmd,mkeficapsule)
+else
  dts/dt.dtb: u-boot
  	$(Q)$(MAKE) $(build)=dts dtbs
+endif
 
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
#13 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

Quoted 19 lines · Heinrich Schuchardt
Quoted 18 lines · Sughosh Ganu

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
Quoted 7 lines

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 4 lines
Makefile +4 -0
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+	-D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D.

This clearly shows that the feature with -K/-D has nothing to do with creating a capsule file.
Two totally different things in one place (command).
And the dtb overlay operation can be achieved by using standard commands.

I believe that the feature should be removed from mkeficapsule.

-Takahiro Akashi

Quoted 39 lines

Please, update tools/mkeficapsule.c before using these. A man-page for mkeficapsule in doc/usage/ would be helpful.

$ tools/mkeficapsule --help
Usage: mkeficapsule [options] <output file>
Options:
        --fit <fit image>       new FIT image file
        --raw <raw image>       new raw image file
        --index <index>         update image index
        --instance <instance>   update hardware instance
        --public-key <key file> public key esl file
        --dtb <dtb file>        dtb file
        --overlay               the dtb file is an overlay
        --help                  print a help message

Best regards

Heinrich

Quoted 19 lines
Makefile +6 -0
  cfg: u-boot.cfg
 
  quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
  PHONY += dtbs
  dtbs: dts/dt.dtb
  	@:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+	$(Q)$(MAKE) $(build)=dts dtbs
+	$(call cmd,mkeficapsule)
+else
  dts/dt.dtb: u-boot
  	$(Q)$(MAKE) $(build)=dts dtbs
+endif
 
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
#14 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

2021?4?28?(?) 14:44 AKASHI Takahiro <[email protected]>:

Quoted 29 lines · Heinrich Schuchardt
Quoted 19 lines · Sughosh Ganu
Quoted 18 lines

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
Quoted 7 lines

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 4 lines
Makefile +4 -0
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+   -D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D.

Quoted 4 lines

This clearly shows that the feature with -K/-D has nothing to do with creating a capsule file.
Two totally different things in one place (command).
And the dtb overlay operation can be achieved by using standard commands.

If I understand correctly, we need the following steps,
1. prepare the key for signing
2. make dtb overlay from that key
3. sign the capsule with the key

And Sughosh's implementation is using mkeficapsule for 2 and 3. Takahiro pointed that mkeficapsule is only for 3 because of its name and avoid confusion.

Is that correct?

What would you think about changing the tool name? E.g.

For step 2.
capsuletool dtb --public-key pubkey [--overlay] target.dtb

For step 3.
capsuletool capsule --raw u-boot.bin --index 1 --public-key pubkey u-boot.cap

Then we can expand it for inspection, verify etc.

Thank you,

Quoted 45 lines

I believe that the feature should be removed from mkeficapsule.

-Takahiro Akashi

Quoted 39 lines

Please, update tools/mkeficapsule.c before using these. A man-page for mkeficapsule in doc/usage/ would be helpful.

$ tools/mkeficapsule --help
Usage: mkeficapsule [options] <output file>
Options:
        --fit <fit image>       new FIT image file
        --raw <raw image>       new raw image file
        --index <index>         update image index
        --instance <instance>   update hardware instance
        --public-key <key file> public key esl file
        --dtb <dtb file>        dtb file
        --overlay               the dtb file is an overlay
        --help                  print a help message

Best regards

Heinrich

Quoted 19 lines
Makefile +6 -0
  cfg: u-boot.cfg
 
  quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
  PHONY += dtbs
  dtbs: dts/dt.dtb
    @:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+   $(Q)$(MAKE) $(build)=dts dtbs
+   $(call cmd,mkeficapsule)
+else
  dts/dt.dtb: u-boot
    $(Q)$(MAKE) $(build)=dts dtbs
+endif
 
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
Signature · 1 line
Masami Hiramatsu
#15 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

Quoted 44 lines · Masami Hiramatsu

2021?4?28?(?) 14:44 AKASHI Takahiro <[email protected]>:

Quoted 29 lines · Heinrich Schuchardt
Quoted 19 lines · Sughosh Ganu
Quoted 18 lines

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
Quoted 7 lines

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 4 lines
Makefile +4 -0
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+   -D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D.

Quoted 4 lines

This clearly shows that the feature with -K/-D has nothing to do with creating a capsule file.
Two totally different things in one place (command).
And the dtb overlay operation can be achieved by using standard commands.

If I understand correctly, we need the following steps,
1. prepare the key for signing
2. make dtb overlay from that key
3. sign the capsule with the key

And Sughosh's implementation is using mkeficapsule for 2 and 3. Takahiro pointed that mkeficapsule is only for 3 because of its name and avoid confusion.

Quoted 7 lines

Is that correct?

What would you think about changing the tool name? E.g.

For step 2.
capsuletool dtb --public-key pubkey [--overlay] target.dtb

My point is: as this command line shows, it has nothing to do with a capsule file. It simply deals with dtb blob for overlaying. (So 'capsuletool' is not appropriate.)

-Takahiro Akashi

Quoted 57 lines

For step 3.
capsuletool capsule --raw u-boot.bin --index 1 --public-key pubkey u-boot.cap

Then we can expand it for inspection, verify etc.

Thank you,

Quoted 45 lines

I believe that the feature should be removed from mkeficapsule.

-Takahiro Akashi

Quoted 39 lines

Please, update tools/mkeficapsule.c before using these. A man-page for mkeficapsule in doc/usage/ would be helpful.

$ tools/mkeficapsule --help
Usage: mkeficapsule [options] <output file>
Options:
        --fit <fit image>       new FIT image file
        --raw <raw image>       new raw image file
        --index <index>         update image index
        --instance <instance>   update hardware instance
        --public-key <key file> public key esl file
        --dtb <dtb file>        dtb file
        --overlay               the dtb file is an overlay
        --help                  print a help message

Best regards

Heinrich

Quoted 19 lines
Makefile +6 -0
  cfg: u-boot.cfg
 
  quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
  PHONY += dtbs
  dtbs: dts/dt.dtb
    @:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+   $(Q)$(MAKE) $(build)=dts dtbs
+   $(call cmd,mkeficapsule)
+else
  dts/dt.dtb: u-boot
    $(Q)$(MAKE) $(build)=dts dtbs
+endif
 
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
Signature · 1 line
Masami Hiramatsu
#16 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

Hi,

2021?5?7?(?) 17:15 AKASHI Takahiro <[email protected]>:

Quoted 51 lines · Masami Hiramatsu
Quoted 49 lines

2021?4?28?(?) 14:44 AKASHI Takahiro <[email protected]>:

Quoted 29 lines · Heinrich Schuchardt
Quoted 19 lines · Sughosh Ganu
Quoted 18 lines

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
Quoted 7 lines

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 4 lines
Makefile +4 -0
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+   -D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D.

Quoted 4 lines

This clearly shows that the feature with -K/-D has nothing to do with creating a capsule file.
Two totally different things in one place (command).
And the dtb overlay operation can be achieved by using standard commands.

If I understand correctly, we need the following steps,
1. prepare the key for signing
2. make dtb overlay from that key
3. sign the capsule with the key

And Sughosh's implementation is using mkeficapsule for 2 and 3. Takahiro pointed that mkeficapsule is only for 3 because of its name and avoid confusion.

Is that correct?

What would you think about changing the tool name? E.g.

Quoted 6 lines
Quoted 2 lines

For step 2.
capsuletool dtb --public-key pubkey [--overlay] target.dtb

My point is: as this command line shows, it has nothing to do with a capsule file. It simply deals with dtb blob for overlaying. (So 'capsuletool' is not appropriate.)

But if the capsuletool provide the devicetree template for the capsule something like test/py/tests/test_efi_capsule/pubkey.dts, we can say it is related to the capsule, because the dts is obviously for capsule. What would you think?

Thank you,

Quoted 61 lines

-Takahiro Akashi

Quoted 57 lines

For step 3.
capsuletool capsule --raw u-boot.bin --index 1 --public-key pubkey u-boot.cap

Then we can expand it for inspection, verify etc.

Thank you,

Quoted 45 lines

I believe that the feature should be removed from mkeficapsule.

-Takahiro Akashi

Quoted 39 lines

Please, update tools/mkeficapsule.c before using these. A man-page for mkeficapsule in doc/usage/ would be helpful.

$ tools/mkeficapsule --help
Usage: mkeficapsule [options] <output file>
Options:
        --fit <fit image>       new FIT image file
        --raw <raw image>       new raw image file
        --index <index>         update image index
        --instance <instance>   update hardware instance
        --public-key <key file> public key esl file
        --dtb <dtb file>        dtb file
        --overlay               the dtb file is an overlay
        --help                  print a help message

Best regards

Heinrich

Quoted 19 lines
Makefile +6 -0
  cfg: u-boot.cfg
 
  quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1104,8 +1108,14 @@ endif
  PHONY += dtbs
  dtbs: dts/dt.dtb
    @:
+ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE)$(CONFIG_EFI_PKEY_DTB_EMBED),yy)
+dts/dt.dtb: u-boot tools
+   $(Q)$(MAKE) $(build)=dts dtbs
+   $(call cmd,mkeficapsule)
+else
  dts/dt.dtb: u-boot
    $(Q)$(MAKE) $(build)=dts dtbs
+endif
 
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@

--
Masami Hiramatsu

--
Masami Hiramatsu

#17 lore raw

PATCH 5/5 Makefile: Add provision for embedding public key in platform's dtb

2021?5?7?(?) 18:57 Masami Hiramatsu <[email protected]>:

Quoted 58 lines

Hi,

2021?5?7?(?) 17:15 AKASHI Takahiro <[email protected]>:

Quoted 54 lines · Masami Hiramatsu
Quoted 51 lines

2021?4?28?(?) 14:44 AKASHI Takahiro <[email protected]>:

Quoted 29 lines · Heinrich Schuchardt
Quoted 19 lines · Sughosh Ganu
Quoted 18 lines

Add provision for embedding the public key used for capsule authentication in the platform's dtb. This is done by invoking the mkeficapsule utility which puts the public key in the efi signature list(esl) format into the dtb.

---
  Makefile | 10 ++++++++++
  1 file changed, 10 insertions(+)
Makefile +0 -0
index 193aa4d1c9..0d50c6a805 100644
@@ -1010,6 +1010,10 @@ cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
  quiet_cmd_lzma = LZMA    $@
  cmd_lzma = lzma -c -z -k -9 $< > $@
 
Quoted 7 lines

Makefile cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; } · line 1016

Quoted 4 lines
Makefile +4 -0
+quiet_cmd_mkeficapsule = MKEFICAPSULE     $@
+cmd_mkeficapsule = $(objtree)/tools/mkeficapsule -K $(CONFIG_EFI_PKEY_FILE) \
+   -D $@
+

tools/mkeficapsule --help does neither show a parameter -K nor a parameter -D.

Quoted 4 lines

This clearly shows that the feature with -K/-D has nothing to do with creating a capsule file.
Two totally different things in one place (command).
And the dtb overlay operation can be achieved by using standard commands.

If I understand correctly, we need the following steps,
1. prepare the key for signing
2. make dtb overlay from that key
3. sign the capsule with the key

And Sughosh's implementation is using mkeficapsule for 2 and 3. Takahiro pointed that mkeficapsule is only for 3 because of its name and avoid confusion.

Is that correct?

What would you think about changing the tool name? E.g.

For step 2.
capsuletool dtb --public-key pubkey [--overlay] target.dtb

Quoted 8 lines
Quoted 3 lines

My point is: as this command line shows, it has nothing to do with a capsule file. It simply deals with dtb blob for overlaying. (So 'capsuletool' is not appropriate.)

But if the capsuletool provide the devicetree template for the capsule something like test/py/tests/test_efi_capsule/pubkey.dts, we can say it is related to the capsule, because the dts is obviously for capsule. What would you think?

Ah, wait. I misunderstood. It seems that the efi_get_public_key_data() is platform dependent. Thus isn't it hard to provide a unified tool to embed the key data into the dtb because it is usable for some platform but not usable for others?

Thank you,

Signature · 1 line
Masami Hiramatsu
#18 lore raw

cover Add support for embedding public key in platform's dtb

In reply to Sughosh Ganu

Hi,

Quoted 33 lines · Sughosh Ganu

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into the
platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

Quoted 9 lines
 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44 ++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 10 deletions(-)

--
2.17.1

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

Regards,
Simon

#19 lore raw

cover Add support for embedding public key in platform's dtb

hi Simon,

Quoted 42 lines · Simon Glass

Hi,

Quoted 39 lines · Sughosh Ganu

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into the
platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44 ++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 10 deletions(-)
Quoted 8 lines
Quoted 3 lines

--
2.17.1

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

There are two weak functions being added. One is for retrieving the public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

-sughosh

#20 lore raw

cover Add support for embedding public key in platform's dtb

Quoted 80 lines · Sughosh Ganu

hi?Simon,

On Wed, 7 Apr 2021 at 21:44, Simon Glass <[email protected] <mailto:[email protected]>> wrote:

Hi,

On Wed, 7 Apr 2021 at 23:54, Sughosh Ganu <[email protected] <mailto:[email protected]>> wrote:
>
> Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option > when capsule authentication is enabled.
>
> Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE > which are used for enabling embedding of the public key in the dtb, > and specifying the esl file name.
>
> Patch 3 moves efi_capsule_auth_enabled as a weak function, which can > be used as a default mechanism for checking if capsule authentication > has been enabled.
>
> Patch 4 adds a default weak function for retrieving the public key > from the platform's dtb.
>
> Patch 5 adds the functionality to embed the esl file into the > platform's dtb during the platform build.
>
> I have tested this functionality on the STM32MP157C DK2 board. >
> [1] -
https://lists.denx.de/pipermail/u-boot/2021-March/442867.html
<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>
>
> Sughosh Ganu (5):
>? ?efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule >? ? ?authentication is enabled
>? ?efi_loader: Kconfig: Add symbols for embedding the public key into the
>? ? ?platform's dtb
>? ?efi_capsule: Add a weak function to check whether capsule >? ? ?authentication is enabled
>? ?efi_capsule: Add a weak function to get the public key needed for >? ? ?capsule authentication
>? ?Makefile: Add provision for embedding public key in platform's dtb >
>? Makefile? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 10 ++++++
>? board/emulation/common/qemu_capsule.c |? 6 ----
>? lib/efi_loader/Kconfig? ? ? ? ? ? ? ? | 16 ++++++++++
>? lib/efi_loader/efi_capsule.c? ? ? ? ? | 44
++++++++++++++++++++++++---
>? 4 files changed, 66 insertions(+), 10 deletions(-)
>
> --
> 2.17.1
>

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

There are two weak functions being added. One is for retrieving the public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

Quoted 1 line

-sughosh

Hello Sughosh,

Could you, please, explain why there could be a need to use public keys for capsule verification that are not compiled into U-Boot. I cannot see how this would increase security.

I cannot imagine any scenario where you would want to allow switching off capsule authentication if it has been built into U-Boot.

Best regards

Heinrich

#21 lore raw

cover Add support for embedding public key in platform's dtb

hi Heinrich,

Quoted 86 lines · Heinrich Schuchardt
Quoted 11 lines · Sughosh Ganu

hi Simon,

On Wed, 7 Apr 2021 at 21:44, Simon Glass <[email protected] <mailto:[email protected]>> wrote:

Hi,

On Wed, 7 Apr 2021 at 23:54, Sughosh Ganu <[email protected] <mailto:[email protected]>> wrote:
>
> Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config

option

Quoted 3 lines
Quoted 3 lines

when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and

EFI_PKEY_FILE

Quoted 4 lines
Quoted 4 lines

which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which

can

Quoted 1 line
Quoted 1 line

be used as a default mechanism for checking if capsule

authentication

Quoted 14 lines
Quoted 11 lines

has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] -

https://lists.denx.de/pipermail/u-boot/2021-March/442867.html
<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>
>

Quoted 11 lines

> Sughosh Ganu (5):
> efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
> authentication is enabled
> efi_loader: Kconfig: Add symbols for embedding the public key
into the
> platform's dtb
> efi_capsule: Add a weak function to check whether capsule
> authentication is enabled
> efi_capsule: Add a weak function to get the public key needed for
> capsule authentication
> Makefile: Add provision for embedding public key in platform's

dtb

Quoted 36 lines
Quoted 5 lines
 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44
    ++++++++++++++++++++++++---
    >  4 files changed, 66 insertions(+), 10 deletions(-)
    >
    > --
    > 2.17.1
    >

    We need to rethink the use of weak functions for this sort of thing,
    or we will end up with an unnavigable mess at some point. If we need
    to adjust the flow of boot, let's adjust the flow rather than adding
    hooks everywhere.

There are two weak functions being added. One is for retrieving the public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

Quoted 8 lines
Quoted 1 line

-sughosh

Hello Sughosh,

Could you, please, explain why there could be a need to use public keys for capsule verification that are not compiled into U-Boot. I cannot see how this would increase security.

With the changes that have been made in the Makefile(patch 5/5), the public key is now embedded into the platform's dtb, and subsequently this dtb is concatenated with the u-boot binary to create a single u-boot.bin image. This image can then be verified during the trusted boot flow to check against any kind of tampering. This takes care of your concern of not having the public key separately on the disk, which makes it open to tampering, with the public key now embedded as part of the u-boot image. You had suggested embedding the public key as part of the u-boot image. I have embedded it within the platform's dtb which is part of the u-boot image. This becomes a generic solution which is platform and architecture agnostic. I believe concatenating the platform's dtb with the u-boot binary is the standard flow for production images.

I cannot imagine any scenario where you would want to allow switching

Quoted 2 lines

off capsule authentication if it has been built into U-Boot.

This is only an additional knob for any user who might want to perform a capsule update without authentication -- with this additional knob, the user can use the same image for updating a capsule which does not have an authentication header. The user would not be required to recompile the image to turn off CONFIG_EFI_CAPSULE_AUTHENTICATE config option. But if you don't see this necessary, i can remove this additional check. In that case, the capsule will be authenticated when CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled.

-sughosh

#22 lore raw

cover Add support for embedding public key in platform's dtb

Quoted 113 lines · Sughosh Ganu

hi Heinrich,

On Thu, 8 Apr 2021 at 14:17, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 08.04.21 08:53, Sughosh Ganu wrote:
> hi?Simon,
>
> On Wed, 7 Apr 2021 at 21:44, Simon Glass <[email protected] <mailto:[email protected]>
> <mailto:sjg at chromium.org <mailto:[email protected]>>> wrote:
>
>? ? ?Hi,
>
>? ? ?On Wed, 7 Apr 2021 at 23:54, Sughosh Ganu <sughosh.ganu at linaro.org <mailto:[email protected]> >? ? ?<mailto:[email protected] <mailto:[email protected]>>> wrote:
>? ? ?>
>? ? ?> Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option
>? ? ?> when capsule authentication is enabled.
>? ? ?>
>? ? ?> Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE
>? ? ?> which are used for enabling embedding of the public key in the dtb,
>? ? ?> and specifying the esl file name.
>? ? ?>
>? ? ?> Patch 3 moves efi_capsule_auth_enabled as a weak function, which can
>? ? ?> be used as a default mechanism for checking if capsule authentication
>? ? ?> has been enabled.
>? ? ?>
>? ? ?> Patch 4 adds a default weak function for retrieving the public key
>? ? ?> from the platform's dtb.
>? ? ?>
>? ? ?> Patch 5 adds the functionality to embed the esl file into the >? ? ?> platform's dtb during the platform build.
>? ? ?>
>? ? ?> I have tested this functionality on the STM32MP157C DK2 board. >? ? ?>
>? ? ?> [1] -
>? ? ?https://lists.denx.de/pipermail/u-boot/2021-March/442867.html
<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>
>? ? ?<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html
<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>>
>? ? ?>
>? ? ?> Sughosh Ganu (5):
>? ? ?>? ?efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule >? ? ?>? ? ?authentication is enabled
>? ? ?>? ?efi_loader: Kconfig: Add symbols for embedding the public key >? ? ?into the
>? ? ?>? ? ?platform's dtb
>? ? ?>? ?efi_capsule: Add a weak function to check whether capsule >? ? ?>? ? ?authentication is enabled
>? ? ?>? ?efi_capsule: Add a weak function to get the public key needed for
>? ? ?>? ? ?capsule authentication
>? ? ?>? ?Makefile: Add provision for embedding public key in platform's dtb
>? ? ?>
>? ? ?>? Makefile? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 10 ++++++ >? ? ?>? board/emulation/common/qemu_capsule.c |? 6 ----
>? ? ?>? lib/efi_loader/Kconfig? ? ? ? ? ? ? ? | 16 ++++++++++ >? ? ?>? lib/efi_loader/efi_capsule.c? ? ? ? ? | 44
>? ? ?++++++++++++++++++++++++---
>? ? ?>? 4 files changed, 66 insertions(+), 10 deletions(-) >? ? ?>
>? ? ?> --
>? ? ?> 2.17.1
>? ? ?>
>
>? ? ?We need to rethink the use of weak functions for this sort of thing,
>? ? ?or we will end up with an unnavigable mess at some point. If we need
>? ? ?to adjust the flow of boot, let's adjust the flow rather than adding
>? ? ?hooks everywhere.
>
>
> There are two weak functions being added. One is for retrieving the > public key to be used for the capsule authentication, and the other is > for checking for whether capsule authentication has been enabled. The > reason why a weak function is needed is because platforms can have other
> mechanisms for retrieval of the public key or for testing if capsule > authentication has been enabled.
>
> If we consider the case of public key retrieval, the majority of > platforms would be built with the device tree concatenated with the > u-boot binary. The weak function would cater to all of those platforms > -- having a weak function would mean that we are not required to repeat
> the same functionality for every platform that uses the same mechanism > for extracting the public key. However, there would be platforms where > the public key is obtained through a different mechanism which is > platform specific. Those platforms would have to define their own > function to get the public key. Same for checking whether capsule > authentication feature has been enabled or not.
>
> -sughosh

Hello Sughosh,

Could you, please, explain why there could be a need to use public keys for capsule verification that are not compiled into U-Boot. I cannot see how this would increase security.

Quoted 13 lines

With the changes that have been made in the Makefile(patch 5/5), the public key is now embedded into the platform's dtb, and subsequently this dtb is concatenated with the u-boot binary to create a single u-boot.bin image. This image can then be verified during the trusted boot flow to check against any kind of tampering. This takes care of your concern of not having the public key separately on the disk, which makes it open to tampering, with the public key now embedded as part of the u-boot image. You had suggested embedding the public key as part of the u-boot image. I have embedded it within the platform's dtb which is part of the u-boot image. This becomes a generic solution which is platform and architecture agnostic. I believe concatenating the platform's dtb with the u-boot binary is the standard flow for production images.

Embedding the key in the device-tree is fine. I am just trying to understand why you need the extensibility via a weak function.

Quoted 5 lines

I cannot imagine any scenario where you would want to allow switching off capsule authentication if it has been built into U-Boot.

Quoted 8 lines

This is only an additional knob for any user who might want to perform a capsule update without authentication -- with this additional knob, the user can use?the same image for updating a capsule which does not have an authentication header. The user would not be required to recompile the image to turn off CONFIG_EFI_CAPSULE_AUTHENTICATE config option. But if you don't see this necessary, i can remove this additional check. In that case, the capsule will be authenticated when CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled.

I would prefer to reduce the number of "knobs" that you have to check when rolling out secure firmware.

Best regards

Heinrich

#23 lore raw

cover Add support for embedding public key in platform's dtb

Quoted 138 lines · Heinrich Schuchardt
Quoted 35 lines · Sughosh Ganu

hi Heinrich,

On Thu, 8 Apr 2021 at 14:17, Heinrich Schuchardt <[email protected] <mailto:[email protected]>> wrote:

On 08.04.21 08:53, Sughosh Ganu wrote:
> hi Simon,
>
> On Wed, 7 Apr 2021 at 21:44, Simon Glass <[email protected] <mailto:[email protected]>
> <mailto:sjg at chromium.org <mailto:[email protected]>>> wrote:
>
> Hi,
>
> On Wed, 7 Apr 2021 at 23:54, Sughosh Ganu
<sughosh.ganu at linaro.org <mailto:[email protected]>
> <mailto:[email protected]
<mailto:[email protected]>>> wrote:
> >
> > Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO
config option
> > when capsule authentication is enabled.
> >
> > Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and
EFI_PKEY_FILE
> > which are used for enabling embedding of the public key in
the dtb,
> > and specifying the esl file name.
> >
> > Patch 3 moves efi_capsule_auth_enabled as a weak function,
which can
> > be used as a default mechanism for checking if capsule
authentication
> > has been enabled.
> >

Quoted 8 lines

> > Patch 4 adds a default weak function for retrieving the
public key
> > from the platform's dtb.
> >
> > Patch 5 adds the functionality to embed the esl file into the
> > platform's dtb during the platform build.
> >
> > I have tested this functionality on the STM32MP157C DK2

board.

Quoted 11 lines
Quoted 3 lines
Quoted 2 lines

[1] -

    https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>
> <https://lists.denx.de/pipermail/u-boot/2021-March/442867.html
<https://lists.denx.de/pipermail/u-boot/2021-March/442867.html>>
> >
> > Sughosh Ganu (5):
> > efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
> > authentication is enabled
> > efi_loader: Kconfig: Add symbols for embedding the public

key

Quoted 30 lines
Quoted 5 lines

into the
> platform's dtb
> efi_capsule: Add a weak function to check whether capsule
> authentication is enabled
> efi_capsule: Add a weak function to get the public key

needed for
> > capsule authentication
> > Makefile: Add provision for embedding public key in
platform's dtb
> >
> > Makefile | 10 ++++++
> > board/emulation/common/qemu_capsule.c | 6 ----
> > lib/efi_loader/Kconfig | 16 ++++++++++
> > lib/efi_loader/efi_capsule.c | 44
> ++++++++++++++++++++++++---
> > 4 files changed, 66 insertions(+), 10 deletions(-)
> >
> > --
> > 2.17.1
> >
>
> We need to rethink the use of weak functions for this sort of
thing,
> or we will end up with an unnavigable mess at some point. If
we need
> to adjust the flow of boot, let's adjust the flow rather than
adding
> hooks everywhere.
>
>

Quoted 2 lines

> There are two weak functions being added. One is for retrieving the > public key to be used for the capsule authentication, and the

other is

Quoted 1 line
Quoted 1 line

for checking for whether capsule authentication has been enabled.

The

Quoted 3 lines
Quoted 1 line

reason why a weak function is needed is because platforms can have

other
> mechanisms for retrieval of the public key or for testing if

capsule

Quoted 5 lines
Quoted 5 lines

authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those

platforms

Quoted 3 lines
Quoted 1 line

-- having a weak function would mean that we are not required to

repeat
> the same functionality for every platform that uses the same

mechanism

Quoted 1 line
Quoted 1 line

for extracting the public key. However, there would be platforms

where

Quoted 10 lines
Quoted 6 lines

the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

-sughosh

Hello Sughosh,

Could you, please, explain why there could be a need to use public

keys

Quoted 1 line

for capsule verification that are not compiled into U-Boot. I cannot

see

Quoted 16 lines

how this would increase security.

With the changes that have been made in the Makefile(patch 5/5), the public key is now embedded into the platform's dtb, and subsequently this dtb is concatenated with the u-boot binary to create a single u-boot.bin image. This image can then be verified during the trusted boot flow to check against any kind of tampering. This takes care of your concern of not having the public key separately on the disk, which makes it open to tampering, with the public key now embedded as part of the u-boot image. You had suggested embedding the public key as part of the u-boot image. I have embedded it within the platform's dtb which is part of the u-boot image. This becomes a generic solution which is platform and architecture agnostic. I believe concatenating the platform's dtb with the u-boot binary is the standard flow for production images.

Quoted 3 lines

Embedding the key in the device-tree is fine. I am just trying to understand why you need the extensibility via a weak function.

This is to provide flexibility for any platform that might have a different mechanism of passing/retrieving the public key. Some platforms might have their dtb passed from an earlier stage firmware, like tf-a. Or there could be a read-only device like a fuse which houses the keys to be used. Having a weak default would allow such platforms to implement a platform specific function to retrieve the public key. So if there is no technical disadvantage of having a weak default, I think keeping this flexibility for platforms would be good.

Quoted 15 lines
Quoted 6 lines

I cannot imagine any scenario where you would want to allow switching off capsule authentication if it has been built into U-Boot.

Quoted 8 lines

This is only an additional knob for any user who might want to perform a capsule update without authentication -- with this additional knob, the user can use the same image for updating a capsule which does not have an authentication header. The user would not be required to recompile the image to turn off CONFIG_EFI_CAPSULE_AUTHENTICATE config option. But if you don't see this necessary, i can remove this additional check. In that case, the capsule will be authenticated when CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled.

Quoted 3 lines

I would prefer to reduce the number of "knobs" that you have to check when rolling out secure firmware.

Okay. I will remove this extra check in the next version. Whether the platform authenticates the capsule or not would then depend solely on the config option.

-sughosh

#24 lore raw

cover Add support for embedding public key in platform's dtb

In reply to Sughosh Ganu

Hi Sughosh,

Quoted 57 lines · Sughosh Ganu

hi Simon,

Quoted 43 lines · Simon Glass

Hi,

Quoted 39 lines · Sughosh Ganu

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into the
platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44 ++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 10 deletions(-)
Quoted 8 lines
Quoted 3 lines

--
2.17.1

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

Quoted 5 lines

There are two weak functions being added. One is for retrieving the public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

-sughosh

Yes, I get it, but if this is to be a critical feature and part of the grand new design for verified boot using UEFI, surely we should be building a new front door, not digging a tunnel in the bathroom :-)

We can either use drivers with driver model, or perhaps have a Kconfig that enables calling the function (so we get a link error if not provided). Or if there will be more than one handler, a linker_list.

Perhaps it is time to consider a 'hook' system, with a command to let us see what hooks are active for any particular event?

Regards,
Simon

#25 lore raw

cover Add support for embedding public key in platform's dtb

hi Simon,

Quoted 83 lines · Simon Glass

Hi Sughosh,

Quoted 8 lines · Sughosh Ganu

hi Simon,

Quoted 4 lines · Simon Glass

Hi,

On Wed, 7 Apr 2021 at 23:54, Sughosh Ganu <[email protected]>

Quoted 18 lines · wrote:
Quoted 18 lines
Quoted 18 lines

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into

the

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44

++++++++++++++++++++++++---

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
 4 files changed, 66 insertions(+), 10 deletions(-)

--
2.17.1

Quoted 7 lines
Quoted 4 lines

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

There are two weak functions being added. One is for retrieving the

public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

Quoted 2 lines

If we consider the case of public key retrieval, the majority of

platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

Quoted 2 lines

-sughosh

Quoted 8 lines

Yes, I get it, but if this is to be a critical feature and part of the grand new design for verified boot using UEFI, surely we should be building a new front door, not digging a tunnel in the bathroom :-)

We can either use drivers with driver model, or perhaps have a Kconfig that enables calling the function (so we get a link error if not provided). Or if there will be more than one handler, a linker_list.

I will use the Kconfig symbol for selecting the function to use for retrieving the public key. So, in the current scenario, the function would be under the CONFIG_EFI_PKEY_DTB_EMBED symbol. This should cater to the majority of the cases. If some platform wants to use a different method to get the public key, it would need to define it's own function.

-sughosh

Quoted 7 lines

Perhaps it is time to consider a 'hook' system, with a command to let us see what hooks are active for any particular event?

Regards,
Simon

#26 lore raw

cover Add support for embedding public key in platform's dtb

Hi Sughosh,

Quoted 75 lines · Sughosh Ganu

hi Simon,

Quoted 71 lines · Simon Glass

Hi Sughosh,

Quoted 57 lines · Sughosh Ganu

hi Simon,

Quoted 43 lines · Simon Glass

Hi,

Quoted 39 lines · Sughosh Ganu

Patch 1 fixes an issue of selection of IMAGE_SIGN_INFO config option when capsule authentication is enabled.

Patch 2 add two config symbols, EFI_PKEY_DTB_EMBED and EFI_PKEY_FILE which are used for enabling embedding of the public key in the dtb, and specifying the esl file name.

Patch 3 moves efi_capsule_auth_enabled as a weak function, which can be used as a default mechanism for checking if capsule authentication has been enabled.

Patch 4 adds a default weak function for retrieving the public key from the platform's dtb.

Patch 5 adds the functionality to embed the esl file into the platform's dtb during the platform build.

I have tested this functionality on the STM32MP157C DK2 board.

[1] - https://lists.denx.de/pipermail/u-boot/2021-March/442867.html

Sughosh Ganu (5):
efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule
authentication is enabled
efi_loader: Kconfig: Add symbols for embedding the public key into the
platform's dtb
efi_capsule: Add a weak function to check whether capsule
authentication is enabled
efi_capsule: Add a weak function to get the public key needed for
capsule authentication
Makefile: Add provision for embedding public key in platform's dtb

 Makefile                              | 10 ++++++
 board/emulation/common/qemu_capsule.c |  6 ----
 lib/efi_loader/Kconfig                | 16 ++++++++++
 lib/efi_loader/efi_capsule.c          | 44 ++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 10 deletions(-)
Quoted 8 lines
Quoted 3 lines

--
2.17.1

We need to rethink the use of weak functions for this sort of thing, or we will end up with an unnavigable mess at some point. If we need to adjust the flow of boot, let's adjust the flow rather than adding hooks everywhere.

Quoted 5 lines

There are two weak functions being added. One is for retrieving the public key to be used for the capsule authentication, and the other is for checking for whether capsule authentication has been enabled. The reason why a weak function is needed is because platforms can have other mechanisms for retrieval of the public key or for testing if capsule authentication has been enabled.

If we consider the case of public key retrieval, the majority of platforms would be built with the device tree concatenated with the u-boot binary. The weak function would cater to all of those platforms -- having a weak function would mean that we are not required to repeat the same functionality for every platform that uses the same mechanism for extracting the public key. However, there would be platforms where the public key is obtained through a different mechanism which is platform specific. Those platforms would have to define their own function to get the public key. Same for checking whether capsule authentication feature has been enabled or not.

-sughosh

Yes, I get it, but if this is to be a critical feature and part of the grand new design for verified boot using UEFI, surely we should be building a new front door, not digging a tunnel in the bathroom :-)

Quoted 6 lines
Quoted 3 lines

We can either use drivers with driver model, or perhaps have a Kconfig that enables calling the function (so we get a link error if not provided). Or if there will be more than one handler, a linker_list.

I will use the Kconfig symbol for selecting the function to use for retrieving the public key. So, in the current scenario, the function would be under the CONFIG_EFI_PKEY_DTB_EMBED symbol. This should cater to the majority of the cases. If some platform wants to use a different method to get the public key, it would need to define it's own function.

I wonder why another method would be needed, but if it, then someone can turn your thing into a choice, I suppose.

Regards,
Simon