Skip to contentSkip to conversation

tools: Add support for signing devicetree blobs

PATCH In review Simon Glass 5 participants 41 messages Nov 12, 2021 – Jan 26, 2022

lore
Share & tools
lore
#0 lore raw

cover tools: Add support for signing devicetree blobs

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

a) it requires adding support for FIT into other bootloaders, notably UEFI
b) it requires packaging a kernel in this standard U-Boot format, meaning that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

The kernel and initrd can be dealt with in other ways. But without FIT, we have no standard way of signing and grouping FDT files. Instead we must include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format, it is possible to embed a signature inside the FDT itself, which is very convenient.

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT, other than in permitted nodes (e.g. /chosen).

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs to be determined.

For now there is absolutely no configurability in the signature mechanism. It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the /chosen node is implemented in h_exclude_nodes() like this:

   if (type == FDT_IS_NODE) {
      /* Ignore the chosen node as well as /signature and subnodes */
      if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
         return 0;
   }

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well as refactoring to avoid code duplication with the new tools. The last four patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

 MAINTAINERS                      |   7 +
 boot/image-fit-sig.c             | 151 +++++++++----
 boot/image-fit.c                 |  12 +-
 common/spl/spl_fit.c             |   3 +-
 doc/fdt_check_sign.1             |  74 +++++++
 doc/fdt_sign.1                   | 111 ++++++++++
 include/image.h                  |  80 ++++++-
 include/u-boot/ecdsa.h           |   5 +-
 include/u-boot/rsa.h             |   5 +-
 lib/ecdsa/ecdsa-libcrypto.c      |   4 +-
 lib/rsa/rsa-sign.c               |   5 +-
 lib/rsa/rsa-verify.c             |  13 +-
 test/py/tests/test_fdt_sign.py   |  83 ++++++++
 test/py/tests/test_vboot.py      |  21 +-
 test/py/tests/vboot/sign-fdt.dts |  23 ++
 test/py/tests/vboot_comm.py      |  22 ++
 tools/Makefile                   |  10 +-
 tools/fdt-host.c                 | 353 +++++++++++++++++++++++++++++++
 tools/fdt_check_sign.c           |  85 ++++++++
 tools/fdt_host.h                 |  46 ++++
 tools/fdt_sign.c                 | 210 ++++++++++++++++++
 tools/fit_check_sign.c           |   4 +-
 tools/fit_common.c               |  69 ++++++
 tools/fit_common.h               |  23 ++
 tools/fit_image.c                |  59 +-----
 tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++
 tools/image-host.c               | 155 +++++++++++---
 tools/imagetool.h                |   4 +
 tools/mkimage.c                  |   4 +
 29 files changed, 1714 insertions(+), 181 deletions(-)
 create mode 100644 doc/fdt_check_sign.1
 create mode 100644 doc/fdt_sign.1
 create mode 100644 test/py/tests/test_fdt_sign.py
 create mode 100644 test/py/tests/vboot/sign-fdt.dts
 create mode 100644 test/py/tests/vboot_comm.py
 create mode 100644 tools/fdt-host.c
 create mode 100644 tools/fdt_check_sign.c
 create mode 100644 tools/fdt_sign.c
 create mode 100644 tools/image-fdt-sig.c
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#1 lore raw

PATCH 1/16 rsa: Add debugging for failure cases

Add some more debugging to make it easier to see what is being tried and what fails. Fix a few comment styles while here.

---

 lib/rsa/rsa-verify.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
lib/rsa/rsa-verify.c +10 -3
index 83f7564101c..26ee256cf4c 100644
@@ -79,14 +79,14 @@ int padding_pkcs_15_verify(struct image_sign_info *info,
 	struct checksum_algo *checksum = info->checksum;
 	int ret, pad_len = msg_len - checksum->checksum_len;
 
-	/* Check pkcs1.5 padding bytes. */
+	/* Check pkcs1.5 padding bytes */
 	ret = rsa_verify_padding(msg, pad_len, checksum);
 	if (ret) {
 		debug("In RSAVerify(): Padding check failed!\n");
 		return -EINVAL;
 	}
 
-	/* Check hash. */
+	/* Check hash */
 	if (memcmp((uint8_t *)msg + pad_len, hash, msg_len - pad_len)) {
 		debug("In RSAVerify(): Hash check failed!\n");
 		return -EACCES;
@@ -502,7 +502,8 @@ int rsa_verify_hash(struct image_sign_info *info,
 	if (CONFIG_IS_ENABLED(RSA_VERIFY_WITH_PKEY) && !info->fdt_blob) {
 		/* don't rely on fdt properties */
 		ret = rsa_verify_with_pkey(info, hash, sig, sig_len);
-
+		if (ret)
+			debug("%s: rsa_verify_with_pkey() failed\n", __func__);
 		return ret;
 	}
 
@@ -522,6 +523,9 @@ int rsa_verify_hash(struct image_sign_info *info,
 		if (info->required_keynode != -1) {
 			ret = rsa_verify_with_keynode(info, hash, sig, sig_len,
 						      info->required_keynode);
+			if (ret)
+				debug("%s: Failed to verify required_keynode\n",
+				      __func__);
 			return ret;
 		}
 
@@ -531,6 +535,8 @@ int rsa_verify_hash(struct image_sign_info *info,
 		ret = rsa_verify_with_keynode(info, hash, sig, sig_len, node);
 		if (!ret)
 			return ret;
+		debug("%s: Could not verify key '%s', trying all\n", __func__,
+		      name);
 
 		/* No luck, so try each of the keys in turn */
 		for (ndepth = 0, noffset = fdt_next_node(blob, sig_node,
@@ -546,6 +552,7 @@ int rsa_verify_hash(struct image_sign_info *info,
 			}
 		}
 	}
+	debug("%s: Failed to verify by any means\n", __func__);
 
 	return ret;
 }
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#2 lore raw

Re: [PATCH 01/16] rsa: Add debugging for failure cases

Add some more debugging to make it easier to see what is being tried and what fails. Fix a few comment styles while here.

---

 lib/rsa/rsa-verify.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!

#3 lore raw

PATCH 2/16 fit_check_sign: Update help to mention the key is in a dtb

In reply to Simon Glass

The key is inside a dtb file, so tweak the help to make that clear.

---

 tools/fit_check_sign.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/fit_check_sign.c +2 -2
index 5573842d251..3d1d33fdab1 100644
@@ -27,7 +27,7 @@ void usage(char *cmdname)
 {
 	fprintf(stderr, "Usage: %s -f fit file -k key file -c config name\n"
 			 "          -f ==> set fit file which should be checked'\n"
-			 "          -k ==> set key file which contains the key'\n"
+			 "          -k ==> set key .dtb file which contains the key'\n"
 			 "          -c ==> set the configuration name'\n",
 		cmdname);
 	exit(EXIT_FAILURE);
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
 		fprintf(stderr, "Signature check OK\n");
 	} else {
 		ret = EXIT_FAILURE;
-		fprintf(stderr, "Signature check Bad (error %d)\n", ret);
+		fprintf(stderr, "Signature check bad (error %d)\n", ret);
 	}
 
 	(void) munmap((void *)fit_blob, fsbuf.st_size);
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#4 lore raw

Re: [PATCH 02/16] fit_check_sign: Update help to mention the key is in a dtb

The key is inside a dtb file, so tweak the help to make that clear.

---

 tools/fit_check_sign.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

#5 lore raw

PATCH 3/16 tools: Move copyfile() into a common file

In reply to Simon Glass

This function is useful in other places. Move it to a common file.

---

 tools/fit_common.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/fit_common.h | 11 +++++++++
 tools/fit_image.c  | 56 ----------------------------------------------
 3 files changed, 67 insertions(+), 56 deletions(-)
tools/fit_common.c +56 -0
index 52b63296f89..c161f23b0f7 100644
@@ -111,3 +111,59 @@ err:
 
 	return -1;
 }
+
+int copyfile(const char *src, const char *dst)
+{
+	int fd_src = -1, fd_dst = -1;
+	void *buf = NULL;
+	ssize_t size;
+	size_t count;
+	int ret = -1;
+
+	fd_src = open(src, O_RDONLY);
+	if (fd_src < 0) {
+		printf("Can't open file %s (%s)\n", src, strerror(errno));
+		goto out;
+	}
+
+	fd_dst = open(dst, O_WRONLY | O_CREAT, 0666);
+	if (fd_dst < 0) {
+		printf("Can't open file %s (%s)\n", dst, strerror(errno));
+		goto out;
+	}
+
+	buf = calloc(1, 512);
+	if (!buf) {
+		printf("Can't allocate buffer to copy file\n");
+		goto out;
+	}
+
+	while (1) {
+		size = read(fd_src, buf, 512);
+		if (size < 0) {
+			printf("Can't read file %s\n", src);
+			goto out;
+		}
+		if (!size)
+			break;
+
+		count = size;
+		size = write(fd_dst, buf, count);
+		if (size < 0) {
+			printf("Can't write file %s\n", dst);
+			goto out;
+		}
+	}
+
+	ret = 0;
+
+ out:
+	if (fd_src >= 0)
+		close(fd_src);
+	if (fd_dst >= 0)
+		close(fd_dst);
+	if (buf)
+		free(buf);
+
+	return ret;
+}
tools/fit_common.h +11 -0
index 1e81d4c68b6..a76c4001c59 100644
@@ -39,4 +39,15 @@ int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
 	     void **blobp, struct stat *sbuf, bool delete_on_error,
 	     bool read_only);
 
+/**
+ * copyfile() - Copy a file
+ *
+ * This uses read()/write() to copy file @src to file @dst
+ *
+ * @src: Filename to read from
+ * @dst: Filename to write to
+ * @return 0 if OK, -1 on error
+ */
+int copyfile(const char *src, const char *dst);
+
 #endif /* _FIT_COMMON_H_ */
tools/fit_image.c +0 -56

62 lines not on this page · raw message

Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#6 lore raw

Re: [PATCH 03/16] tools: Move copyfile() into a common file

This function is useful in other places. Move it to a common file.

---

 tools/fit_common.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/fit_common.h | 11 +++++++++
 tools/fit_image.c  | 56 ----------------------------------------------
 3 files changed, 67 insertions(+), 56 deletions(-)

Applied to u-boot-dm, thanks!

#7 lore raw

PATCH 4/16 tools: Avoid leaving extra data at the end of copied files

In reply to Simon Glass

The copyfile() implementation has strange behaviour if the destination file already exists. Update it to ensure that any existing data in the destination file is dropped.

---

 tools/fit_common.c | 2 +-
 tools/fit_common.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/fit_common.c +1 -1
index c161f23b0f7..d13e5ebf1ae 100644
@@ -126,7 +126,7 @@ int copyfile(const char *src, const char *dst)
 		goto out;
 	}
 
-	fd_dst = open(dst, O_WRONLY | O_CREAT, 0666);
+	fd_dst = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 	if (fd_dst < 0) {
 		printf("Can't open file %s (%s)\n", dst, strerror(errno));
 		goto out;
tools/fit_common.h +2 -0
index a76c4001c59..55f3f6acd4e 100644
@@ -44,6 +44,8 @@ int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
  *
  * This uses read()/write() to copy file @src to file @dst
  *
+ * If @dst exists, it is overwritten and truncated to the correct size.
+ *
  * @src: Filename to read from
  * @dst: Filename to write to
  * @return 0 if OK, -1 on error
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#8 lore raw

Re: [PATCH 04/16] tools: Avoid leaving extra data at the end of copied files

The copyfile() implementation has strange behaviour if the destination file already exists. Update it to ensure that any existing data in the destination file is dropped.

---

 tools/fit_common.c | 2 +-
 tools/fit_common.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

#9 lore raw

PATCH 5/16 tools: Improve comments in signing functions

In reply to Simon Glass

Add some more comments to explain what is going on in the signing functions. Fix two repeated typos.

---

 include/image.h    |  2 +-
 tools/fdt_host.h   |  8 ++++
 tools/image-host.c | 98 +++++++++++++++++++++++++++++++++++-----------
 3 files changed, 85 insertions(+), 23 deletions(-)
include/image.h +1 -1
index fd662e74b41..533c23e2002 100644
@@ -1025,7 +1025,7 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
  * fit_add_verification_data() - add verification data to FIT image nodes
  *
  * @keydir:	Directory containing keys
- * @kwydest:	FDT blob to write public key information to
+ * @kwydest:	FDT blob to write public key information to (NULL if none)
  * @fit:	Pointer to the FIT format image header
  * @comment:	Comment to add to signature nodes
  * @require_keys: Mark all keys as 'required'
tools/fdt_host.h +8 -0
index 15c07c7a96e..bc42306c9e5 100644
@@ -27,6 +27,14 @@
  */
 int fdt_remove_unused_strings(const void *old, void *new);
 
+/**
+ * fit_check_sign() - Check a signature in a FIT
+ *
+ * @fit: FIT to check
+ * @key: Key FDT blob to check against
+ * @fit_uname_config: Name of configuration to check (NULL for default)
+ * @return 0 if OK, -ve if signature failed
+ */
 int fit_check_sign(const void *fit, const void *key,
 		   const char *fit_uname_config);
 
tools/image-host.c +76 -22

171 lines not on this page · raw message

Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#10 lore raw

Re: [PATCH 05/16] tools: Improve comments in signing functions

Add some more comments to explain what is going on in the signing functions. Fix two repeated typos.

---

 include/image.h    |  2 +-
 tools/fdt_host.h   |  8 ++++
 tools/image-host.c | 98 +++++++++++++++++++++++++++++++++++-----------
 3 files changed, 85 insertions(+), 23 deletions(-)

Applied to u-boot-dm, thanks!

#11 lore raw

PATCH 6/16 tools: Drop unused name in image-host

In reply to Simon Glass

The name is created but never used. Drop it.

---

 tools/image-host.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/image-host.c +1 -4
index 73d35f3eee3..e4322d323a2 100644
@@ -725,7 +725,7 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
 			       struct strlist *node_inc, const char *conf_name,
 			       const char *sig_name, const char *iname)
 {
-	char name[200], path[200];
+	char path[200];
 	int noffset;
 	int hash_count;
 	int ret;
@@ -736,9 +736,6 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
 	if (strlist_add(node_inc, path))
 		goto err_mem;
 
-	snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
-		 conf_name);
-
 	/* Add all this image's hashes */
 	hash_count = 0;
 	for (noffset = fdt_first_subnode(fit, image_noffset);
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#12 lore raw

Re: [PATCH 06/16] tools: Drop unused name in image-host

The name is created but never used. Drop it.

---

 tools/image-host.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Applied to u-boot-dm, thanks!

#13 lore raw

PATCH 7/16 tools: Avoid confusion between keys and signatures

In reply to Simon Glass

We should be consistent in using the term 'signature' to describe a value added to sign something and 'key' to describe the key that can be used to verify the signature.

Tidy up the code to stick to this.

Add some comments to fit_config_verify_key() and its callers while we are here.

---

 boot/image-fit-sig.c | 97 ++++++++++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 25 deletions(-)
boot/image-fit-sig.c +72 -25
index 63e5423c925..f0ccd9b5227 100644
@@ -135,7 +135,7 @@ int fit_image_check_sig(const void *fit, int noffset, const void *data,
 
 static int fit_image_verify_sig(const void *fit, int image_noffset,
 				const char *data, size_t size,
-				const void *sig_blob, int sig_offset)
+				const void *key_blob, int key_offset)
 {
 	int noffset;
 	char *err_msg = "";
@@ -184,34 +184,34 @@ error:
 
 int fit_image_verify_required_sigs(const void *fit, int image_noffset,
 				   const char *data, size_t size,
-				   const void *sig_blob, int *no_sigsp)
+				   const void *key_blob, int *no_sigsp)
 {
 	int verify_count = 0;
 	int noffset;
-	int sig_node;
+	int key_node;
 
 	/* Work out what we need to verify */
 	*no_sigsp = 1;
-	sig_node = fdt_subnode_offset(sig_blob, 0, FIT_SIG_NODENAME);
-	if (sig_node < 0) {
+	key_node = fdt_subnode_offset(key_blob, 0, FIT_SIG_NODENAME);
+	if (key_node < 0) {
 		debug("%s: No signature node found: %s\n", __func__,
-		      fdt_strerror(sig_node));
+		      fdt_strerror(key_node));
 		return 0;
 	}
 
-	fdt_for_each_subnode(noffset, sig_blob, sig_node) {
+	fdt_for_each_subnode(noffset, key_blob, key_node) {
 		const char *required;
 		int ret;
 
-		required = fdt_getprop(sig_blob, noffset, FIT_KEY_REQUIRED,
+		required = fdt_getprop(key_blob, noffset, FIT_KEY_REQUIRED,
 				       NULL);
 		if (!required || strcmp(required, "image"))
 			continue;
 		ret = fit_image_verify_sig(fit, image_noffset, data, size,
-					   sig_blob, noffset);
+					   key_blob, noffset);
 		if (ret) {
 			printf("Failed to verify required signature '%s'\n",
-			       fit_get_name(sig_blob, noffset, NULL));
+			       fit_get_name(key_blob, noffset, NULL));
 			return ret;
 		}
 		verify_count++;
@@ -368,8 +368,35 @@ static int fit_config_check_sig(const void *fit, int noffset,
 	return 0;
 }
 
-static int fit_config_verify_sig(const void *fit, int conf_noffset,
-				 const void *sig_blob, int sig_offset)
+/**
+ * fit_config_verify_key() - Verify that a configuration is signed with a key
+ *
+ * Here we are looking at a particular configuration that needs verification:
+ *
+ *	configurations {
+ *		default = "conf-1";
+ *		conf-1 {
+ *			kernel = "kernel-1";
+ *			fdt = "fdt-1";
+ *			signature-1 {
+ *				algo = "sha1,rsa2048";
+ *				value = <...conf 1 signature...>;
+ *			};
+ *		};
+ *
+ * We must check each of the signature subnodes of conf-1. Hopefully one of them
+ * will match the key at key_offset.
+ *
+ * @fit: FIT to check
+ * @conf_noffset: Offset of the configuration node to check (e.g.
+ *	/configurations/conf-1)
+ * @key_blob: Blob containing the keys to check against
+ * @key_offset: Offset of the key to check within @key_blob
+ * @return 0 if OK, -EPERM if any signatures did not verify, or the
+ *	configuration node has an invalid name
+ */
+static int fit_config_verify_key(const void *fit, int conf_noffset,
+				 const void *key_blob, int key_offset)
 {
 	int noffset;
 	char *err_msg = "No 'signature' subnode found";
@@ -382,7 +409,7 @@ static int fit_config_verify_sig(const void *fit, int conf_noffset,
 
 		if (!strncmp(name, FIT_SIG_NODENAME,
 			     strlen(FIT_SIG_NODENAME))) {
-			ret = fit_config_check_sig(fit, noffset, sig_offset,
+			ret = fit_config_check_sig(fit, noffset, key_offset,
 						   conf_noffset, &err_msg);
 			if (ret) {
 				puts("- ");
@@ -409,12 +436,25 @@ error:
 	return -EPERM;
 }
 
-static int fit_config_verify_required_sigs(const void *fit, int conf_noffset,
-					   const void *sig_blob)
+/**
+ * fit_config_verify_required_keys() - verify any required signatures for config
+ *
+ * This looks through all the signatures we expect and verifies that at least
+ * all the required ones are valid signatures for the configuration
+ *
+ * @fit: FIT to check
+ * @conf_noffset: Offset of the configuration node to check (e.g.
+ *	/configurations/conf-1)
+ * @key_blob: Blob containing the keys to check against
+ * @return 0 if OK, -EPERM if any signatures did not verify, or the
+ *	configuration node has an invalid name
+ */
+static int fit_config_verify_required_keys(const void *fit, int conf_noffset,
+					   const void *key_blob)
 {
 	const char *name = fit_get_name(fit, conf_noffset, NULL);
 	int noffset;
-	int sig_node;
+	int key_node;
 	int verified = 0;
 	int reqd_sigs = 0;
 	bool reqd_policy_all = true;
@@ -430,38 +470,45 @@ static int fit_config_verify_required_sigs(const void *fit, int conf_noffset,
 	}
 
 	/* Work out what we need to verify */
-	sig_node = fdt_subnode_offset(sig_blob, 0, FIT_SIG_NODENAME);
-	if (sig_node < 0) {
+	key_node = fdt_subnode_offset(key_blob, 0, FIT_SIG_NODENAME);
+	if (key_node < 0) {
 		debug("%s: No signature node found: %s\n", __func__,
-		      fdt_strerror(sig_node));
+		      fdt_strerror(key_node));
 		return 0;
 	}
 
 	/* Get required-mode policy property from DTB */
-	reqd_mode = fdt_getprop(sig_blob, sig_node, "required-mode", NULL);
+	reqd_mode = fdt_getprop(key_blob, key_node, "required-mode", NULL);
 	if (reqd_mode && !strcmp(reqd_mode, "any"))
 		reqd_policy_all = false;
 
 	debug("%s: required-mode policy set to '%s'\n", __func__,
 	      reqd_policy_all ? "all" : "any");
 
-	fdt_for_each_subnode(noffset, sig_blob, sig_node) {
+	/*
+	 * The algorithm here is a little convoluted due to how we want it to
+	 * work. Here we work through each of the signature nodes in the
+	 * public-key area. These are in the U-Boot control devicetree. Each
+	 * node was created by signing a configuration, so we check if it is
+	 * 'required' and if so, request that it be verified.
+	 */
+	fdt_for_each_subnode(noffset, key_blob, key_node) {
 		const char *required;
 		int ret;
 
-		required = fdt_getprop(sig_blob, noffset, FIT_KEY_REQUIRED,
+		required = fdt_getprop(key_blob, noffset, FIT_KEY_REQUIRED,
 				       NULL);
 		if (!required || strcmp(required, "conf"))
 			continue;
 
 		reqd_sigs++;
 
-		ret = fit_config_verify_sig(fit, conf_noffset, sig_blob,
+		ret = fit_config_verify_key(fit, conf_noffset, key_blob,
 					    noffset);
 		if (ret) {
 			if (reqd_policy_all) {
 				printf("Failed to verify required signature '%s'\n",
-				       fit_get_name(sig_blob, noffset, NULL));
+				       fit_get_name(key_blob, noffset, NULL));
 				return ret;
 			}
 		} else {
@@ -481,6 +528,6 @@ static int fit_config_verify_required_sigs(const void *fit, int conf_noffset,
 
 int fit_config_verify(const void *fit, int conf_noffset)
 {
-	return fit_config_verify_required_sigs(fit, conf_noffset,
+	return fit_config_verify_required_keys(fit, conf_noffset,
 					       gd_fdt_blob());
 }
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#14 lore raw

Re: [PATCH 07/16] tools: Avoid confusion between keys and signatures

We should be consistent in using the term 'signature' to describe a value added to sign something and 'key' to describe the key that can be used to verify the signature.

Tidy up the code to stick to this.

Add some comments to fit_config_verify_key() and its callers while we are here.

---

 boot/image-fit-sig.c | 97 ++++++++++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 25 deletions(-)

Applied to u-boot-dm, thanks!

#15 lore raw

PATCH 8/16 tools: Tidy up argument order in fit_config_check_sig()

In reply to Simon Glass

Put the parent node first in the parameters as this is more natural. Also add a comment to explain what is going on.

---

 boot/image-fit-sig.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)
boot/image-fit-sig.c +22 -9
index f0ccd9b5227..253748ef649 100644
@@ -226,21 +226,34 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
 /**
  * fit_config_check_sig() - Check the signature of a config
  *
+ * Here we are looking at a particular signature that needs verification (here
+ * signature-1):
+ *
+ *	configurations {
+ *		default = "conf-1";
+ *		conf-1 {
+ *			kernel = "kernel-1";
+ *			fdt = "fdt-1";
+ *			signature-1 {
+ *				algo = "sha1,rsa2048";
+ *				value = <...conf 1 signature...>;
+ *			};
+ *		};
+ *
  * @fit: FIT to check
- * @noffset: Offset of configuration node (e.g. /configurations/conf-1)
- * @required_keynode:	Offset in the control FDT of the required key node,
+ * @noffset: Offset of the signature node being checked (e.g.
+ *	 /configurations/conf-1/signature-1)
+ * @conf_noffset: Offset of configuration node (e.g. /configurations/conf-1)
+ * @required_keynode:	Offset in @key_blob of the required key node,
  *			if any. If this is given, then the configuration wil not
  *			pass verification unless that key is used. If this is
  *			-1 then any signature will do.
- * @conf_noffset: Offset of the configuration subnode being checked (e.g.
- *	 /configurations/conf-1/kernel)
  * @err_msgp:		In the event of an error, this will be pointed to a
  *			help error string to display to the user.
  * @return 0 if all verified ok, <0 on error
  */
-static int fit_config_check_sig(const void *fit, int noffset,
-				int required_keynode, int conf_noffset,
-				char **err_msgp)
+static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,
+				int required_keynode, char **err_msgp)
 {
 	static char * const exc_prop[] = {
 		"data",
@@ -409,8 +422,8 @@ static int fit_config_verify_key(const void *fit, int conf_noffset,
 
 		if (!strncmp(name, FIT_SIG_NODENAME,
 			     strlen(FIT_SIG_NODENAME))) {
-			ret = fit_config_check_sig(fit, noffset, key_offset,
-						   conf_noffset, &err_msg);
+			ret = fit_config_check_sig(fit, noffset, conf_noffset,
+						   key_offset, &err_msg);
 			if (ret) {
 				puts("- ");
 			} else {
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#16 lore raw

Re: [PATCH 08/16] tools: Tidy up argument order in fit_config_check_sig()

Put the parent node first in the parameters as this is more natural. Also add a comment to explain what is going on.

---

 boot/image-fit-sig.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

Applied to u-boot-dm, thanks!

#17 lore raw

PATCH 9/16 tools: Pass the key blob around

In reply to Simon Glass

At present we rely on the key blob being in the global_data fdt_blob pointer. This is true in U-Boot but not with tools. For clarity, pass the parameter around.

---

 boot/image-fit-sig.c | 31 ++++++++++++++++++-------------
 boot/image-fit.c     | 12 +++++++-----
 common/spl/spl_fit.c |  3 ++-
 include/image.h      | 23 ++++++++++++++++++-----
 4 files changed, 45 insertions(+), 24 deletions(-)
boot/image-fit-sig.c +18 -13
index 253748ef649..a751c12d174 100644
@@ -65,7 +65,8 @@ struct image_region *fit_region_make_list(const void *fit,
 
 static int fit_image_setup_verify(struct image_sign_info *info,
 				  const void *fit, int noffset,
-				  int required_keynode, char **err_msgp)
+				  const void *key_blob, int required_keynode,
+				  char **err_msgp)
 {
 	char *algo_name;
 	const char *padding_name;
@@ -91,7 +92,7 @@ static int fit_image_setup_verify(struct image_sign_info *info,
 	info->checksum = image_get_checksum_algo(algo_name);
 	info->crypto = image_get_crypto_algo(algo_name);
 	info->padding = image_get_padding_algo(padding_name);
-	info->fdt_blob = gd_fdt_blob();
+	info->fdt_blob = key_blob;
 	info->required_keynode = required_keynode;
 	printf("%s:%s", algo_name, info->keyname);
 
@@ -104,7 +105,8 @@ static int fit_image_setup_verify(struct image_sign_info *info,
 }
 
 int fit_image_check_sig(const void *fit, int noffset, const void *data,
-			size_t size, int required_keynode, char **err_msgp)
+			size_t size, const void *key_blob, int required_keynode,
+			char **err_msgp)
 {
 	struct image_sign_info info;
 	struct image_region region;
@@ -112,8 +114,8 @@ int fit_image_check_sig(const void *fit, int noffset, const void *data,
 	int fit_value_len;
 
 	*err_msgp = NULL;
-	if (fit_image_setup_verify(&info, fit, noffset, required_keynode,
-				   err_msgp))
+	if (fit_image_setup_verify(&info, fit, noffset, key_blob,
+				   required_keynode, err_msgp))
 		return -1;
 
 	if (fit_image_hash_get_value(fit, noffset, &fit_value,
@@ -156,8 +158,8 @@ static int fit_image_verify_sig(const void *fit, int image_noffset,
 		}
 		if (!strncmp(name, FIT_SIG_NODENAME,
 			     strlen(FIT_SIG_NODENAME))) {
-			ret = fit_image_check_sig(fit, noffset, data,
-						  size, -1, &err_msg);
+			ret = fit_image_check_sig(fit, noffset, data, size,
+						  key_blob, -1, &err_msg);
 			if (ret) {
 				puts("- ");
 			} else {
@@ -244,6 +246,7 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  * @noffset: Offset of the signature node being checked (e.g.
  *	 /configurations/conf-1/signature-1)
  * @conf_noffset: Offset of configuration node (e.g. /configurations/conf-1)
+ * @key_blob: Blob containing the keys to check against
  * @required_keynode:	Offset in @key_blob of the required key node,
  *			if any. If this is given, then the configuration wil not
  *			pass verification unless that key is used. If this is
@@ -253,7 +256,8 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  * @return 0 if all verified ok, <0 on error
  */
 static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,
-				int required_keynode, char **err_msgp)
+				const void *key_blob, int required_keynode,
+				char **err_msgp)
 {
 	static char * const exc_prop[] = {
 		"data",
@@ -275,12 +279,12 @@ static int fit_config_check_sig(const void *fit, int noffset, int conf_noffset,
 	int count;
 
 	config_name = fit_get_name(fit, conf_noffset, NULL);
-	debug("%s: fdt=%p, conf='%s', sig='%s'\n", __func__, gd_fdt_blob(),
+	debug("%s: fdt=%p, conf='%s', sig='%s'\n", __func__, key_blob,
 	      fit_get_name(fit, noffset, NULL),
-	      fit_get_name(gd_fdt_blob(), required_keynode, NULL));
+	      fit_get_name(key_blob, required_keynode, NULL));
 	*err_msgp = NULL;
-	if (fit_image_setup_verify(&info, fit, noffset, required_keynode,
-				   err_msgp))
+	if (fit_image_setup_verify(&info, fit, noffset, key_blob,
+				   required_keynode, err_msgp))
 		return -1;
 
 	if (fit_image_hash_get_value(fit, noffset, &fit_value,
@@ -423,7 +427,8 @@ static int fit_config_verify_key(const void *fit, int conf_noffset,
 		if (!strncmp(name, FIT_SIG_NODENAME,
 			     strlen(FIT_SIG_NODENAME))) {
 			ret = fit_config_check_sig(fit, noffset, conf_noffset,
-						   key_offset, &err_msg);
+						   key_blob, key_offset,
+						   &err_msg);
 			if (ret) {
 				puts("- ");
 			} else {
boot/image-fit.c +7 -5
index 33b4a46028b..59191a5486c 100644
@@ -1309,7 +1309,8 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data,
 }
 
 int fit_image_verify_with_data(const void *fit, int image_noffset,
-			       const void *data, size_t size)
+			       const void *key_blob, const void *data,
+			       size_t size)
 {
 	int		noffset = 0;
 	char		*err_msg = "";
@@ -1319,7 +1320,7 @@ int fit_image_verify_with_data(const void *fit, int image_noffset,
 	/* Verify all required signatures */
 	if (FIT_IMAGE_ENABLE_VERIFY &&
 	    fit_image_verify_required_sigs(fit, image_noffset, data, size,
-					   gd_fdt_blob(), &verify_all)) {
+					   key_blob, &verify_all)) {
 		err_msg = "Unable to verify required signature";
 		goto error;
 	}
@@ -1342,8 +1343,8 @@ int fit_image_verify_with_data(const void *fit, int image_noffset,
 		} else if (FIT_IMAGE_ENABLE_VERIFY && verify_all &&
 				!strncmp(name, FIT_SIG_NODENAME,
 					strlen(FIT_SIG_NODENAME))) {
-			ret = fit_image_check_sig(fit, noffset, data,
-							size, -1, &err_msg);
+			ret = fit_image_check_sig(fit, noffset, data, size,
+						  gd_fdt_blob(), -1, &err_msg);
 
 			/*
 			 * Show an indication on failure, but do not return
@@ -1406,7 +1407,8 @@ int fit_image_verify(const void *fit, int image_noffset)
 		goto err;
 	}
 
-	return fit_image_verify_with_data(fit, image_noffset, data, size);
+	return fit_image_verify_with_data(fit, image_noffset, gd_fdt_blob(),
+					  data, size);
 
 err:
 	printf("error!\n%s in '%s' image node\n", err_msg,
common/spl/spl_fit.c +2 -1
index 5fe0273d66d..55133ceea6f 100644
@@ -314,7 +314,8 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 	if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) {
 		printf("## Checking hash(es) for Image %s ... ",
 		       fit_get_name(fit, node, NULL));
-		if (!fit_image_verify_with_data(fit, node, src, length))
+		if (!fit_image_verify_with_data(fit, node, gd_fdt_blob(), src,
+						length))
 			return -EPERM;
 		puts("OK\n");
 	}
include/image.h +18 -5
index 533c23e2002..d5598cec461 100644
@@ -1047,8 +1047,19 @@ int fit_add_verification_data(const char *keydir, const char *keyfile,
 			      int require_keys, const char *engine_id,
 			      const char *cmdname);
 
+/**
+ * fit_image_verify_with_data() - Verify an image with given data
+ *
+ * @fit:	Pointer to the FIT format image header
+ * @image_offset: Offset in @fit of image to verify
+ * @key_blob:	FDT containing public keys
+ * @data:	Image data to verify
+ * @size:	Size of image data
+ */
 int fit_image_verify_with_data(const void *fit, int image_noffset,
-			       const void *data, size_t size);
+			       const void *key_blob, const void *data,
+			       size_t size);
+
 int fit_image_verify(const void *fit, int noffset);
 int fit_config_verify(const void *fit, int conf_noffset);
 int fit_all_image_verify(const void *fit);
@@ -1296,7 +1307,7 @@ struct padding_algo *image_get_padding_algo(const char *name);
  * @image_noffset:	Offset of image node to check
  * @data:		Image data to check
  * @size:		Size of image data
- * @sig_blob:		FDT containing public keys
+ * @key_blob:		FDT containing public keys
  * @no_sigsp:		Returns 1 if no signatures were required, and
  *			therefore nothing was checked. The caller may wish
  *			to fall back to other mechanisms, or refuse to
@@ -1304,7 +1315,7 @@ struct padding_algo *image_get_padding_algo(const char *name);
  * @return 0 if all verified ok, <0 on error
  */
 int fit_image_verify_required_sigs(const void *fit, int image_noffset,
-		const char *data, size_t size, const void *sig_blob,
+		const char *data, size_t size, const void *key_blob,
 		int *no_sigsp);
 
 /**
@@ -1314,7 +1325,8 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  * @noffset:		Offset of signature node to check
  * @data:		Image data to check
  * @size:		Size of image data
- * @required_keynode:	Offset in the control FDT of the required key node,
+ * @keyblob:		Key blob to check (typically the control FDT)
+ * @required_keynode:	Offset in the keyblob of the required key node,
  *			if any. If this is given, then the image wil not
  *			pass verification unless that key is used. If this is
  *			-1 then any signature will do.
@@ -1323,7 +1335,8 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  * @return 0 if all verified ok, <0 on error
  */
 int fit_image_check_sig(const void *fit, int noffset, const void *data,
-		size_t size, int required_keynode, char **err_msgp);
+			size_t size, const void *key_blob, int required_keynode,
+			char **err_msgp);
 
 int fit_image_decrypt_data(const void *fit,
 			   int image_noffset, int cipher_noffset,
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#18 lore raw

Re: [PATCH 09/16] tools: Pass the key blob around

At present we rely on the key blob being in the global_data fdt_blob pointer. This is true in U-Boot but not with tools. For clarity, pass the parameter around.

---

 boot/image-fit-sig.c | 31 ++++++++++++++++++-------------
 boot/image-fit.c     | 12 +++++++-----
 common/spl/spl_fit.c |  3 ++-
 include/image.h      | 23 ++++++++++++++++++-----
 4 files changed, 45 insertions(+), 24 deletions(-)

Applied to u-boot-dm, thanks!

#19 lore raw

PATCH 10/16 image: Return destination node for add_verify_data() method

In reply to Simon Glass

It is useful to know where the verification data was written. Update the API to return this.

---

 include/image.h             | 3 ++-
 include/u-boot/ecdsa.h      | 5 +++--
 include/u-boot/rsa.h        | 5 +++--
 lib/ecdsa/ecdsa-libcrypto.c | 4 ++--
 lib/rsa/rsa-sign.c          | 5 ++++-
 tools/image-host.c          | 5 ++---
 6 files changed, 16 insertions(+), 11 deletions(-)
include/image.h +2 -1
index d5598cec461..0f5e037a192 100644
@@ -1242,7 +1242,8 @@ struct crypto_algo {
 	 *
 	 * @info:	Specifies key and FIT information
 	 * @keydest:	Destination FDT blob for public key data
-	 * @return: 0, on success, -ve on error
+	 * @return: node offset within the FDT blob where the data was written,
+	 *	or -ve on error
 	 */
 	int (*add_verify_data)(struct image_sign_info *info, void *keydest);
 
include/u-boot/ecdsa.h +3 -2
index f6951c7346d..f1fa176d916 100644
@@ -44,8 +44,9 @@ int ecdsa_sign(struct image_sign_info *info, const struct image_region region[],
  *
  * @info:	Specifies key and FIT information
  * @keydest:	Destination FDT blob for public key data
- * @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
- * other -ve value on error
+ * @return: node offset within the FDT blob where the data was written on
+ *	success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
+ *	value on other error
  */
 int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest);
 
include/u-boot/rsa.h +3 -2
index 7556aa5b4b7..fafefeedd80 100644
@@ -61,8 +61,9 @@ int rsa_sign(struct image_sign_info *info,
  *
  * @info:	Specifies key and FIT information
  * @keydest:	Destination FDT blob for public key data
- * @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
-		other -ve value on error
+ * @return: node offset within the FDT blob where the data was written on
+ *	success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
+ *	value on other error
 */
 int rsa_add_verify_data(struct image_sign_info *info, void *keydest);
 
lib/ecdsa/ecdsa-libcrypto.c +2 -2
index 1757a145623..aa9a226d031 100644
@@ -299,7 +299,7 @@ static int do_add(struct signer *ctx, void *fdt, const char *key_node_name)
 	if (ret < 0)
 		return ret;
 
-	return 0;
+	return key_node;
 }
 
 int ecdsa_add_verify_data(struct image_sign_info *info, void *fdt)
@@ -311,7 +311,7 @@ int ecdsa_add_verify_data(struct image_sign_info *info, void *fdt)
 	fdt_key_name = info->keyname ? info->keyname : "default-key";
 	ret = prepare_ctx(&ctx, info);
 	if (ret >= 0)
-		do_add(&ctx, fdt, fdt_key_name);
+		ret = do_add(&ctx, fdt, fdt_key_name);
 
 	free_ctx(&ctx);
 	return ret;
lib/rsa/rsa-sign.c +4 -1
index 0579e5294ee..e8b06c857f2 100644
@@ -701,5 +701,8 @@ err_get_pub_key:
 	if (info->engine_id)
 		rsa_engine_remove(e);
 
-	return ret;
+	if (ret)
+		return ret;
+
+	return node;
 }
tools/image-host.c +2 -3
index e4322d323a2..e53fe4bbbed 100644
@@ -264,7 +264,7 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile,
 	 */
 	if (keydest) {
 		ret = info.crypto->add_verify_data(&info, keydest);
-		if (ret) {
+		if (ret < 0) {
 			printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
 			       node_name, image_name);
 			return ret;
@@ -1030,11 +1030,10 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
 	/* Write the public key into the supplied FDT file */
 	if (keydest) {
 		ret = info.crypto->add_verify_data(&info, keydest);
-		if (ret) {
+		if (ret < 0) {
 			printf("Failed to add verification data for '%s' signature node in '%s' configuration node\n",
 			       node_name, conf_name);
 		}
-		return ret;
 	}
 
 	return 0;
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#20 lore raw

PATCH 11/16 tools: Pass public-key node through to caller

In reply to Simon Glass

Update the two functions that call add_verify_data() so that the caller can see the node that was written to.

---

 tools/image-host.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
tools/image-host.c +25 -3
index e53fe4bbbed..e2b120ce532 100644
@@ -209,7 +209,8 @@ static int fit_image_setup_sig(struct image_sign_info *info,
  * @comment:	Comment to add to signature nodes
  * @require_keys: Mark all keys as 'required'
  * @engine_id:	Engine to use for signing
- * @return 0 if ok, -1 on error
+ * @return keydest node if @keydest is non-NULL, else 0 if none; -ve error code
+ *	on failure
  */
 static int fit_image_process_sig(const char *keydir, const char *keyfile,
 		void *keydest, void *fit, const char *image_name,
@@ -269,6 +270,8 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile,
 			       node_name, image_name);
 			return ret;
 		}
+		/* Return the node that was written to */
+		return ret;
 	}
 
 	return 0;
@@ -645,7 +648,7 @@ int fit_image_add_verification_data(const char *keydir, const char *keyfile,
 				fit, image_name, noffset, data, size,
 				comment, require_keys, engine_id, cmdname);
 		}
-		if (ret)
+		if (ret < 0)
 			return ret;
 	}
 
@@ -974,6 +977,24 @@ static int fit_config_get_regions(const void *fit, int conf_noffset,
 	return 0;
 }
 
+/**
+ * fit_config_process_sig - Process a single subnode of the configurations/ node
+ *
+ * Generate a signed hash of the supplied data and store it in the node.
+ *
+ * @keydir:	Directory containing keys to use for signing
+ * @keydest:	Destination FDT blob to write public keys into (NULL if none)
+ * @fit:	pointer to the FIT format image header
+ * @conf_name	name of config being processed (used to display errors)
+ * @conf_noffset: Offset of configuration node, e.g. '/configurations/conf-1'
+ * @noffset:	subnode offset, e.g. '/configurations/conf-1/sig-1'
+ * @comment:	Comment to add to signature nodes
+ * @require_keys: Mark all keys as 'required'
+ * @engine_id:	Engine to use for signing
+ * @cmdname:	Command name used when reporting errors
+ * @return keydest node if @keydest is non-NULL, else 0 if none; -ve error code
+ *	on failure
+ */
 static int fit_config_process_sig(const char *keydir, const char *keyfile,
 		void *keydest, void *fit, const char *conf_name,
 		int conf_noffset, int noffset, const char *comment,
@@ -1034,6 +1055,7 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
 			printf("Failed to add verification data for '%s' signature node in '%s' configuration node\n",
 			       node_name, conf_name);
 		}
+		return ret;
 	}
 
 	return 0;
@@ -1063,7 +1085,7 @@ static int fit_config_add_verification_data(const char *keydir,
 				fit, conf_name, conf_noffset, noffset, comment,
 				require_keys, engine_id, cmdname);
 		}
-		if (ret)
+		if (ret < 0)
 			return ret;
 	}
 
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#21 lore raw

Re: [PATCH 11/16] tools: Pass public-key node through to caller

Update the two functions that call add_verify_data() so that the caller can see the node that was written to.

---

 tools/image-host.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!

#22 lore raw

PATCH 12/16 tools: mkimage: Show where signatures/keys are written

In reply to Simon Glass

At present mkimage displays the node information but it is not clear what signing action was taken. Add a message that shows it. For now it only supports showing a single signing action, since that is the common case.

Sample:

Signature written to 'sha1-basic/test.fit',
node '/configurations/conf-1/signature'
Public key written to 'sha1-basic/sandbox-u-boot.dtb',
node '/signature/key-dev'

---

 include/image.h    | 23 ++++++++++++++++++++++-
 tools/fit_common.c | 13 +++++++++++++
 tools/fit_common.h | 10 ++++++++++
 tools/fit_image.c  |  3 ++-
 tools/image-host.c | 23 ++++++++++++++++++-----
 tools/imagetool.h  |  3 +++
 tools/mkimage.c    |  4 ++++
 7 files changed, 72 insertions(+), 7 deletions(-)
include/image.h +22 -1
index 0f5e037a192..733fa016694 100644
@@ -1021,6 +1021,25 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
 		    const char *comment, int require_keys,
 		    const char *engine_id, const char *cmdname);
 
+#define NODE_MAX_NAME_LEN	80
+
+/**
+ * struct image_summary  - Provides information about signing info added
+ *
+ * @sig_offset: Offset of the node in the blob devicetree where the signature
+ *	was wriiten
+ * @sig_path: Path to @sig_offset
+ * @keydest_offset: Offset of the node in the keydest devicetree where the
+ *	public key was written (-1 if none)
+ * @keydest_path: Path to @keydest_offset
+ */
+struct image_summary {
+	int sig_offset;
+	char sig_path[NODE_MAX_NAME_LEN];
+	int keydest_offset;
+	char keydest_path[NODE_MAX_NAME_LEN];
+};
+
 /**
  * fit_add_verification_data() - add verification data to FIT image nodes
  *
@@ -1031,6 +1050,7 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
  * @require_keys: Mark all keys as 'required'
  * @engine_id:	Engine to use for signing
  * @cmdname:	Command name used when reporting errors
+ * @summary:	Returns information about what data was written
  *
  * Adds hash values for all component images in the FIT blob.
  * Hashes are calculated for all component images which have hash subnodes
@@ -1045,7 +1065,8 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
 int fit_add_verification_data(const char *keydir, const char *keyfile,
 			      void *keydest, void *fit, const char *comment,
 			      int require_keys, const char *engine_id,
-			      const char *cmdname);
+			      const char *cmdname,
+			      struct image_summary *summary);
 
 /**
  * fit_image_verify_with_data() - Verify an image with given data
tools/fit_common.c +13 -0
index d13e5ebf1ae..defdc9d5688 100644
@@ -167,3 +167,16 @@ int copyfile(const char *src, const char *dst)
 
 	return ret;
 }
+
+void summary_show(struct image_summary *summary, const char *imagefile,
+		  const char *keydest)
+{
+	if (summary->sig_offset) {
+		printf("Signature written to '%s', node '%s'\n", imagefile,
+		       summary->sig_path);
+		if (keydest) {
+			printf("Public key written to '%s', node '%s'\n",
+			       keydest, summary->keydest_path);
+		}
+	}
+}
tools/fit_common.h +10 -0
index 55f3f6acd4e..07fb718ae3a 100644
@@ -52,4 +52,14 @@ int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
  */
 int copyfile(const char *src, const char *dst);
 
+/**
+ * summary_show() - Show summary information about the signing process
+ *
+ * @summary: Summary info to show
+ * @imagefile: Filename of the output image
+ * @keydest: Filename where the key information is written (NULL if none)
+ */
+void summary_show(struct image_summary *summary, const char *imagefile,
+		  const char *keydest);
+
 #endif /* _FIT_COMMON_H_ */
tools/fit_image.c +2 -1
index c4f56bb6967..aff27d0ffcb 100644
@@ -73,7 +73,8 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
 						params->comment,
 						params->require_keys,
 						params->engine_id,
-						params->cmdname);
+						params->cmdname,
+						&params->summary);
 	}
 
 	if (dest_blob) {
tools/image-host.c +18 -5
index e2b120ce532..fb9aa7493cc 100644
@@ -1064,7 +1064,7 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
 static int fit_config_add_verification_data(const char *keydir,
 		const char *keyfile, void *keydest, void *fit, int conf_noffset,
 		const char *comment, int require_keys, const char *engine_id,
-		const char *cmdname)
+		const char *cmdname, struct image_summary *summary)
 {
 	const char *conf_name;
 	int noffset;
@@ -1084,9 +1084,20 @@ static int fit_config_add_verification_data(const char *keydir,
 			ret = fit_config_process_sig(keydir, keyfile, keydest,
 				fit, conf_name, conf_noffset, noffset, comment,
 				require_keys, engine_id, cmdname);
+			if (ret < 0)
+				return ret;
+
+			summary->sig_offset = noffset;
+			fdt_get_path(fit, noffset, summary->sig_path,
+				     sizeof(summary->sig_path));
+
+			if (keydest) {
+				summary->keydest_offset = ret;
+				fdt_get_path(keydest, ret,
+					     summary->keydest_path,
+					     sizeof(summary->keydest_path));
+			}
 		}
-		if (ret < 0)
-			return ret;
 	}
 
 	return 0;
@@ -1130,7 +1141,8 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
 int fit_add_verification_data(const char *keydir, const char *keyfile,
 			      void *keydest, void *fit, const char *comment,
 			      int require_keys, const char *engine_id,
-			      const char *cmdname)
+			      const char *cmdname,
+			      struct image_summary *summary)
 {
 	int images_noffset, confs_noffset;
 	int noffset;
@@ -1178,7 +1190,8 @@ int fit_add_verification_data(const char *keydir, const char *keyfile,
 		ret = fit_config_add_verification_data(keydir, keyfile, keydest,
 						       fit, noffset, comment,
 						       require_keys,
-						       engine_id, cmdname);
+						       engine_id, cmdname,
+						       summary);
 		if (ret)
 			return ret;
 	}
tools/imagetool.h +3 -0
index e229a34ffc5..c0579c8c93c 100644
@@ -21,6 +21,8 @@
 #include <unistd.h>
 #include <u-boot/sha1.h>
 
+#include <image.h>
+
 #include "fdt_host.h"
 
 #define ARRAY_SIZE(x)		(sizeof(x) / sizeof((x)[0]))
@@ -83,6 +85,7 @@ struct image_tool_params {
 	int bl_len;		/* Block length in byte for external data */
 	const char *engine_id;	/* Engine to use for signing */
 	bool reset_timestamp;	/* Reset the timestamp on an existing image */
+	struct image_summary summary;	/* results of signing process */
 };
 
 /*
tools/mkimage.c +4 -0
index fbe883ce362..566607c489e 100644
@@ -10,6 +10,7 @@
 #include "imagetool.h"
 #include "mkimage.h"
 #include "imximage.h"
+#include <fit_common.h>
 #include <image.h>
 #include <version.h>
 #ifdef __linux__
@@ -469,6 +470,9 @@ int main(int argc, char **argv)
 
 		(void) munmap((void *)ptr, sbuf.st_size);
 		(void) close (ifd);
+		if (!retval)
+			summary_show(&params.summary, params.imagefile,
+				     params.keydest);
 
 		exit (retval);
 	}
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#23 lore raw

Re: [PATCH 12/16] tools: mkimage: Show where signatures/keys are written

At present mkimage displays the node information but it is not clear what signing action was taken. Add a message that shows it. For now it only supports showing a single signing action, since that is the common case.

Sample:

Signature written to 'sha1-basic/test.fit',
node '/configurations/conf-1/signature'
Public key written to 'sha1-basic/sandbox-u-boot.dtb',
node '/signature/key-dev'

---

 include/image.h    | 23 ++++++++++++++++++++++-
 tools/fit_common.c | 13 +++++++++++++
 tools/fit_common.h | 10 ++++++++++
 tools/fit_image.c  |  3 ++-
 tools/image-host.c | 23 ++++++++++++++++++-----
 tools/imagetool.h  |  3 +++
 tools/mkimage.c    |  4 ++++
 7 files changed, 72 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

#24 lore raw

PATCH 13/16 tools: Add a new tool to sign FDT blobs

In reply to Simon Glass

This works similarly to FIT signing except that it signs the entire FDT (with a few exclusions), rather than just FIT configurations or images.

Also it is a stand-alone tool rather than being part of mkimage.

The signature is added to the FDT so it can be checked later, to ensure that no modifications were made to the FDT.

The /chosen node is excluded, since U-Boot may want to update it.

---

 include/image.h   |  29 ++++
 tools/Makefile    |   8 +-
 tools/fdt-host.c  | 333 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/fdt_host.h  |  19 +++
 tools/fdt_sign.c  | 210 +++++++++++++++++++++++++++++
 tools/imagetool.h |   1 +
 6 files changed, 598 insertions(+), 2 deletions(-)
 create mode 100644 tools/fdt-host.c
 create mode 100644 tools/fdt_sign.c
include/image.h +29 -0
index 733fa016694..b2767883636 100644
@@ -1154,6 +1154,35 @@ int fit_check_ramdisk(const void *fit, int os_noffset,
 int calculate_hash(const void *data, int data_len, const char *algo,
 			uint8_t *value, int *value_len);
 
+/**
+ * fdt_add_verif_data() - add verification data to an FDT blob
+ *
+ * @keydir:	Directory containing keys
+ * @keyfile:	Filename containing .key file
+ * @kwydest:	FDT blob to write public key information to (NULL if none)
+ * @fit:	Pointer to the FIT format image header
+ * @key_name:	Name of key used to sign (used for node name and .crt file)
+ * @comment:	Comment to add to signature nodes
+ * @require_keys: Mark all keys as 'required'
+ * @engine_id:	Engine to use for signing
+ * @cmdname:	Command name used when reporting errors
+ * @summary:	Returns information about what data was written
+ *
+ * Adds hash values for all component images in the FIT blob.
+ * Hashes are calculated for all component images which have hash subnodes
+ * with algorithm property set to one of the supported hash algorithms.
+ *
+ * Also add signatures if signature nodes are present.
+ *
+ * returns
+ *     0, on success
+ *     libfdt error code, on failure
+ */
+int fdt_add_verif_data(const char *keydir, const char *keyfile, void *keydest,
+		       void *blob, const char *key_name, const char *comment,
+		       bool require_keys, const char *engine_id,
+		       const char *cmdname, struct image_summary *summary);
+
 /*
  * At present we only support signing on the host, and verification on the
  * device
tools/Makefile +6 -2
index 1763f44cac4..07eca631cb0 100644
@@ -72,12 +72,14 @@ hostprogs-y += mkenvimage
 mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
 
 hostprogs-y += dumpimage mkimage
-hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign
+hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign \
+	fdt_sign
 
 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
 
 FIT_OBJS-y := fit_common.o fit_image.o image-host.o boot/image-fit.o
-FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o boot/image-fit-sig.o
+FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o \
+	boot/image-fit-sig.o fdt-host.o
 FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := boot/image-cipher.o
 
 # The following files are synced with upstream DTC.
@@ -154,6 +156,7 @@ dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
 mkimage-objs   := $(dumpimage-mkimage-objs) mkimage.o
 fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
 fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
+fdt_sign-objs   := $(dumpimage-mkimage-objs) fdt_sign.o
 file2include-objs := file2include.o
 
 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
@@ -191,6 +194,7 @@ HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
 HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
+HOSTLDLIBS_fdt_sign := $(HOSTLDLIBS_mkimage)
 
 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
tools/fdt-host.c new file +333 -0

333 lines not on this page · raw message

tools/fdt_host.h +19 -0
index bc42306c9e5..877f098676b 100644
@@ -10,6 +10,8 @@
 #include "../include/linux/libfdt.h"
 #include "../include/fdt_support.h"
 
+struct image_region;
+
 /**
  * fdt_remove_unused_strings() - Remove any unused strings from an FDT
  *
@@ -38,4 +40,21 @@ int fdt_remove_unused_strings(const void *old, void *new);
 int fit_check_sign(const void *fit, const void *key,
 		   const char *fit_uname_config);
 
+/**
+ * fdt_get_regions() - Get the regions to sign
+ *
+ * This calculates a list of node to hash for this particular configuration,
+ * then finds which regions of the devicetree they correspond to.
+ *
+ * @blob:	Pointer to the FDT blob to sign
+ * @strtab_len:	Length in bytes of the string table to sign, -1 to sign it all
+ * @regionp: Returns list of regions that need to be hashed (allocated; must be
+ *	freed by the caller)
+ * @region_count: Returns number of regions
+ * @return 0 if OK, -ENOMEM if out of memory, -EIO if the regions to hash could
+ * not be found, -EINVAL if no registers were found to hash
+ */
+int fdt_get_regions(const void *blob, int strtab_len,
+		    struct image_region **regionp, int *region_countp);
+
 #endif /* __FDT_HOST_H__ */
tools/fdt_sign.c new file +210 -0

210 lines not on this page · raw message

tools/imagetool.h +1 -0
index c0579c8c93c..4f9626fd1e0 100644
@@ -70,6 +70,7 @@ struct image_tool_params {
 	const char *keydir;	/* Directory holding private keys */
 	const char *keydest;	/* Destination .dtb for public key */
 	const char *keyfile;	/* Filename of private or public key */
+	const char *keyname;	/* Name to use for key node if added */
 	const char *comment;	/* Comment to add to signature node */
 	int require_keys;	/* 1 to mark signing keys as 'required' */
 	int file_size;		/* Total size of output file */
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#25 lore raw

PATCH 14/16 tools: Add a new tool to check FDT-blob signatures

In reply to Simon Glass

Add a stand-alone (from mkimage) tool that checks signatures in an FDT blob.

---

 tools/Makefile         |   6 +-
 tools/fdt-host.c       |  20 ++++
 tools/fdt_check_sign.c |  85 ++++++++++++++
 tools/fdt_host.h       |  19 +++
 tools/image-fdt-sig.c  | 254 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 382 insertions(+), 2 deletions(-)
 create mode 100644 tools/fdt_check_sign.c
 create mode 100644 tools/image-fdt-sig.c
tools/Makefile +4 -2
index 07eca631cb0..b7857d86fac 100644
@@ -73,13 +73,13 @@ mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
 
 hostprogs-y += dumpimage mkimage
 hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign \
-	fdt_sign
+	fdt_sign fdt_check_sign
 
 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
 
 FIT_OBJS-y := fit_common.o fit_image.o image-host.o boot/image-fit.o
 FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o \
-	boot/image-fit-sig.o fdt-host.o
+	boot/image-fit-sig.o fdt-host.o image-fdt-sig.o
 FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := boot/image-cipher.o
 
 # The following files are synced with upstream DTC.
@@ -157,6 +157,7 @@ mkimage-objs   := $(dumpimage-mkimage-objs) mkimage.o
 fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
 fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
 fdt_sign-objs   := $(dumpimage-mkimage-objs) fdt_sign.o
+fdt_check_sign-objs   := $(dumpimage-mkimage-objs) fdt_check_sign.o
 file2include-objs := file2include.o
 
 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
@@ -195,6 +196,7 @@ HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
 HOSTLDLIBS_fdt_sign := $(HOSTLDLIBS_mkimage)
+HOSTLDLIBS_fdt_check_sign := $(HOSTLDLIBS_mkimage)
 
 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
tools/fdt-host.c +20 -0
index 8aa0e099f2f..142d486091b 100644
@@ -331,3 +331,23 @@ int fdt_add_verif_data(const char *keydir, const char *keyfile, void *keydest,
 
 	return ret;
 }
+
+#ifdef CONFIG_FIT_SIGNATURE
+int fdt_check_sign(const void *blob, const void *key)
+{
+	int fdt_sigs;
+	int ret;
+
+	fdt_sigs = fdt_subnode_offset(blob, 0, FIT_SIG_NODENAME);
+	if (fdt_sigs < 0) {
+		printf("No %s node found (err=%d)\n", FIT_SIG_NODENAME,
+		       fdt_sigs);
+		return fdt_sigs;
+	}
+
+	ret = fdt_sig_verify(blob, fdt_sigs, key);
+	fprintf(stderr, "Verify %s\n", ret ? "failed" : "OK");
+
+	return ret;
+}
+#endif
tools/fdt_check_sign.c new file +85 -0

85 lines not on this page · raw message

tools/fdt_host.h +19 -0
index 877f098676b..b653efcb5d3 100644
@@ -57,4 +57,23 @@ int fit_check_sign(const void *fit, const void *key,
 int fdt_get_regions(const void *blob, int strtab_len,
 		    struct image_region **regionp, int *region_countp);
 
+/**
+ * fdt_check_sign() - Check signatures in an FDT blob
+ *
+ * @fdt: FDT blob to check
+ * @key: Key FDT blob to check against
+ * @return 0 if OK, -ve if any required signature failed
+ */
+int fdt_check_sign(const void *blob, const void *key);
+
+/**
+ * fdt_sig_verify() - Check signatures in an FDT blob
+ *
+ * @fdt: FDT blob to check
+ * @fit_sigs: Offset of /signatures node in the FDT
+ * @key: Key FDT blob to check against
+ * @return 0 if OK, -ve if any required signature failed
+ */
+int fdt_sig_verify(const void *blob, int fdt_sigs, const void *key);
+
 #endif /* __FDT_HOST_H__ */
tools/image-fdt-sig.c new file +254 -0

254 lines not on this page · raw message

Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#26 lore raw

PATCH 15/16 test: Add a test for FDT signing

In reply to Simon Glass

Add a test which checks that signing and checking work, including signing an FDT twice.

---

 test/py/tests/test_fdt_sign.py   | 83 ++++++++++++++++++++++++++++++++
 test/py/tests/test_vboot.py      | 21 ++------
 test/py/tests/vboot/sign-fdt.dts | 23 +++++++++
 test/py/tests/vboot_comm.py      | 22 +++++++++
 4 files changed, 131 insertions(+), 18 deletions(-)
 create mode 100644 test/py/tests/test_fdt_sign.py
 create mode 100644 test/py/tests/vboot/sign-fdt.dts
 create mode 100644 test/py/tests/vboot_comm.py
test/py/tests/test_fdt_sign.py new file +83 -0
new file mode 100644
index 00000000000..72d58211159
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2021 Google LLC
+#
+# U-Boot FDT-signing test
+
+import os
+
+import u_boot_utils as util
+import vboot_comm
+
+def test_fdt_sign(u_boot_console):
+    def dtc(dts):
+        """Run the device tree compiler to compile a .dts file
+
+        The output file will be the same as the input file but with a .dtb
+        extension.
+
+        Args:
+            dts: Device tree file to compile.
+        """
+        dtb = dts.replace('.dts', '.dtb')
+        util.run_and_log(cons, 'dtc %s %s%s -O dtb -p 0x1000 '
+                         '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
+
+    cons = u_boot_console
+    datadir = os.path.join(cons.config.source_dir, 'test/py/tests/vboot/')
+    fdt_sign = os.path.join(cons.config.build_dir, 'tools/fdt_sign')
+    fdt_check_sign = os.path.join(cons.config.build_dir, 'tools/fdt_check_sign')
+
+    tmpdir = os.path.join(cons.config.result_dir, 'fdt_sign') + '/'
+    if not os.path.exists(tmpdir):
+        os.mkdir(tmpdir)
+
+    dtb = '%ssandbox-u-boot.dtb' % tmpdir
+    dtc_args = '-I dts -O dtb -i %s' % tmpdir
+    dtc('sign-fdt.dts')
+    dtc('sandbox-u-boot.dts')
+
+    vboot_comm.create_rsa_pair(cons, tmpdir, 'dev')
+
+    # Sign and check that it verifies
+    signed = os.path.join(tmpdir, 'sign-fdt.dtb')
+    cmd = [fdt_sign, '-f', signed, '-G', os.path.join(tmpdir, 'dev.key'),
+           '-K', dtb, '-k', tmpdir, '-r']
+    util.run_and_log(cons, ' '.join(cmd))
+
+    cmd = [fdt_check_sign, '-f', signed, '-k', dtb]
+    util.run_and_log(cons, ' '.join(cmd))
+
+    # Update the chosen node, which dpes not affect things since the signature
+    # omits that node
+    util.run_and_log(cons, 'fdtput -t bx %s /chosen fred 1' % signed)
+
+    cmd = [fdt_check_sign, '-f', signed, '-k', dtb]
+    util.run_and_log(cons, ' '.join(cmd))
+
+    # Update the alias node, which should break things because that is included
+    # in the signature
+    util.run_and_log(cons, 'fdtput -t bx %s /aliases fred 1' % signed)
+
+    cmd = [fdt_check_sign, '-f', signed, '-k', dtb]
+    util.run_and_log_expect_exception(cons, cmd, 1, 'Verification failed')
+
+    # Regenerate the original devictree and sign it
+    dtc('sign-fdt.dts')
+    dtc('sandbox-u-boot.dts')
+    out = os.path.join(tmpdir, 'out-fdt.dtb')
+    cmd = [fdt_sign, '-f', signed, '-G', os.path.join(tmpdir, 'dev.key'),
+           '-K', dtb, '-k', tmpdir, '-r', '-o', out]
+    util.run_and_log(cons, ' '.join(cmd))
+
+    cmd = [fdt_check_sign, '-f', out, '-k', dtb]
+    util.run_and_log(cons, ' '.join(cmd))
+
+    # Create a new key and sign with that too
+    vboot_comm.create_rsa_pair(cons, tmpdir, 'prod')
+    cmd = [fdt_sign, '-f', out, '-G', os.path.join(tmpdir, 'prod.key'),
+           '-K', dtb, '-k', tmpdir, '-r']
+    util.run_and_log(cons, ' '.join(cmd))
+
+    # Now check that both signatures are valid
+    cmd = [fdt_check_sign, '-f', out, '-k', dtb]
+    util.run_and_log(cons, ' '.join(cmd))
test/py/tests/test_vboot.py +3 -18
index 095e00cce36..8458210691d 100644
@@ -29,6 +29,7 @@ import shutil
 import struct
 import pytest
 import u_boot_utils as util
+import vboot_comm
 import vboot_forge
 import vboot_evil
 
@@ -173,22 +174,6 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
             handle.write(struct.pack(">I", size))
         return struct.unpack(">I", total_size)[0]
 
-    def create_rsa_pair(name):
-        """Generate a new RSA key paid and certificate
-
-        Args:
-            name: Name of of the key (e.g. 'dev')
-        """
-        public_exponent = 65537
-        util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %s%s.key '
-                     '-pkeyopt rsa_keygen_bits:2048 '
-                     '-pkeyopt rsa_keygen_pubexp:%d' %
-                     (tmpdir, name, public_exponent))
-
-        # Create a certificate containing the public key
-        util.run_and_log(cons, 'openssl req -batch -new -x509 -key %s%s.key '
-                         '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
-
     def test_with_algo(sha_algo, padding, sign_options):
         """Test verified boot with the given hash algorithm.
 
@@ -377,8 +362,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
     dtb = '%ssandbox-u-boot.dtb' % tmpdir
     sig_node = '/configurations/conf-1/signature'
 
-    create_rsa_pair('dev')
-    create_rsa_pair('prod')
+    vboot_comm.create_rsa_pair(cons, tmpdir, 'dev')
+    vboot_comm.create_rsa_pair(cons, tmpdir, 'prod')
 
     # Create a number kernel image with zeroes
     with open('%stest-kernel.bin' % tmpdir, 'wb') as fd:
test/py/tests/vboot/sign-fdt.dts new file +23 -0
new file mode 100644
index 00000000000..2c5b84976b1
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	model = "Google Snow";
+	chosen {
+		bootargs = "console=tty1";
+		stdout-path = "serial3:115200n8";
+	};
+	aliases {
+		serail0 = "/serial@12c30000";
+	};
+
+	serial@12c30000 {
+		compatible = "samsung,exynos4210-uart";
+		reg = <0x12c30000 0x00000100>;
+		u-boot,dm-pre-reloc;
+	};
+};
test/py/tests/vboot_comm.py new file +22 -0
new file mode 100644
index 00000000000..7e1690e89f8
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2021 Google LLC
+#
+# Common functions
+
+import u_boot_utils as util
+
+def create_rsa_pair(cons, tmpdir, name):
+    """Generate a new RSA key pair and certificate
+
+    Args:
+        name: Name of the key (e.g. 'dev')
+    """
+    public_exponent = 65537
+    util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %s%s.key '
+                 '-pkeyopt rsa_keygen_bits:2048 '
+                 '-pkeyopt rsa_keygen_pubexp:%d' %
+                 (tmpdir, name, public_exponent))
+
+    # Create a certificate containing the public key
+    util.run_and_log(cons, 'openssl req -batch -new -x509 -key %s%s.key '
+                     '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#27 lore raw

PATCH 16/16 tools: Add man pages for fdt_sign and fdt_check_sign

In reply to Simon Glass

Add some documentation for these tools, along with a MAINTAINER entry.

---

 MAINTAINERS          |   7 +++
 doc/fdt_check_sign.1 |  74 +++++++++++++++++++++++++++++
 doc/fdt_sign.1       | 111 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 192 insertions(+)
 create mode 100644 doc/fdt_check_sign.1
 create mode 100644 doc/fdt_sign.1
MAINTAINERS +7 -0
index 00ff572d4d2..9f476d03eb0 100644
@@ -780,6 +780,13 @@ F:	cmd/fdt.c
 F:	common/fdt_support.c
 F:	scripts/dtc-version.sh
 
+FDT SIGNING
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	doc/fdt_*sign.1
+F:	tools/fdt_check_sign.c
+F:	tools/fdt_sign.c
+
 FREEBSD
 M:	Rafal Jaworowski <[email protected]>
 S:	Maintained
doc/fdt_check_sign.1 new file +74 -0

74 lines not on this page · raw message

doc/fdt_sign.1 new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
#28 lore raw
In reply to Simon Glass

Hi Simon

Quoted 4 lines · Simon Glass

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

just to be sure: I am not one of those.

Quoted 3 lines

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

Quoted 116 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

The kernel and initrd can be dealt with in other ways. But without FIT, we have no standard way of signing and grouping FDT files. Instead we must include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format, it is possible to embed a signature inside the FDT itself, which is very convenient.

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT, other than in permitted nodes (e.g. /chosen).

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs to be determined.

For now there is absolutely no configurability in the signature mechanism. It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the /chosen node is implemented in h_exclude_nodes() like this:

   if (type == FDT_IS_NODE) {
      /* Ignore the chosen node as well as /signature and subnodes */
      if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
         return 0;
   }

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well as refactoring to avoid code duplication with the new tools. The last four patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

 MAINTAINERS                      |   7 +
 boot/image-fit-sig.c             | 151 +++++++++----
 boot/image-fit.c                 |  12 +-
 common/spl/spl_fit.c             |   3 +-
 doc/fdt_check_sign.1             |  74 +++++++
 doc/fdt_sign.1                   | 111 ++++++++++
 include/image.h                  |  80 ++++++-
 include/u-boot/ecdsa.h           |   5 +-
 include/u-boot/rsa.h             |   5 +-
 lib/ecdsa/ecdsa-libcrypto.c      |   4 +-
 lib/rsa/rsa-sign.c               |   5 +-
 lib/rsa/rsa-verify.c             |  13 +-
 test/py/tests/test_fdt_sign.py   |  83 ++++++++
 test/py/tests/test_vboot.py      |  21 +-
 test/py/tests/vboot/sign-fdt.dts |  23 ++
 test/py/tests/vboot_comm.py      |  22 ++
 tools/Makefile                   |  10 +-
 tools/fdt-host.c                 | 353 +++++++++++++++++++++++++++++++
 tools/fdt_check_sign.c           |  85 ++++++++
 tools/fdt_host.h                 |  46 ++++
 tools/fdt_sign.c                 | 210 ++++++++++++++++++
 tools/fit_check_sign.c           |   4 +-
 tools/fit_common.c               |  69 ++++++
 tools/fit_common.h               |  23 ++
 tools/fit_image.c                |  59 +-----
 tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++
 tools/image-host.c               | 155 +++++++++++---
 tools/imagetool.h                |   4 +
 tools/mkimage.c                  |   4 +
 29 files changed, 1714 insertions(+), 181 deletions(-)
 create mode 100644 doc/fdt_check_sign.1
 create mode 100644 doc/fdt_sign.1
 create mode 100644 test/py/tests/test_fdt_sign.py
 create mode 100644 test/py/tests/vboot/sign-fdt.dts
 create mode 100644 test/py/tests/vboot_comm.py
 create mode 100644 tools/fdt-host.c
 create mode 100644 tools/fdt_check_sign.c
 create mode 100644 tools/fdt_sign.c
 create mode 100644 tools/image-fdt-sig.c
Quoted 4 lines

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
[email protected] | Skype: ffozog

#29 lore raw
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve,  U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Quoted 6 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
   that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Quoted 2 lines

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

Quoted 11 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

Quoted 12 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Quoted 7 lines

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

This series should have been sent as RFC.

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

   if (type == FDT_IS_NODE) {
      /* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10)) return 0;
   }

Man pages are provided with example usage of the tools. Use this to view them:

   man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
  rsa: Add debugging for failure cases
  fit_check_sign: Update help to mention the key is in a dtb
  tools: Move copyfile() into a common file
  tools: Avoid leaving extra data at the end of copied files
  tools: Improve comments in signing functions
  tools: Drop unused name in image-host
  tools: Avoid confusion between keys and signatures
  tools: Tidy up argument order in fit_config_check_sig()
  tools: Pass the key blob around
  image: Return destination node for add_verify_data() method
  tools: Pass public-key node through to caller
  tools: mkimage: Show where signatures/keys are written
  tools: Add a new tool to sign FDT blobs
  tools: Add a new tool to check FDT-blob signatures
  test: Add a test for FDT signing
  tools: Add man pages for fdt_sign and fdt_check_sign

 MAINTAINERS                      |   7 + boot/image-fit-sig.c             | 151 +++++++++---- boot/image-fit.c                 |  12 +- common/spl/spl_fit.c             |   3 +- doc/fdt_check_sign.1             |  74 +++++++ doc/fdt_sign.1                   | 111 ++++++++++ include/image.h                  |  80 ++++++- include/u-boot/ecdsa.h           |   5 +- include/u-boot/rsa.h             |   5 +- lib/ecdsa/ecdsa-libcrypto.c      |   4 +- lib/rsa/rsa-sign.c               |   5 +- lib/rsa/rsa-verify.c             |  13 +- test/py/tests/test_fdt_sign.py   |  83 ++++++++ test/py/tests/test_vboot.py      |  21 +- test/py/tests/vboot/sign-fdt.dts |  23 ++ test/py/tests/vboot_comm.py      |  22 ++
 tools/Makefile                   |  10 +-
 tools/fdt-host.c                 | 353 +++++++++++++++++++++++++++++++ tools/fdt_check_sign.c           |  85 ++++++++ tools/fdt_host.h                 |  46 ++++ tools/fdt_sign.c                 | 210 ++++++++++++++++++ tools/fit_check_sign.c           |   4 +- tools/fit_common.c               |  69 ++++++ tools/fit_common.h               |  23 ++ tools/fit_image.c                |  59 +----- tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++ tools/image-host.c               | 155 +++++++++++--- tools/imagetool.h                |   4 +
 tools/mkimage.c                  |   4 +
 29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1
 create mode 100644 doc/fdt_sign.1
 create mode 100644 test/py/tests/test_fdt_sign.py
 create mode 100644 test/py/tests/vboot/sign-fdt.dts
 create mode 100644 test/py/tests/vboot_comm.py
 create mode 100644 tools/fdt-host.c
 create mode 100644 tools/fdt_check_sign.c
 create mode 100644 tools/fdt_sign.c
 create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

#30 lore raw

Hi Heinrich,

Quoted 26 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Quoted 6 lines

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

Quoted 13 lines
Quoted 7 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Quoted 4 lines

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

Quoted 5 lines
Quoted 3 lines

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Quoted 17 lines
Quoted 12 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Quoted 5 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 18 lines
Quoted 18 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

Quoted 7 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 2 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 101 lines

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
return 0;
}

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 13 +-
test/py/tests/test_fdt_sign.py | 83 ++++++++
test/py/tests/test_vboot.py | 21 +-
test/py/tests/vboot/sign-fdt.dts | 23 ++
test/py/tests/vboot_comm.py | 22 ++
tools/Makefile | 10 +-
tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++
tools/fdt_check_sign.c | 85 ++++++++
tools/fdt_host.h | 46 ++++
tools/fdt_sign.c | 210 ++++++++++++++++++
tools/fit_check_sign.c | 4 +-
tools/fit_common.c | 69 ++++++
tools/fit_common.h | 23 ++
tools/fit_image.c | 59 +-----
tools/image-fdt-sig.c | 254 ++++++++++++++++++++++
tools/image-host.c | 155 +++++++++++---
tools/imagetool.h | 4 +
tools/mkimage.c | 4 +
29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

#31 lore raw

Hi Simon,

Quoted 66 lines · Simon Glass

Hi Heinrich,

Quoted 12 lines · Heinrich Schuchardt
Quoted 8 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Quoted 6 lines
Quoted 6 lines

Various people are opposed to using FIT since:

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders,

notably

Quoted 3 lines
Quoted 3 lines

UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI

subsystem.

Quoted 11 lines
Quoted 1 line

FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

Quoted 6 lines
Quoted 6 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and

initrd

Quoted 11 lines
Quoted 1 line

being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

The kernel and initrd can be dealt with in other ways. But without

FIT,

Quoted 2 lines

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Ilias has made a proposal to “measure” files that do not have signatures until files include signature.

Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is

needed.

Quoted 1 line
Quoted 1 line

One option would be to tack a signature on before or after the

file,

Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which

is very

Quoted 3 lines
Quoted 3 lines

convenient.

This series provides a tool, fdt_sign, which can add a signature

to an

Quoted 4 lines
Quoted 3 lines

FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Shouldn’t devicetree.org and kernel.org folks involved in this DT signing effort ? I believe there are parrallel efforts in this area. Or is it a private <u-boot FDT sign>? in that case, they do not need to be involved. Depending on the case, you may want to split the patch series in a number of chunks.

Quoted 163 lines
Quoted 6 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 8 lines
Quoted 8 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this

case

Quoted 6 lines
Quoted 6 lines

that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to

U-Boot

Quoted 11 lines
Quoted 6 lines

fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 2 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 6 lines

Best regards

Heinrich

Quoted 1 line

It would of course be possible to adjust which nodes are signed,

as is

Quoted 6 lines
Quoted 6 lines

done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and

subnodes */

Quoted 1 line
Quoted 1 line
           if (!strcmp("/chosen", data) || !strncmp("/signature",

data, 10))

Quoted 4 lines
Quoted 4 lines
              return 0;
        }

    Man pages are provided with example usage of the tools. Use this

to view

Quoted 10 lines
Quoted 10 lines

them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

Quoted 3 lines
Quoted 3 lines

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 1 line
Quoted 1 line
    <

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 31 lines
Quoted 31 lines

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-

Quoted 8 lines
Quoted 8 lines
      lib/rsa/rsa-sign.c               |   5 +-
      lib/rsa/rsa-verify.c             |  13 +-
      test/py/tests/test_fdt_sign.py   |  83 ++++++++
      test/py/tests/test_vboot.py      |  21 +-
      test/py/tests/vboot/sign-fdt.dts |  23 ++
      test/py/tests/vboot_comm.py      |  22 ++
      tools/Makefile                   |  10 +-
      tools/fdt-host.c                 | 353

+++++++++++++++++++++++++++++++

Quoted 22 lines
Quoted 22 lines
      tools/fdt_check_sign.c           |  85 ++++++++
      tools/fdt_host.h                 |  46 ++++
      tools/fdt_sign.c                 | 210 ++++++++++++++++++
      tools/fit_check_sign.c           |   4 +-
      tools/fit_common.c               |  69 ++++++
      tools/fit_common.h               |  23 ++
      tools/fit_image.c                |  59 +-----
      tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++
      tools/image-host.c               | 155 +++++++++++---
      tools/imagetool.h                |   4 +
      tools/mkimage.c                  |   4 +
      29 files changed, 1714 insertions(+), 181 deletions(-)

create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

Quoted 8 lines
Quoted 8 lines
    --
    2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype:

ffozog

Quoted 2 lines
Quoted 2 lines
Signature · 3 lines
François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
[email protected] | Skype: ffozog
#32 lore raw

Hi François,

Quoted 67 lines · François Ozog

Hi Simon,

Quoted 63 lines · Simon Glass

Hi Heinrich,

Quoted 26 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Quoted 6 lines

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

Quoted 13 lines
Quoted 7 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Quoted 4 lines

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Ilias has made a proposal to “measure” files that do not have signatures until files include signature.

OK

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Shouldn’t devicetree.org and kernel.org folks involved in this DT signing effort ? I believe there are parrallel efforts in this area. Or is it a private <u-boot FDT sign>? in that case, they do not need to be involved. Depending on the case, you may want to split the patch series in a number of chunks.

Yes indeed these people should be involved, but I also think that interested parties should be part of the boot-architecture effort. The meeting notes where this tool was discussed are here:

https://lists.linaro.org/pipermail/boot-architecture/2021-October/001955.html

My slides are available there, too.

Here is what I have done so far: I sent a v4 series to devicetree-compiler a week ago with the fdt_region and fdtgrep parts. Rob and Bill are copied on this series, as you can see. I was not sure about sending U-Boot patches to the boot-architecture list, but I will cover it in a future meeting.

But if there are others that should be copied, please feel free to add them, or point me to them.

Regards,
Simon

Quoted 157 lines
Quoted 42 lines
Quoted 7 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 18 lines
Quoted 18 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

Quoted 7 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 1 line
Quoted 109 lines
Quoted 1 line

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 101 lines

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
return 0;
}

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 13 +-
test/py/tests/test_fdt_sign.py | 83 ++++++++
test/py/tests/test_vboot.py | 21 +-
test/py/tests/vboot/sign-fdt.dts | 23 ++
test/py/tests/vboot_comm.py | 22 ++
tools/Makefile | 10 +-
tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++
tools/fdt_check_sign.c | 85 ++++++++
tools/fdt_host.h | 46 ++++
tools/fdt_sign.c | 210 ++++++++++++++++++
tools/fit_check_sign.c | 4 +-
tools/fit_common.c | 69 ++++++
tools/fit_common.h | 23 ++
tools/fit_image.c | 59 +-----
tools/image-fdt-sig.c | 254 ++++++++++++++++++++++
tools/image-host.c | 155 +++++++++++---
tools/imagetool.h | 4 +
tools/mkimage.c | 4 +
29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

--
François-Frédéric Ozog | Director Business Development
T: +33.67221.6485
[email protected] | Skype: ffozog

#33 lore raw

Hi Simon

Quoted 132 lines · Simon Glass

Hi François,

Quoted 8 lines · François Ozog

Hi Simon,

Quoted 4 lines · Simon Glass

Hi Heinrich,

On Fri, 12 Nov 2021 at 17:02, Heinrich Schuchardt <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines · François Ozog
Quoted 6 lines

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot

image

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

type.

Various people are opposed to using FIT since:

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders,

notably

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI

subsystem.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 1 line

FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Simon, what are you missing?

Some people don't want to use FIT.

Quoted 4 lines
Quoted 4 lines

b) it requires packaging a kernel in this standard U-Boot

format,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

meaning
that distros must run 'mkimage' and deal with the kernel

and initrd

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/

for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used

for

Quoted 9 lines
Quoted 9 lines
Quoted 1 line

signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

Quoted 3 lines
Quoted 3 lines

The kernel and initrd can be dealt with in other ways. But

without FIT,

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Ilias has made a proposal to “measure” files that do not have signatures

until files include signature.

OK

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

we have no standard way of signing and grouping FDT files.

Instead

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files

is needed.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

One option would be to tack a signature on before or after the

file,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

processing it accordingly. But due to the nature of the FDT

binary

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

format,
it is possible to embed a signature inside the FDT itself,

which is very

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

convenient.

This series provides a tool, fdt_sign, which can add a

signature to an

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

FDT. The signature can be checked later, preventing any change

to

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

the FDT,
other than in permitted nodes (e.g. /chosen).

Shouldn’t devicetree.org and kernel.org folks involved in this DT

signing effort ? I believe there are parrallel efforts in this area. Or is it a private <u-boot FDT sign>? in that case, they do not need to be involved. Depending on the case, you may want to split the patch series in a number of chunks.

Yes indeed these people should be involved, but I also think that interested parties should be part of the boot-architecture effort. The meeting notes where this tool was discussed are here:

https://lists.linaro.org/pipermail/boot-architecture/2021-October/001955.html

My slides are available there, too.

Quoted 9 lines

Here is what I have done so far: I sent a v4 series to devicetree-compiler a week ago with the fdt_region and fdtgrep parts. Rob and Bill are copied on this series, as you can see. I was not sure about sending U-Boot patches to the boot-architecture list, but I will cover it in a future meeting.

But if there are others that should be copied, please feel free to add them, or point me to them.

Sorry. I missed those. Now the reference is made that’s good.

Quoted 180 lines

Regards,
Simon

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 2 lines
Quoted 2 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or

FIT.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As with FIT signing, multiple signatures are possible, but in

this case

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

that requires that fit_sign be called once for each signature.

To

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to

U-Boot

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fairly easily, but needs further discussion as the correct

plumbing

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

needs
to be determined.

For now there is absolutely no configurability in the signature mechanism.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Best regards

Heinrich

Quoted 1 line

It would of course be possible to adjust which nodes are

signed, as is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

done for FIT, but that needs further discussion also. The

omission

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
    of the
    /chosen node is implemented in h_exclude_nodes() like this:

        if (type == FDT_IS_NODE) {
           /* Ignore the chosen node as well as /signature and

subnodes */

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
           if (!strcmp("/chosen", data) || !strncmp("/signature",

data, 10))

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
              return 0;
        }

    Man pages are provided with example usage of the tools. Use

this to view

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the

way,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
    <

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
      lib/rsa/rsa-sign.c               |   5 +-
      lib/rsa/rsa-verify.c             |  13 +-
      test/py/tests/test_fdt_sign.py   |  83 ++++++++
      test/py/tests/test_vboot.py      |  21 +-
      test/py/tests/vboot/sign-fdt.dts |  23 ++
      test/py/tests/vboot_comm.py      |  22 ++
      tools/Makefile                   |  10 +-
      tools/fdt-host.c                 | 353

+++++++++++++++++++++++++++++++

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
      tools/fdt_check_sign.c           |  85 ++++++++
      tools/fdt_host.h                 |  46 ++++
      tools/fdt_sign.c                 | 210 ++++++++++++++++++
      tools/fit_check_sign.c           |   4 +-
      tools/fit_common.c               |  69 ++++++
      tools/fit_common.h               |  23 ++
      tools/fit_image.c                |  59 +-----
      tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++
      tools/image-host.c               | 155 +++++++++++---
      tools/imagetool.h                |   4 +
      tools/mkimage.c                  |   4 +
      29 files changed, 1714 insertions(+), 181 deletions(-)

create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
    --
    2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> |

Skype: ffozog

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--
François-Frédéric Ozog | Director Business Development
T: +33.67221.6485
[email protected] | Skype: ffozog

Signature · 3 lines
François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
[email protected] | Skype: ffozog
#34 lore raw
In reply to Simon Glass
Quoted 29 lines · Simon Glass

Hi Heinrich,

Quoted 26 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Quoted 8 lines
Quoted 6 lines

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

The problem with FIT is that other firmware like EDK II does not support it.

Why do you expect those people to like your new tool better?

Quoted 14 lines
Quoted 14 lines
Quoted 8 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Quoted 8 lines
Quoted 4 lines

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

The question was:

How do you protect the private key used by Linux to sign the FIT image with the updated initrd generated by intramfs-tools?

Best regards

Heinrich

Quoted 175 lines
Quoted 6 lines
Quoted 4 lines

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Quoted 17 lines
Quoted 12 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Quoted 5 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 18 lines
Quoted 18 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

Quoted 7 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 2 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 101 lines

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
return 0;
}

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 13 +-
test/py/tests/test_fdt_sign.py | 83 ++++++++
test/py/tests/test_vboot.py | 21 +-
test/py/tests/vboot/sign-fdt.dts | 23 ++
test/py/tests/vboot_comm.py | 22 ++
tools/Makefile | 10 +-
tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++
tools/fdt_check_sign.c | 85 ++++++++
tools/fdt_host.h | 46 ++++
tools/fdt_sign.c | 210 ++++++++++++++++++
tools/fit_check_sign.c | 4 +-
tools/fit_common.c | 69 ++++++
tools/fit_common.h | 23 ++
tools/fit_image.c | 59 +-----
tools/image-fdt-sig.c | 254 ++++++++++++++++++++++
tools/image-host.c | 155 +++++++++++---
tools/imagetool.h | 4 +
tools/mkimage.c | 4 +
29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

#35 lore raw

Hi Heinrich,

Quoted 38 lines · Heinrich Schuchardt
Quoted 34 lines · Simon Glass

Hi Heinrich,

Quoted 31 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Simon, what are you missing?

Some people don't want to use FIT.

The problem with FIT is that other firmware like EDK II does not support it.

Why do you expect those people to like your new tool better?

I believe the EDK decision is not so much that it *does* not support FIT, which is after all not a lot of code, but that it *should* not. If I have that wrong, please let me know.

The goal here is to support signing in an FDT without FIT. I believe EDK supports FDT, at least.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 9 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Quoted 8 lines
Quoted 3 lines

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

The question was:

How do you protect the private key used by Linux to sign the FIT image with the updated initrd generated by intramfs-tools?

Well, if it is a FIT we can add a seperate signature at the time the initramfs-tools runs. It does support multiple signatures. If that is not suitable I am sure something else can be devised. What are the constraints / requirements?

Regards,
Simon

Quoted 180 lines

Best regards

Heinrich

Quoted 175 lines
Quoted 6 lines
Quoted 4 lines

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Quoted 17 lines
Quoted 12 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Quoted 5 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 18 lines
Quoted 18 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

Quoted 7 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 2 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 101 lines

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
return 0;
}

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 13 +-
test/py/tests/test_fdt_sign.py | 83 ++++++++
test/py/tests/test_vboot.py | 21 +-
test/py/tests/vboot/sign-fdt.dts | 23 ++
test/py/tests/vboot_comm.py | 22 ++
tools/Makefile | 10 +-
tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++
tools/fdt_check_sign.c | 85 ++++++++
tools/fdt_host.h | 46 ++++
tools/fdt_sign.c | 210 ++++++++++++++++++
tools/fit_check_sign.c | 4 +-
tools/fit_common.c | 69 ++++++
tools/fit_common.h | 23 ++
tools/fit_image.c | 59 +-----
tools/image-fdt-sig.c | 254 ++++++++++++++++++++++
tools/image-host.c | 155 +++++++++++---
tools/imagetool.h | 4 +
tools/mkimage.c | 4 +
29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

#36 lore raw

Hi Simon

Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 7 lines · Heinrich Schuchardt
Quoted 3 lines · Simon Glass

Hi Heinrich,

On Fri, 12 Nov 2021 at 17:02, Heinrich Schuchardt <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines · François Ozog
Quoted 6 lines

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot

image

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

type.

Various people are opposed to using FIT since:

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders,

notably

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI

subsystem.

Quoted 14 lines
Quoted 13 lines
Quoted 11 lines
Quoted 1 line

FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

Quoted 9 lines
Quoted 1 line

The problem with FIT is that other firmware like EDK II does not support

it.

Quoted 2 lines

Why do you expect those people to like your new tool better?

I believe the EDK decision is not so much that it *does* not support FIT, which is after all not a lot of code, but that it *should* not. If I have that wrong, please let me know.

UEFI (EDK2 and now U-Boot) design choice is that it does not include *any* technologies for OS: UEFI launches an OS loader that know about those. A possible way to introduce a FIT is by adding a protocol that can register a vendor media file , assign a UUID to a FIT. Add support for this in the UEFI stub of the kernel.
Another way would be a minimalistic UEFI app that will fetch the second parameter as a FIT. The FIT format parsing code is only in this minimalistic loader. U-Boot can play this role based on your efforts to have U-Boot as UEFI application.
You could also promote FIT in the systemd-boot UeFi application. I believe this is a very good option BTW.

Quoted 251 lines

The goal here is to support signing in an FDT without FIT. I believe EDK supports FDT, at least.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

b) it requires packaging a kernel in this standard U-Boot

format,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

meaning
that distros must run 'mkimage' and deal with the kernel

and initrd

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/

for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used

for

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

signing any file containing an initrd.

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

The question was:

How do you protect the private key used by Linux to sign the FIT image with the updated initrd generated by intramfs-tools?

Well, if it is a FIT we can add a seperate signature at the time the initramfs-tools runs. It does support multiple signatures. If that is not suitable I am sure something else can be devised. What are the constraints / requirements?

Regards,
Simon

Quoted 9 lines

Best regards

Heinrich

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The kernel and initrd can be dealt with in other ways. But

without FIT,

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Quoted 2 lines
Quoted 2 lines

we have no standard way of signing and grouping FDT files.

Instead

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files

is needed.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

One option would be to tack a signature on before or after the

file,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

processing it accordingly. But due to the nature of the FDT

binary

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

format,
it is possible to embed a signature inside the FDT itself,

which is very

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

convenient.

This series provides a tool, fdt_sign, which can add a

signature to an

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

FDT. The signature can be checked later, preventing any change

to

Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 2 lines

the FDT,
other than in permitted nodes (e.g. /chosen).

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 2 lines
Quoted 2 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or

FIT.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As with FIT signing, multiple signatures are possible, but in

this case

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

that requires that fit_sign be called once for each signature.

To

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to

U-Boot

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fairly easily, but needs further discussion as the correct

plumbing

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

needs
to be determined.

For now there is absolutely no configurability in the signature mechanism.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Best regards

Heinrich

Quoted 1 line

It would of course be possible to adjust which nodes are

signed, as is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

done for FIT, but that needs further discussion also. The

omission

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
     of the
     /chosen node is implemented in h_exclude_nodes() like this:

         if (type == FDT_IS_NODE) {
            /* Ignore the chosen node as well as /signature and

subnodes */

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
            if (!strcmp("/chosen", data) || !strncmp("/signature",

data, 10))

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
               return 0;
         }

     Man pages are provided with example usage of the tools. Use

this to view

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the

way,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
     <

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
       lib/rsa/rsa-sign.c               |   5 +-
       lib/rsa/rsa-verify.c             |  13 +-
       test/py/tests/test_fdt_sign.py   |  83 ++++++++
       test/py/tests/test_vboot.py      |  21 +-
       test/py/tests/vboot/sign-fdt.dts |  23 ++
       test/py/tests/vboot_comm.py      |  22 ++
       tools/Makefile                   |  10 +-
       tools/fdt-host.c                 | 353

+++++++++++++++++++++++++++++++

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
       tools/fdt_check_sign.c           |  85 ++++++++
       tools/fdt_host.h                 |  46 ++++
       tools/fdt_sign.c                 | 210 ++++++++++++++++++
       tools/fit_check_sign.c           |   4 +-
       tools/fit_common.c               |  69 ++++++
       tools/fit_common.h               |  23 ++
       tools/fit_image.c                |  59 +-----
       tools/image-fdt-sig.c            | 254 ++++++++++++++++++++++
       tools/image-host.c               | 155 +++++++++++---
       tools/imagetool.h                |   4 +
       tools/mkimage.c                  |   4 +
       29 files changed, 1714 insertions(+), 181 deletions(-)

create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
     --
     2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype:

ffozog

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Signature · 3 lines
François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
[email protected] | Skype: ffozog
#37 lore raw

Hi François,

Quoted 54 lines · François Ozog

Hi Simon

Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 45 lines · Heinrich Schuchardt
Quoted 29 lines · Simon Glass

Hi Heinrich,

Quoted 26 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Quoted 8 lines
Quoted 6 lines

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Simon, what are you missing?

Some people don't want to use FIT.

The problem with FIT is that other firmware like EDK II does not support it.

Why do you expect those people to like your new tool better?

Quoted 8 lines
Quoted 3 lines

I believe the EDK decision is not so much that it *does* not support FIT, which is after all not a lot of code, but that it *should* not. If I have that wrong, please let me know.

UEFI (EDK2 and now U-Boot) design choice is that it does not include *any* technologies for OS: UEFI launches an OS loader that know about those.
A possible way to introduce a FIT is by adding a protocol that can register a vendor media file , assign a UUID to a FIT. Add support for this in the UEFI stub of the kernel.
Another way would be a minimalistic UEFI app that will fetch the second parameter as a FIT. The FIT format parsing code is only in this minimalistic loader. U-Boot can play this role based on your efforts to have U-Boot as UEFI application. You could also promote FIT in the systemd-boot UeFi application. I believe this is a very good option BTW.

I think UEFI is making things very complicated. If we define a standard boot flow we should not need grub.

U-Boot already supports FIT so we don't have a problem there.

Since FIT is a container format, and UEFI supports other container formats (capsule update for example), there is no obvious philosophical reason why UEFI should not support FIT.

Anyway, at least you can understand why I sent this patch.

Regards,
SImon

Quoted 228 lines
Quoted 34 lines

The goal here is to support signing in an FDT without FIT. I believe EDK supports FDT, at least.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 9 lines

b) it requires packaging a kernel in this standard U-Boot format, meaning
that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

U-Boot tools are contained in distros like Debian and Ubuntu. Package flash-kernel uses a script in /etc/initramfs/post-update.d/ for a similar purpose. The same hook directory can be used to create a FIT image with a simple bash script.

Why do we need a new tool for signing device-trees?

The real problem to solve is the protection of the private key used for signing any file containing an initrd.

Quoted 8 lines
Quoted 3 lines

Well FIT already solves that one. Either FIT is not being used, in which case this series is useful, or it is being used, in which case the initrd problem is solved.

The question was:

How do you protect the private key used by Linux to sign the FIT image with the updated initrd generated by intramfs-tools?

Quoted 188 lines

Well, if it is a FIT we can add a seperate signature at the time the initramfs-tools runs. It does support multiple signatures. If that is not suitable I am sure something else can be devised. What are the constraints / requirements?

Regards,
Simon

Quoted 180 lines

Best regards

Heinrich

Quoted 175 lines
Quoted 6 lines
Quoted 4 lines

The kernel and initrd can be dealt with in other ways. But without FIT,

How can the initrd be checked without FIT?

I don't know. Please check with the EFI people.

Quoted 17 lines
Quoted 12 lines

we have no standard way of signing and grouping FDT files. Instead we must
include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format,
it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 4 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT,
other than in permitted nodes (e.g. /chosen).

Quoted 5 lines

I am not aware of any standard defining which nodes may be changed in the FDT fixup and which may not be changed.

How can we discover which nodes were excluded from the signature after the signature?

There is no way at present. I decided against adding a list of signed nodes. We can of course add whatever is useful here.

Quoted 18 lines
Quoted 18 lines

This series also provides a fdt_check_sign tool, used to check signatures.

Both of these tools are stand-alone do not require mkimage or FIT.

As with FIT signing, multiple signatures are possible, but in this case that requires that fit_sign be called once for each signature. To make the
check fail if a signature does not match, it should be marked as 'required' using the -r flag to fdt_sign.

Run-time support for checking FDT signatures could be added to U-Boot fairly easily, but needs further discussion as the correct plumbing needs
to be determined.

Quoted 7 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism.

I would have expected a description of what a signature looks like. I don't wont to reverse engineer your patches.

Please, describe this in doc/develop/ and in this cover-letter.

It is the same format as the FIT signature, an RSA signature. See here:

https://github.com/u-boot/u-boot/blob/master/doc/uImage.FIT/signature.txt#L162

Quoted 2 lines

This series should have been sent as RFC.

The last time I did that it disappeared without trace. You can of course make comments on any series I send.

Regards,
Simon

Quoted 101 lines

Best regards

Heinrich

Quoted 96 lines

It would of course be possible to adjust which nodes are signed, as is done for FIT, but that needs further discussion also. The omission of the
/chosen node is implemented in h_exclude_nodes() like this:

if (type == FDT_IS_NODE) {
/* Ignore the chosen node as well as /signature and subnodes */ if (!strcmp("/chosen", data) || !strncmp("/signature", data, 10))
return 0;
}

Man pages are provided with example usage of the tools. Use this to view them:

man -l doc/fdt_check_sign.1

This series also includes various clean-ups noticed along the way, as well
as refactoring to avoid code duplication with the new tools. The last four
patches are the new code.

This series is available at u-boot-dm/fdt-sign-working :

https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working
<https://source.denx.de/u-boot/custodians/u-boot-dm/-/tree/fdt-sign-working>

Simon Glass (16):
rsa: Add debugging for failure cases
fit_check_sign: Update help to mention the key is in a dtb
tools: Move copyfile() into a common file
tools: Avoid leaving extra data at the end of copied files
tools: Improve comments in signing functions
tools: Drop unused name in image-host
tools: Avoid confusion between keys and signatures
tools: Tidy up argument order in fit_config_check_sig()
tools: Pass the key blob around
image: Return destination node for add_verify_data() method
tools: Pass public-key node through to caller
tools: mkimage: Show where signatures/keys are written
tools: Add a new tool to sign FDT blobs
tools: Add a new tool to check FDT-blob signatures
test: Add a test for FDT signing
tools: Add man pages for fdt_sign and fdt_check_sign

MAINTAINERS | 7 +
boot/image-fit-sig.c | 151 +++++++++----
boot/image-fit.c | 12 +-
common/spl/spl_fit.c | 3 +-
doc/fdt_check_sign.1 | 74 +++++++
doc/fdt_sign.1 | 111 ++++++++++
include/image.h | 80 ++++++-
include/u-boot/ecdsa.h | 5 +-
include/u-boot/rsa.h | 5 +-
lib/ecdsa/ecdsa-libcrypto.c | 4 +-
lib/rsa/rsa-sign.c | 5 +-
lib/rsa/rsa-verify.c | 13 +-
test/py/tests/test_fdt_sign.py | 83 ++++++++
test/py/tests/test_vboot.py | 21 +-
test/py/tests/vboot/sign-fdt.dts | 23 ++
test/py/tests/vboot_comm.py | 22 ++
tools/Makefile | 10 +-
tools/fdt-host.c | 353 +++++++++++++++++++++++++++++++
tools/fdt_check_sign.c | 85 ++++++++
tools/fdt_host.h | 46 ++++
tools/fdt_sign.c | 210 ++++++++++++++++++
tools/fit_check_sign.c | 4 +-
tools/fit_common.c | 69 ++++++
tools/fit_common.h | 23 ++
tools/fit_image.c | 59 +-----
tools/image-fdt-sig.c | 254 ++++++++++++++++++++++
tools/image-host.c | 155 +++++++++++---
tools/imagetool.h | 4 +
tools/mkimage.c | 4 +
29 files changed, 1714 insertions(+), 181 deletions(-) create mode 100644 doc/fdt_check_sign.1 create mode 100644 doc/fdt_sign.1
create mode 100644 test/py/tests/test_fdt_sign.py create mode 100644 test/py/tests/vboot/sign-fdt.dts create mode 100644 test/py/tests/vboot_comm.py create mode 100644 tools/fdt-host.c
create mode 100644 tools/fdt_check_sign.c create mode 100644 tools/fdt_sign.c
create mode 100644 tools/image-fdt-sig.c

--
2.34.0.rc1.387.gb447b232ab-goog

--

François-Frédéric Ozog | /Director Business Development/
T: +33.67221.6485
[email protected] <mailto:[email protected]> | Skype: ffozog

--
François-Frédéric Ozog | Director Business Development
T: +33.67221.6485
[email protected] | Skype: ffozog

#38 lore raw
Quoted 61 lines · Simon Glass

Hi François,

Quoted 58 lines · François Ozog

Hi Simon

Quoted 53 lines · Simon Glass

Hi Heinrich,

Quoted 38 lines · Heinrich Schuchardt
Quoted 34 lines · Simon Glass

Hi Heinrich,

Quoted 31 lines · Heinrich Schuchardt
Quoted 10 lines · François Ozog

Hi Simon

Le ven. 12 nov. 2021 à 20:36, Simon Glass <[email protected] <mailto:[email protected]>> a écrit :

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

Quoted 8 lines

just to be sure: I am not one of those.

a) it requires adding support for FIT into other bootloaders, notably UEFI

whatever happens to FIT is entirely orthogonal to U-Boot UEFI subsystem. FIT can evolve, U-Boot UEFI does not have to change.

We already can create signed FIT images containing a UEFI binary and a devcie-tree and launch the FIT image with the bootm command.

Cf.
CONFIG_BOOTM_EFI
test/py/tests/test_efi_fit.py
doc/usage/bootefi.rst

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Simon, what are you missing?

Some people don't want to use FIT.

The problem with FIT is that other firmware like EDK II does not support it.

Why do you expect those people to like your new tool better?

I believe the EDK decision is not so much that it *does* not support FIT, which is after all not a lot of code, but that it *should* not. If I have that wrong, please let me know.

Quoted 7 lines
Quoted 4 lines

UEFI (EDK2 and now U-Boot) design choice is that it does not include *any* technologies for OS: UEFI launches an OS loader that know about those.
A possible way to introduce a FIT is by adding a protocol that can register a vendor media file , assign a UUID to a FIT. Add support for this in the UEFI stub of the kernel.
Another way would be a minimalistic UEFI app that will fetch the second parameter as a FIT. The FIT format parsing code is only in this minimalistic loader. U-Boot can play this role based on your efforts to have U-Boot as UEFI application. You could also promote FIT in the systemd-boot UeFi application. I believe this is a very good option BTW.

I think UEFI is making things very complicated. If we define a standard boot flow we should not need grub.

To be clear, UEFI doesn't require grub (nor systemd-boot) but off the shelf distributions tend to really really like that, rather than modifying UEFI variables more directly to implement some sort of boot menu and other related features.

Signature · 1 line
Tom
#39 lore raw
In reply to Simon Glass
Quoted 20 lines · Simon Glass

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

a) it requires adding support for FIT into other bootloaders, notably UEFI
b) it requires packaging a kernel in this standard U-Boot format, meaning that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

The kernel and initrd can be dealt with in other ways. But without FIT, we have no standard way of signing and grouping FDT files. Instead we must include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format, it is possible to embed a signature inside the FDT itself, which is very convenient.

Quoted 5 lines

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT, other than in permitted nodes (e.g. /chosen).

This series also provides a fdt_check_sign tool, used to check signatures.

This could be useful. Not because I'm interested in signing device-tree
blobs as such, but as a replacement for the current incomprehensible way
FIT images are signed and verified. This seems to be a much better and
simpler scheme, that avoids (can avoid) the overly simplistic approach
of signing just image nodes, and the way too complex signing-configurations-and-then-add-a-property-saying-which-nodes-I-signed-and-sign-that-as-well.

In order not to hard-code anything in the tool about /chosen or whatnot, make the rule be that the blob (I'll use that word, because it can as well be a FIT image containing kernel image+initramfs etc., or a FIT containing a U-Boot script) has a property in the top node

  unsigned-nodes = "/chosen", "/signatures";

(maybe it could be

unsigned-nodes = <&chosen &sigs>

but that may make the implementation a little more complex). That property itself is by definition part of what gets signed. The verifier can and should choose to reject the whole thing if "/" is mentioned.

Then, please, for debugging, inside the /signatures node, beside the signature data, also add a copy of the offset/len pairs that were actually hashed, and that hash value.

  /signatures {
    hashed-regions = <offset0 len0 offset1 len1 ...>;
    hash-1 {
      value = 0xabcd;
      algo = "sha256";
    };
    signature-1 {
       ...
    };
    ...

And make the tool start by adding dummy properties, so those strings "hashed-regions", "value", "algo", "signer" and whatever other property names are used already exist in the string table. After that, fill in the actual values - and have the rule that the entire string table is hashed, not just some initial part of it.

The verifier will of course not rely on /signatures/hashed-regions, but will compute the regions itself based on /unsigned-nodes (and implicitly add a region consisting of the string table and the memreserve table).

Then we'd have a generic scheme for signing blobs, disentangled from whether they are actually describing hardware or used as a generic container format. And instead of "image" or "conf", we could mark a public key as being required for "whole-blob" (bikeshedding welcome), using that same scheme for verifying a container with a boot script and a container with kernel+initramfs+dtbs.

Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism. It would of course be possible to adjust which nodes are signed, as is

Yes, let the blob itself define that. And don't add any ad hoc "oh, skip a property if it is called data-offset or data or...".

Rasmus

#40 lore raw

Hi Rasmus,

Quoted 26 lines · Rasmus Villemoes
Quoted 24 lines · Simon Glass

At present mkimage supports signing FITs, the standard U-Boot image type.

Various people are opposed to using FIT since:

a) it requires adding support for FIT into other bootloaders, notably UEFI
b) it requires packaging a kernel in this standard U-Boot format, meaning that distros must run 'mkimage' and deal with the kernel and initrd being inside a FIT

The kernel and initrd can be dealt with in other ways. But without FIT, we have no standard way of signing and grouping FDT files. Instead we must include them in the distro as separate files.

In particular, some sort of mechanism for verifying FDT files is needed. One option would be to tack a signature on before or after the file, processing it accordingly. But due to the nature of the FDT binary format, it is possible to embed a signature inside the FDT itself, which is very convenient.

This series provides a tool, fdt_sign, which can add a signature to an FDT. The signature can be checked later, preventing any change to the FDT, other than in permitted nodes (e.g. /chosen).

Quoted 8 lines
Quoted 1 line

This series also provides a fdt_check_sign tool, used to check signatures.

This could be useful. Not because I'm interested in signing device-tree
blobs as such, but as a replacement for the current incomprehensible way
FIT images are signed and verified. This seems to be a much better and
simpler scheme, that avoids (can avoid) the overly simplistic approach
of signing just image nodes, and the way too complex signing-configurations-and-then-add-a-property-saying-which-nodes-I-signed-and-sign-that-as-well.

That property is not actually signed. It is just a hint.

Quoted 8 lines

In order not to hard-code anything in the tool about /chosen or whatnot, make the rule be that the blob (I'll use that word, because it can as well be a FIT image containing kernel image+initramfs etc., or a FIT containing a U-Boot script) has a property in the top node

  unsigned-nodes = "/chosen", "/signatures";
Quoted 7 lines

(maybe it could be

unsigned-nodes = <&chosen &sigs>

but that may make the implementation a little more complex). That property itself is by definition part of what gets signed. The verifier can and should choose to reject the whole thing if "/" is mentioned.

If you list unsigned nodes, then the signature will become invalid if a new image or config is added later.

Quoted 5 lines

Then, please, for debugging, inside the /signatures node, beside the signature data, also add a copy of the offset/len pairs that were actually hashed, and that hash value.

Quoted 10 lines
  /signatures {
    hashed-regions = <offset0 len0 offset1 len1 ...>;
    hash-1 {
      value = 0xabcd;
      algo = "sha256";
    };
    signature-1 {
       ...
    };
    ...

The offsets may change whenever the devicetree is modified.

Quoted 6 lines

And make the tool start by adding dummy properties, so those strings "hashed-regions", "value", "algo", "signer" and whatever other property names are used already exist in the string table. After that, fill in the actual values - and have the rule that the entire string table is hashed, not just some initial part of it.

The hashed part of the string table is the part used for each signature. It is in fact the whole table at the time that signing takes place. It's just that the table may expand late.

Quoted 11 lines

The verifier will of course not rely on /signatures/hashed-regions, but will compute the regions itself based on /unsigned-nodes (and implicitly add a region consisting of the string table and the memreserve table).

Then we'd have a generic scheme for signing blobs, disentangled from whether they are actually describing hardware or used as a generic container format. And instead of "image" or "conf", we could mark a public key as being required for "whole-blob" (bikeshedding welcome), using that same scheme for verifying a container with a boot script and a container with kernel+initramfs+dtbs.

What does this 'whole blob' help with?

Quoted 5 lines
Quoted 2 lines

For now there is absolutely no configurability in the signature mechanism. It would of course be possible to adjust which nodes are signed, as is

Yes, let the blob itself define that. And don't add any ad hoc "oh, skip a property if it is called data-offset or data or...".

We don't want to sign the data because it is already hashed once. There is no point and it just makes verification slower.

For data-offset we want tools to be able to move the data around, e.g. for memory-allocation reasons.

Overall I can grant that you are describing another way of doing things, but I'm not sure what it would bring us.

The scheme in this series is aimed at a different purpose: signing a devicetree blob, rather than a FIT.

Regards,
Simon