common, fit, rsa: enhancements
v3 cover common, fit, rsa: enhancements
- add sha256,rsa2048 and sha256,rsa4098 support to u-boot.
- add "fdt checksign" command to u-boot cmdshell. This command checks, if a fdt is correct signed.
- add hosttool "fit_info" which prints the offset and the len of a property from in a fdt file. This values can be used, to extract the data from a property (for example with "dd")
- add hosttool "fit_check_sign". This does the same as the u-boot cmdshell tool "fdt sign". It checks, if fit image is correct signed
- changes for v2:
- add comments from Simon Glass
- add new patch: "[PATCH v2 6/8] gen: Add progressive hash API" from Hung-ying Tyan <[email protected]> as
Simon Glass mentioned
- changes for v3:
- add comments from Simon Glass:
- rebased against current head eeb72e67619b98d2502fe634a3a5d9953de92ad0
-> Makefile adaptions necessary introduced from kbuild changes
Heiko Schocher (8):
tools/image-host: fix sign-images bug
fdt: add "fdt checksign" command
fit: add sha256 support
rsa: add sha256-rsa2048 algorithm
rsa: add sha256,rsa4096 algorithm
gen: Add progressive hash API
tools, fit: add fit_info host command tools, fit_check_sign: verify a signed fit image
common/cmd_fdt.c | 42 +++++-
common/hash.c | 116 +++++++++++++--
common/image-fit.c | 5 +
common/image-sig.c | 63 ++++++++
doc/uImage.FIT/signature.txt | 20 ++-
include/fdt_support.h | 5 +
include/hash.h | 48 ++++++
include/image.h | 38 ++++-
include/rsa-checksum.h | 24 +++
include/rsa.h | 24 +++
lib/fdtdec.c | 20 +++
lib/rsa/Makefile | 2 +-
lib/rsa/rsa-checksum.c | 163 +++++++++++++++++++++
lib/rsa/rsa-sign.c | 10 +-
lib/rsa/rsa-verify.c | 107 +++++---------
lib/sha256.c | 5 +-
.../{sign-configs.its => sign-configs-sha1.its} | 0
test/vboot/sign-configs-sha256.its | 45 ++++++
.../{sign-images.its => sign-images-sha1.its} | 0
test/vboot/sign-images-sha256.its | 42 ++++++
test/vboot/vboot_test.sh | 86 +++++++----
tools/.gitignore | 2 +
tools/Makefile | 16 +-
tools/fdt_host.h | 2 +
tools/fdtdec.c | 1 +
tools/fit_check_sign.c | 85 +++++++++++
tools/fit_common.c | 86 +++++++++++
tools/fit_common.h | 22 +++
tools/fit_image.c | 62 +-------
tools/fit_info.c | 96 ++++++++++++
tools/image-host.c | 17 ++-
tools/rsa-checksum.c | 1 +
tools/rsa-verify.c | 1 +
tools/sha256.c | 1 +
34 files changed, 1076 insertions(+), 181 deletions(-)
create mode 100644 include/rsa-checksum.h
create mode 100644 lib/rsa/rsa-checksum.c
rename test/vboot/{sign-configs.its => sign-configs-sha1.its} (100%)
create mode 100644 test/vboot/sign-configs-sha256.its
rename test/vboot/{sign-images.its => sign-images-sha1.its} (100%)
create mode 100644 test/vboot/sign-images-sha256.its
create mode 100644 tools/fdtdec.c
create mode 100644 tools/fit_check_sign.c
create mode 100644 tools/fit_common.c
create mode 100644 tools/fit_common.h
create mode 100644 tools/fit_info.c
create mode 100644 tools/rsa-checksum.c
create mode 100644 tools/rsa-verify.c
create mode 100644 tools/sha256.cSignature · 1 line
1.8.3.1
PATCH v3 1/8 tools/image-host: fix sign-images bug
property "sign-images" is never found, fix this.
---
changes for v2:
- add Acked-by from Simon Glass
--- tools/image-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/image-host.c +1 -1
@@ -403,7 +403,7 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset, goto err_mem;/* Get a list of images that we intend to sign */ - prop =fit_config_get_image_list (fit, conf_noffset, &len, + prop =fit_config_get_image_list (fit, sig_offset, &len, &allow_missing);if (!prop)return 0 ;
Signature · 1 line
1.8.3.1
PATCH v3 1/8 tools/image-host: fix sign-images bug
Quoted 4 lines · Heiko Schocher
property "sign-images" is never found, fix this.
Signed-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/74bf3dc3/attachment.pgp>
PATCH v3 2/8 fdt: add "fdt checksign" command
In reply to Heiko Schochercheck if a fdt is correct signed
pass an optional addr value. Contains the addr of the key blob
---
changes vor v2:
- add comment from Simon Glass:
- rename "fdt sign" to "fdt checksign"
-> rename patch subject from "fdt: add "fdt sign" command"
to "fdt: add "fdt checksign" command"
- add error message
changes for v2:
add Acked-by from Simon Glass
--- common/cmd_fdt.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
common/cmd_fdt.c +41 -1
@@ -570,7 +570,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])ft_board_setup (working_fdt, gd->bd);#endif /* Create a chosen node */ - else if (argv[1][0] == 'c') { + else if (strncmp(argv[1], "cho", 3) == 0) { unsigned long initrd_start = 0, initrd_end = 0; if ((argc != 2) && (argc != 4))
@@ -583,6 +583,41 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])fdt_chosen (working_fdt,1 );fdt_initrd (working_fdt, initrd_start, initrd_end,1 ); + +#if defined(CONFIG_FIT_SIGNATURE ) + } else if (strncmp(argv[1], "che", 3) == 0) { +int cfg_noffset; +int ret; +unsigned long addr; +struct fdt_header *blob; + +if (!working_fdt) +return CMD_RET_FAILURE ; + +if (argc >2 ) { + addr =simple_strtoul (argv[2 ],NULL ,16 ); + blob =map_sysmem (addr,0 ); + }else { + blob = (struct fdt_header *)gd->fdt_blob; + } +if (!fdt_valid (&blob)) +return 1 ; + + gd->fdt_blob = blob; + cfg_noffset =fit_conf_get_node (working_fdt,NULL ); +if (!cfg_noffset) { +printf ("Could not find configuration node: %s\n" , +fdt_strerror (cfg_noffset)); +return CMD_RET_FAILURE ; + } + + ret =fit_config_verify (working_fdt, cfg_noffset); +if (ret ==1 ) +return CMD_RET_SUCCESS ; +else +return CMD_RET_FAILURE ; +#endif + }/* resize the fdt */ else if (strncmp (argv[1 ],"re" ,2 ) ==0 ) {
@@ -992,6 +1027,11 @@ static char fdt_help_text[] ="fdt rsvmem delete <index> - Delete a mem reserves\n" "fdt chosen [<start> <end>] - Add/update the /chosen branch in the tree\n" " <start>/<end> - initrd start/end addr\n" +#if defined(CONFIG_FIT_SIGNATURE ) +"fdt checksign [<addr>] - check FIT signature\n" +" <start> - addr of key blob\n" + " default gd->fdt_blob\n" +#endif "NOTE: Dereference aliases by omiting the leading '/', " "e.g. fdt print ethernet0." ;#endif
Signature · 1 line
1.8.3.1
PATCH v3 2/8 fdt: add "fdt checksign" command
Quoted 5 lines · Heiko Schocher
check if a fdt is correct signed
pass an optional addr value. Contains the addr of the key blobSigned-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/d9e750d4/attachment.pgp>
PATCH v3 3/8 fit: add sha256 support
In reply to Heiko Schocheradd sha256 support to fit images
---
changes for v2:
- add Acked-by from Simon Glass
changes for v3:
- add comment from Simon Glass:
- remove const attribute
- do not remove IMAGE_ENABLE_SHA256, as we have no
board config file when compiling mkimage for the
host
- rebased against current head eeb72e67619b98d2502fe634a3a5d9953de92ad0
-> Makefile adaptions necessary introduced from kbuild changes --- common/image-fit.c | 5 +++++ include/image.h | 9 +++++++++ lib/sha256.c | 5 +++-- tools/Makefile | 3 ++- tools/sha256.c | 1 + 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tools/sha256.c
common/image-fit.c +5 -0
@@ -22,6 +22,7 @@ DECLARE_GLOBAL_DATA_PTR;#include <bootstage.h> #include <sha1.h> +#include <sha256.h> #include <u-boot/crc.h> #include <u-boot/md5.h>
@@ -882,6 +883,10 @@ int calculate_hash(const void *data, int data_len, const char *algo,sha1_csum_wd ((unsigned char *)data, data_len, (unsigned char *)value,CHUNKSZ_SHA1 ); *value_len =20 ; + }else if (IMAGE_ENABLE_SHA256 &&strcmp (algo,"sha256" ) ==0 ) { +sha256_csum_wd ((unsigned char *)data, data_len, + (unsigned char *)value,CHUNKSZ_SHA256 ); + *value_len =SHA256_SUM_LEN ; }else if (IMAGE_ENABLE_MD5 &&strcmp (algo,"md5" ) ==0 ) {md5_wd ((unsigned char *)data, data_len, value,CHUNKSZ_MD5 ); *value_len =16 ;
include/image.h +9 -0
@@ -57,13 +57,18 @@ struct lmb;# ifdef CONFIG_SPL_SHA1_SUPPORT # define IMAGE_ENABLE_SHA1 1# endif +# ifdef CONFIG_SPL_SHA256_SUPPORT +# define IMAGE_ENABLE_SHA256 1 +# endif # else # define CONFIG_CRC32 /* FIT images need CRC32 support */ # define CONFIG_MD5 /* and MD5 */ # define CONFIG_SHA1 /* and SHA1 */ +# define CONFIG_SHA256 /* and SHA256 */ # define IMAGE_ENABLE_CRC32 1# define IMAGE_ENABLE_MD5 1# define IMAGE_ENABLE_SHA1 1 +# define IMAGE_ENABLE_SHA256 1# endif #ifndef IMAGE_ENABLE_CRC32
@@ -78,6 +83,10 @@ struct lmb;#define IMAGE_ENABLE_SHA1 0#endif +#ifndef IMAGE_ENABLE_SHA256 +#define IMAGE_ENABLE_SHA256 0 +#endif +#endif /* CONFIG_FIT */ #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
lib/sha256.c +3 -2
@@ -258,14 +258,15 @@ void sha256_csum_wd(const unsigned char *input, unsigned int ilen, {sha256_context ctx;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) -unsigned char *end, *curr; +const unsigned char *end; +unsigned char *curr;int chunk;#endif sha256_starts (&ctx);#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - curr = input; + curr = (unsigned char *)input; end = input + ilen;while (curr < end) { chunk = end - curr;
tools/Makefile +2 -1
@@ -40,7 +40,6 @@ CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y) # TODO: CONFIG_CMD_LICENSE does not work hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX) - hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX) hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX) HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic
@@ -85,6 +84,7 @@ dumpimage-mkimage-objs := aisimage.o \ os_support.o \ pblimage.o \ sha1.o \ + sha256.o \ ublimage.o \ $(LIBFDT_OBJS) \ $(RSA_OBJS-y)
@@ -137,6 +137,7 @@ hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX) HOSTCFLAGS_crc32.o := -pedantic HOSTCFLAGS_md5.o := -pedantic HOSTCFLAGS_sha1.o := -pedantic +HOSTCFLAGS_sha256.o := -pedantic # Don't build by default #hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX)
tools/sha256.c new file +1 -0
@@ -0,0 +1 @@ +#include "../lib/sha256.c"
Signature · 1 line
1.8.3.1
PATCH v3 3/8 fit: add sha256 support
Quoted 4 lines · Heiko Schocher
add sha256 support to fit images
Signed-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/a47daad8/attachment.pgp>
PATCH v3 4/8 rsa: add sha256-rsa2048 algorithm
In reply to Heiko Schocherbased on patch from andreas at oetken.name:
http://patchwork.ozlabs.org/patch/294318/
commit message:
I currently need support for rsa-sha256 signatures in u-boot and found out that the code for signatures is not very generic. Thus adding of different hash-algorithms for rsa-signatures is not easy to do without copy-pasting the rsa-code. I attached a patch for how I think it could be better and included support for rsa-sha256. This is a fast first shot.
aditionally work:
- removed checkpatch warnings
- removed compiler warnings
- rebased against current head
---
changes for v2:
- add comment from Simon Glass:
- add commit message from original patch
- remove unnecessary function declaration
rsa_verify_256()
- sandbox: add sha256 tests
changes for v3:
- add comment from Simon Glass:
- remove "#if defined(CONFIG_FIT_SIGNATURE)"
- remove "#if IMAGE_ENABLE_VERIFY"
- left-align the comments in struct rsa_public_key
- test without parameter, do sha1 and sha256 tests in one call
---
common/image-sig.c | 38 +++++++++
doc/uImage.FIT/signature.txt | 14 +++-
include/image.h | 21 +++++
include/rsa-checksum.h | 23 +++++
include/rsa.h | 14 ++++
lib/rsa/Makefile | 2 +-
lib/rsa/rsa-checksum.c | 98 ++++++++++++++++++++++
lib/rsa/rsa-sign.c | 10 ++-
lib/rsa/rsa-verify.c | 83 ++++++------------
.../{sign-configs.its => sign-configs-sha1.its} | 0
test/vboot/sign-configs-sha256.its | 45 ++++++++++
.../{sign-images.its => sign-images-sha1.its} | 0
test/vboot/sign-images-sha256.its | 42 ++++++++++
test/vboot/vboot_test.sh | 66 ++++++++-------
14 files changed, 363 insertions(+), 93 deletions(-)
create mode 100644 include/rsa-checksum.h
create mode 100644 lib/rsa/rsa-checksum.c
rename test/vboot/{sign-configs.its => sign-configs-sha1.its} (100%)
create mode 100644 test/vboot/sign-configs-sha256.its
rename test/vboot/{sign-images.its => sign-images-sha1.its} (100%)
create mode 100644 test/vboot/sign-images-sha256.itscommon/image-sig.c +38 -0
@@ -14,15 +14,53 @@ DECLARE_GLOBAL_DATA_PTR;#endif /* !USE_HOSTCC*/ #include <image.h> #include <rsa.h> +#include <rsa-checksum.h> #define IMAGE_MAX_HASHED_NODES 100 +#ifdef USE_HOSTCC +__attribute__((weak))void *get_blob (void ) +{ +return NULL ; +} +#endif + +struct checksum_algo checksum_algos[] = { + { +"sha1" , +SHA1_SUM_LEN , +#if IMAGE_ENABLE_SIGN + EVP_sha1, +#else + sha1_calculate, + padding_sha1_rsa2048, +#endif + }, + { +"sha256" , +SHA256_SUM_LEN , +#if IMAGE_ENABLE_SIGN + EVP_sha256, +#else + sha256_calculate, + padding_sha256_rsa2048, +#endif + } +};struct image_sig_algo image_sig_algos[] = { {"sha1,rsa2048" , rsa_sign, rsa_add_verify_data, rsa_verify, + &checksum_algos[0 ], + }, + { +"sha256,rsa2048" , + rsa_sign, + rsa_add_verify_data, + rsa_verify, + &checksum_algos[1 ], } };
doc/uImage.FIT/signature.txt +13 -1
@@ -346,7 +346,9 @@ Simple Verified Boot Test Please see doc/uImage.FIT/verified-boot.txt for more information +/home/hs/ids/u-boot/sandbox/tools/mkimage -D -I dts -O dtb -p 2000 Build keys +do sha1 test Build FIT with signed images Test Verified Boot Run: unsigned signatures:: OK Sign images
@@ -355,10 +357,20 @@ Build FIT with signed configuration Test Verified Boot Run: unsigned config: OK Sign images Test Verified Boot Run: signed config: OK +Test Verified Boot Run: signed config with bad hash: OK +do sha256 test +Build FIT with signed images +Test Verified Boot Run: unsigned signatures:: OK +Sign images +Test Verified Boot Run: signed images: OK +Build FIT with signed configuration +Test Verified Boot Run: unsigned config: OK +Sign images +Test Verified Boot Run: signed config: OK +Test Verified Boot Run: signed config with bad hash: OK Test passed - Future Work ----------- - Roll-back protection using a TPM is done using the tpm command. This can
include/image.h +21 -0
@@ -833,6 +833,7 @@ int calculate_hash(const void *data, int data_len, const char *algo,# ifdef USE_HOSTCC # define IMAGE_ENABLE_SIGN 1# define IMAGE_ENABLE_VERIFY 0 +# include <openssl/evp.h> #else # define IMAGE_ENABLE_SIGN 0# define IMAGE_ENABLE_VERIFY 1
@@ -872,6 +873,23 @@ struct image_region {int size; }; +#if IMAGE_ENABLE_VERIFY +# include <rsa-checksum.h> +#endif +struct checksum_algo { +const char *name; +const int checksum_len; +#if IMAGE_ENABLE_SIGN +const EVP_MD *(*calculate)(void ); +#else +#if IMAGE_ENABLE_VERIFY +void (*calculate)(const struct image_region region[], +int region_count,uint8_t *checksum); +const uint8_t *rsa_padding; +#endif +#endif +}; +struct image_sig_algo {const char *name;/* Name of algorithm */
@@ -922,6 +940,9 @@ struct image_sig_algo {int (*verify)(struct image_sign_info *info,const struct image_region region[],int region_count,uint8_t *sig,uint sig_len); + +/* pointer to checksum algorithm */ +struct checksum_algo *checksum; };/**
include/rsa-checksum.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (c) 2013, Andreas Oetken. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _RSA_CHECKSUM_H +#define _RSA_CHECKSUM_H + +#include <errno.h> +#include <image.h> +#include <sha1.h> +#include <sha256.h> + +extern const uint8_t padding_sha256_rsa2048[]; +extern const uint8_t padding_sha1_rsa2048[]; + +void sha256_calculate (const struct image_region region[],int region_count, +uint8_t *checksum); +void sha1_calculate (const struct image_region region[],int region_count, +uint8_t *checksum); + +#endif
include/rsa.h +14 -0
@@ -15,6 +15,20 @@#include <errno.h> #include <image.h> +/** +* struct rsa_public_key - holder for a public key +* +* An RSA public key consists of a modulus (typically called N), the inverse +* and R^2, where R is 2^(# key bits). +*/ + +struct rsa_public_key { +uint len;/* len of modulus[] in number of uint32_t */ +uint32_t n0inv;/* -1 / modulus[0] mod 2^32 */ +uint32_t *modulus;/* modulus as little endian array */ +uint32_t *rr;/* R^2 as little endian array */ +}; +#if IMAGE_ENABLE_SIGN /** * sign() - calculate and return signature for given input data
lib/rsa/Makefile +1 -1
@@ -7,4 +7,4 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o +obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o
lib/rsa/rsa-checksum.c new file +98 -0
98 lines not on this page · raw message
lib/rsa/rsa-sign.c +6 -4
@@ -159,8 +159,9 @@ static void rsa_remove(void)EVP_cleanup (); } -static int rsa_sign_with_key (RSA *rsa,const struct image_region region[], -int region_count,uint8_t **sigp,uint *sig_size) +static int rsa_sign_with_key (RSA *rsa,struct checksum_algo *checksum_algo, +const struct image_region region[],int region_count, +uint8_t **sigp,uint *sig_size) {EVP_PKEY *key;EVP_MD_CTX *context;
@@ -192,7 +193,7 @@ static int rsa_sign_with_key(RSA *rsa, const struct image_region region[], goto err_create; }EVP_MD_CTX_init (context); -if (!EVP_SignInit (context,EVP_sha1 ())) { +if (!EVP_SignInit (context, checksum_algo->calculate ())) { ret =rsa_err ("Signer setup failed" ); goto err_sign; }
@@ -242,7 +243,8 @@ int rsa_sign(struct image_sign_info *info, ret =rsa_get_priv_key (info->keydir, info->keyname, &rsa);if (ret) goto err_priv; - ret =rsa_sign_with_key (rsa, region, region_count, sigp, sig_len); + ret =rsa_sign_with_key (rsa, info->algo->checksum, region, + region_count, sigp, sig_len);if (ret) goto err_sign;
lib/rsa/rsa-verify.c +24 -59
143 lines not on this page · raw message
test/vboot/sign-configs-sha1.its renamed from test/vboot/sign-configs.its +0 -0
test/vboot/sign-configs-sha256.its new file +45 -0
45 lines not on this page · raw message
test/vboot/sign-images-sha1.its renamed from test/vboot/sign-images.its +0 -0
test/vboot/sign-images-sha256.its new file +42 -0
42 lines not on this page · raw message
test/vboot/vboot_test.sh +38 -28
85 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 4/8 rsa: add sha256-rsa2048 algorithm
Hi Heiko,
Quoted 10 lines · Heiko Schocher
based on patch from andreas at oetken.name:
http://patchwork.ozlabs.org/patch/294318/
commit message:
I currently need support for rsa-sha256 signatures in u-boot and found out that the code for signatures is not very generic. Thus adding of different hash-algorithms for rsa-signatures is not easy to do without copy-pasting the rsa-code. I attached a patch for how I think it could be better and included support for rsa-sha256. This is a fast first shot.
Quoted 8 lines
aditionally work:
- removed checkpatch warnings
- removed compiler warnings
- rebased against current headSigned-off-by Heiko Schocher <[email protected]>Cc andreas at oetken.nameCc Simon Glass <[email protected]>
This looks good to me. However, when running it I hit this crash?
O=b/sandbox test/vboot/vboot_test.sh Simple Verified Boot Test
=========================
Please see doc/uImage.FIT/verified-boot.txt for more information
/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/mkimage -D -I dts -O dtb -p 2000
Build keys
do sha1 test
Build FIT with signed images
Test Verified Boot Run: unsigned signatures:: OK
Sign images
Test Verified Boot Run: signed images: OK
Build FIT with signed configuration
Test Verified Boot Run: unsigned config: OK
Sign images
Test Verified Boot Run: signed config: OK
check signed config on the host
*** buffer overflow detected ***:/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign terminated
======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f07c7ba9f47] /lib/x86_64-linux-gnu/libc.so.6(+0x109e40)[0x7f07c7ba8e40] /home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign[0x40226f] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f07c7ac076d] /home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign[0x4023c5] ======= Memory map: ========
00400000-0041a000 r-xp 00000000 fc:01 9840801
/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign
00619000-0061a000 r--p 00019000 fc:01 9840801
/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign
0061a000-0061b000 rw-p 0001a000 fc:01 9840801
/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_sign
0061b000-00711000 rw-p 00000000 00:00 0
00c24000-00c45000 rw-p 00000000 00:00 0 [heap]
7f07c746e000-7f07c7483000 r-xp 00000000 fc:01 2622892
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f07c7483000-7f07c7682000 ---p 00015000 fc:01 2622892
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f07c7682000-7f07c7683000 r--p 00014000 fc:01 2622892
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f07c7683000-7f07c7684000 rw-p 00015000 fc:01 2622892
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f07c7684000-7f07c769a000 r-xp 00000000 fc:01 2622826
/lib/x86_64-linux-gnu/libz.so.1.2.3.4
7f07c769a000-7f07c7899000 ---p 00016000 fc:01 2622826
/lib/x86_64-linux-gnu/libz.so.1.2.3.4
7f07c7899000-7f07c789a000 r--p 00015000 fc:01 2622826
/lib/x86_64-linux-gnu/libz.so.1.2.3.4
7f07c789a000-7f07c789b000 rw-p 00016000 fc:01 2622826
/lib/x86_64-linux-gnu/libz.so.1.2.3.4
7f07c789b000-7f07c789d000 r-xp 00000000 fc:01 2622044
/lib/x86_64-linux-gnu/libdl-2.15.so
7f07c789d000-7f07c7a9d000 ---p 00002000 fc:01 2622044
/lib/x86_64-linux-gnu/libdl-2.15.so
7f07c7a9d000-7f07c7a9e000 r--p 00002000 fc:01 2622044
/lib/x86_64-linux-gnu/libdl-2.15.so
7f07c7a9e000-7f07c7a9f000 rw-p 00003000 fc:01 2622044
/lib/x86_64-linux-gnu/libdl-2.15.so
7f07c7a9f000-7f07c7c54000 r-xp 00000000 fc:01 2622027
/lib/x86_64-linux-gnu/libc-2.15.so
7f07c7c54000-7f07c7e54000 ---p 001b5000 fc:01 2622027
/lib/x86_64-linux-gnu/libc-2.15.so
7f07c7e54000-7f07c7e58000 r--p 001b5000 fc:01 2622027
/lib/x86_64-linux-gnu/libc-2.15.so
7f07c7e58000-7f07c7e5a000 rw-p 001b9000 fc:01 2622027
/lib/x86_64-linux-gnu/libc-2.15.so
7f07c7e5a000-7f07c7e5f000 rw-p 00000000 00:00 0 7f07c7e5f000-7f07c8010000 r-xp 00000000 fc:01 2640614
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f07c8010000-7f07c8210000 ---p 001b1000 fc:01 2640614
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f07c8210000-7f07c822b000 r--p 001b1000 fc:01 2640614
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f07c822b000-7f07c8236000 rw-p 001cc000 fc:01 2640614
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f07c8236000-7f07c823a000 rw-p 00000000 00:00 0 7f07c823a000-7f07c828e000 r-xp 00000000 fc:01 2640615
/lib/x86_64-linux-gnu/libssl.so.1.0.0
7f07c828e000-7f07c848e000 ---p 00054000 fc:01 2640615
/lib/x86_64-linux-gnu/libssl.so.1.0.0
7f07c848e000-7f07c8491000 r--p 00054000 fc:01 2640615
/lib/x86_64-linux-gnu/libssl.so.1.0.0
7f07c8491000-7f07c8497000 rw-p 00057000 fc:01 2640615
/lib/x86_64-linux-gnu/libssl.so.1.0.0
7f07c8497000-7f07c8498000 rw-p 00000000 00:00 0 7f07c8498000-7f07c84ba000 r-xp 00000000 fc:01 2622041
/lib/x86_64-linux-gnu/ld-2.15.so
7f07c869f000-7f07c86a3000 rw-p 00000000 00:00 0 7f07c86b7000-7f07c86ba000 rw-p 00000000 00:00 0 7f07c86ba000-7f07c86bb000 r--p 00022000 fc:01 2622041
/lib/x86_64-linux-gnu/ld-2.15.so
7f07c86bb000-7f07c86bd000 rw-p 00023000 fc:01 2622041
/lib/x86_64-linux-gnu/ld-2.15.so
7fff08a47000-7fff08a68000 rw-p 00000000 00:00 0 [stack]
7fff08ad7000-7fff08ad9000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
[vsyscall]test/vboot/vboot_test.sh: line 65: 7597 Aborted (core
dumped) ${fit_check_sign} -f test.fit -k sandbox-u-boot.dtb > ${tmp}
Verified boot key check on host failed, output follows:
Do you see this? Presumably not - I can dig a bit if you like?
Regards,
Simon
PATCH v3 4/8 rsa: add sha256-rsa2048 algorithm
Hello Simon,
Am 09.03.2014 06:33, schrieb Simon Glass:
Quoted 49 lines
Hi Heiko,
Quoted 10 lines · Heiko Schocher
based on patch from andreas at oetken.name:
http://patchwork.ozlabs.org/patch/294318/
commit message:
I currently need support for rsa-sha256 signatures in u-boot and found out that the code for signatures is not very generic. Thus adding of different hash-algorithms for rsa-signatures is not easy to do without copy-pasting the rsa-code. I attached a patch for how I think it could be better and included support for rsa-sha256. This is a fast first shot.Quoted 8 lines
aditionally work:
- removed checkpatch warnings
- removed compiler warnings
- rebased against current headSigned-off-by Heiko Schocher<[email protected]>Cc andreas at oetken.nameCc Simon Glass<[email protected]>This looks good to me. However, when running it I hit this crash?
O=b/sandbox
test/vboot/vboot_test.shSimple Verified Boot Test
=========================Please see
doc/uImage.FIT/verified-boot.txtfor more information
/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/mkimage-D -I dts -O dtb -p 2000
Build keys
do sha1 test
Build FIT with signed images
Test Verified Boot Run: unsigned signatures:: OK
Sign images
Test Verified Boot Run: signed images: OK
Build FIT with signed configuration
Test Verified Boot Run: unsigned config: OK
Sign images
Test Verified Boot Run: signed config: OK
check signed config on the host
*** buffer overflow detected ***:/home/sjg/c/src/third_party/u-boot/files/b/sandbox/tools/fit_check_signterminated
======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f07c7ba9f47] /lib/x86_64-linux-gnu/libc.so.6(+0x109e40)[0x7f07c7ba8e40]
[...]
Quoted 8 lines
[vsyscall]
test/vboot/vboot_test.sh: line 65: 7597 Aborted (core
dumped) ${fit_check_sign} -f test.fit -k sandbox-u-boot.dtb> ${tmp}Verified boot key check on host failed, output follows:
Do you see this? Presumably not - I can dig a bit if you like?
No, I do not see this crash ... Hmm... you reply this error to the 4/8 patch of this series, but "fit_check_sign" is introduced in the 8/8 ... did you tried with all 8 patches applied?
Just tested with current head of U-Boot and I see no error:
commit 247161b8160fc699b0a517f081220bb50bc502a8
Merge: d57d60c 96ac18c
Author: Tom Rini <[email protected]>
Date: Fri Mar 7 20:54:22 2014 -0500
Merge branch 'master' of git://git.denx.de/u-boot-mpc85xx
$ O=sandbox ./test/vboot/vboot_test.sh Simple Verified Boot Test =========================
Please see doc/uImage.FIT/verified-boot.txt for more information
/home/hs/ids/u-boot/sandbox/tools/mkimage -D -I dts -O dtb -p 2000 Build keys
do sha1 test
Build FIT with signed images
Test Verified Boot Run: unsigned signatures:: OK
Sign images
Test Verified Boot Run: signed images: OK
Build FIT with signed configuration
Test Verified Boot Run: unsigned config: OK
Sign images
Test Verified Boot Run: signed config: OK
check signed config on the host
OK
Test Verified Boot Run: signed config: OK
Test Verified Boot Run: signed config with bad hash: OK do sha256 test
Build FIT with signed images
Test Verified Boot Run: unsigned signatures:: OK
Sign images
Test Verified Boot Run: signed images: OK
Build FIT with signed configuration
Test Verified Boot Run: unsigned config: OK
Sign images
Test Verified Boot Run: signed config: OK
check signed config on the host
OK
Test Verified Boot Run: signed config: OK
Test Verified Boot Run: signed config with bad hash: OK
Test passed
pollux:u-boot hs [temp] $
Can you try with current head again?
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH v3 4/8 rsa: add sha256-rsa2048 algorithm
In reply to Heiko SchocherQuoted 10 lines · Heiko Schocher
based on patch from andreas at oetken.name:
http://patchwork.ozlabs.org/patch/294318/
commit message:
I currently need support for rsa-sha256 signatures in u-boot and found out that the code for signatures is not very generic. Thus adding of different hash-algorithms for rsa-signatures is not easy to do without copy-pasting the rsa-code. I attached a patch for how I think it could be better and included support for rsa-sha256. This is a fast first shot.
Quoted 8 lines
aditionally work:
- removed checkpatch warnings
- removed compiler warnings
- rebased against current headSigned-off-by Heiko Schocher <[email protected]>Cc andreas at oetken.nameCc Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/8fe628f3/attachment.pgp>
PATCH v3 5/8 rsa: add sha256,rsa4096 algorithm
In reply to Heiko SchocherAdd support for sha256,rsa4096 signatures in u-boot.
---
changes for v2:
- add comment from Simon Glass:
- add a commit message
changes for v3:
add Acked-by from Simon Glass
--- common/image-sig.c | 23 ++++++++++++++++++ include/image.h | 1 + include/rsa-checksum.h | 1 + include/rsa.h | 10 ++++++++ lib/rsa/rsa-checksum.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-- lib/rsa/rsa-verify.c | 20 +++++----------- 6 files changed, 104 insertions(+), 16 deletions(-)
common/image-sig.c +23 -0
@@ -29,6 +29,7 @@ struct checksum_algo checksum_algos[] = { {"sha1" ,SHA1_SUM_LEN , +RSA2048_BYTES , #if IMAGE_ENABLE_SIGN EVP_sha1, #else
@@ -39,14 +40,28 @@ struct checksum_algo checksum_algos[] = { { "sha256", SHA256_SUM_LEN, + RSA2048_BYTES, #if IMAGE_ENABLE_SIGN EVP_sha256, #else sha256_calculate, padding_sha256_rsa2048, #endif + }, + { + "sha256", + SHA256_SUM_LEN, + RSA4096_BYTES, +#if IMAGE_ENABLE_SIGN + EVP_sha256, +#else + sha256_calculate, + padding_sha256_rsa4096, +#endif } + }; + struct image_sig_algo image_sig_algos[] = { { "sha1,rsa2048",
@@ -61,7 +76,15 @@ struct image_sig_algo image_sig_algos[] = { rsa_add_verify_data, rsa_verify, &checksum_algos[1], + }, + { + "sha256,rsa4096", + rsa_sign, + rsa_add_verify_data, + rsa_verify, + &checksum_algos[2], } + };struct image_sig_algo *image_get_sig_algo (const char *name)
include/image.h +1 -0
@@ -879,6 +879,7 @@ struct image_region {struct checksum_algo {const char *name;const int checksum_len; +const int pad_len;#if IMAGE_ENABLE_SIGN const EVP_MD *(*calculate)(void );#else
include/rsa-checksum.h +1 -0
@@ -12,6 +12,7 @@#include <sha1.h> #include <sha256.h> +extern const uint8_t padding_sha256_rsa4096[];extern const uint8_t padding_sha256_rsa2048[];extern const uint8_t padding_sha1_rsa2048[];
include/rsa.h +10 -0
@@ -103,4 +103,14 @@ static inline int rsa_verify(struct image_sign_info *info, }#endif +#define RSA2048_BYTES (2048 / 8) +#define RSA4096_BYTES (4096 / 8) + +/* This is the minimum/maximum key size we support, in bits */ +#define RSA_MIN_KEY_BITS 2048 +#define RSA_MAX_KEY_BITS 4096 + +/* This is the maximum signature length that we support, in bits */ +#define RSA_MAX_SIG_BITS 4096 +#endif
lib/rsa/rsa-checksum.c +63 -2
77 lines not on this page · raw message
lib/rsa/rsa-verify.c +6 -14
@@ -15,15 +15,6 @@#define UINT64_MULT32 (v, multby) (((uint64_t)(v)) * ((uint32_t)(multby))) -#define RSA2048_BYTES (2048 / 8) - -/* This is the minimum/maximum key size we support, in bits */ -#define RSA_MIN_KEY_BITS 2048 -#define RSA_MAX_KEY_BITS 2048 - -/* This is the maximum signature length that we support, in bits */ -#define RSA_MAX_SIG_BITS 2048 -/** * subtract_modulus() - subtract modulus from the given value *
@@ -197,7 +188,7 @@ static int rsa_verify_key(const struct rsa_public_key *key, const uint8_t *sig,return ret; padding = algo->rsa_padding; - pad_len =RSA2048_BYTES - algo->checksum_len; + pad_len = algo->pad_len - algo->checksum_len;/* Check pkcs1.5 padding bytes. */ if (memcmp (buf, padding, pad_len)) {
@@ -281,7 +272,7 @@ int rsa_verify(struct image_sign_info *info, {const void *blob = info->fdt_blob;/* Reserve memory for maximum checksum-length */ -uint8_t hash[RSA2048_BYTES ]; +uint8_t hash[info->algo->checksum->pad_len];int ndepth, noffset;int sig_node, node;char name[100 ];
@@ -291,9 +282,10 @@ int rsa_verify(struct image_sign_info *info,* Verify that the checksum-length does not exceed the * rsa-signature-length */ -if (info->algo->checksum->checksum_len >RSA2048_BYTES ) { -debug ("%s: invlaid checksum-algorithm %s for RSA2048\n" , - __func__, info->algo->checksum->name); +if (info->algo->checksum->checksum_len > + info->algo->checksum->pad_len) { +debug ("%s: invlaid checksum-algorithm %s for %s\n" , + __func__, info->algo->checksum->name, info->algo->name);return -EINVAL ; }
Signature · 1 line
1.8.3.1
PATCH v3 5/8 rsa: add sha256,rsa4096 algorithm
Quoted 5 lines · Heiko Schocher
Add support for sha256,rsa4096 signatures in u-boot.
Signed-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>Cc andreas at oetken.name
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/ad463857/attachment.pgp>
PATCH v3 6/8 gen: Add progressive hash API
In reply to Heiko SchocherFrom: Hung-ying Tyan <[email protected]>
Add hash_init(), hash_update() and hash_finish() to the hash_algo struct. Add hash_lookup_algo() to look up the struct given an algorithm name.
---
changes for v2:
- new in v2
changes for v3:
add Acked-by from Simon Glass
--- common/hash.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++------ include/hash.h | 48 ++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 11 deletions(-)
common/hash.c +105 -11
@@ -12,6 +12,7 @@#include <common.h> #include <command.h> +#include <malloc.h> #include <hw_sha.h> #include <hash.h> #include <sha1.h>
@@ -19,6 +20,88 @@#include <asm/io.h> #include <asm/errno.h> +#ifdef CONFIG_CMD_SHA1SUM +static int hash_init_sha1 (struct hash_algo *algo,void **ctxp) +{ +sha1_context *ctx =malloc (sizeof (sha1_context)); +sha1_starts (ctx); + *ctxp = ctx; +return 0 ; +} + +static int hash_update_sha1 (struct hash_algo *algo,void *ctx,const void *buf, +unsigned int size,int is_last) +{ +sha1_update ((sha1_context *)ctx, buf, size); +return 0 ; +} + +static int hash_finish_sha1 (struct hash_algo *algo,void *ctx,void *dest_buf, +int size) +{ +if (size < algo->digest_size) +return -1 ; + +sha1_finish ((sha1_context *)ctx, dest_buf); +free (ctx); +return 0 ; +} +#endif + +#ifdef CONFIG_SHA256 +static int hash_init_sha256 (struct hash_algo *algo,void **ctxp) +{ +sha256_context *ctx =malloc (sizeof (sha256_context)); +sha256_starts (ctx); + *ctxp = ctx; +return 0 ; +} + +static int hash_update_sha256 (struct hash_algo *algo,void *ctx, +const void *buf,unsigned int size,int is_last) +{ +sha256_update ((sha256_context *)ctx, buf, size); +return 0 ; +} + +static int hash_finish_sha256 (struct hash_algo *algo,void *ctx,void + *dest_buf,int size) +{ +if (size < algo->digest_size) +return -1 ; + +sha256_finish ((sha256_context *)ctx, dest_buf); +free (ctx); +return 0 ; +} +#endif + +static int hash_init_crc32 (struct hash_algo *algo,void **ctxp) +{ +uint32_t *ctx =malloc (sizeof (uint32_t )); + *ctx =0 ; + *ctxp = ctx; +return 0 ; +} + +static int hash_update_crc32 (struct hash_algo *algo,void *ctx, +const void *buf,unsigned int size,int is_last) +{ + *((uint32_t *)ctx) =crc32 (*((uint32_t *)ctx), buf, size); +return 0 ; +} + +static int hash_finish_crc32 (struct hash_algo *algo,void *ctx,void *dest_buf, +int size) +{ +if (size < algo->digest_size) +return -1 ; + + *((uint32_t *)dest_buf) = *((uint32_t *)ctx); +free (ctx); +return 0 ; +} +/* * These are the hash algorithms we support. Chips which support accelerated * crypto could perhaps add named version of these algorithms here. Note that
@@ -53,6 +136,9 @@ static struct hash_algo hash_algo[] = {SHA1_SUM_LEN , sha1_csum_wd,CHUNKSZ_SHA1 , + hash_init_sha1, + hash_update_sha1, + hash_finish_sha1, }, #define MULTI_HASH#endif
@@ -62,6 +148,9 @@ static struct hash_algo hash_algo[] = {SHA256_SUM_LEN , sha256_csum_wd,CHUNKSZ_SHA256 , + hash_init_sha256, + hash_update_sha256, + hash_finish_sha256, }, #define MULTI_HASH#endif
@@ -70,6 +159,9 @@ static struct hash_algo hash_algo[] = { 4, crc32_wd_buf,CHUNKSZ_CRC32 , + hash_init_crc32, + hash_update_crc32, + hash_finish_crc32, }, };
@@ -204,16 +296,19 @@ static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum,return 0 ; } -static struct hash_algo *find_hash_algo (const char *name) +int hash_lookup_algo (const char *algo_name,struct hash_algo **algop) {int i;for (i =0 ; i <ARRAY_SIZE (hash_algo); i++) { -if (!strcmp (name, hash_algo[i].name)) -return &hash_algo[i]; +if (!strcmp (algo_name, hash_algo[i].name)) { + *algop = &hash_algo[i]; +return 0 ; + } } -return NULL ; +debug ("Unknown hash algorithm '%s'\n" , algo_name); +return -EPROTONOSUPPORT ; } static void show_hash(struct hash_algo *algo, ulong addr, ulong len,
@@ -230,12 +325,12 @@ int hash_block(const char *algo_name, const void *data, unsigned int len, uint8_t *output, int *output_size) { struct hash_algo *algo; +int ret; + + ret =hash_lookup_algo (algo_name, &algo); +if (ret) +return ret; - algo =find_hash_algo (algo_name); -if (!algo) { -debug ("Unknown hash algorithm '%s'\n" , algo_name); -return -EPROTONOSUPPORT ; - }if (output_size && *output_size < algo->digest_size) {debug ("Output buffer size %d too small (need %d bytes)" , *output_size, algo->digest_size);
@@ -265,8 +360,7 @@ int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,u8 vsum[HASH_MAX_DIGEST_SIZE ];void *buf; - algo =find_hash_algo (algo_name); -if (!algo) { +if (hash_lookup_algo (algo_name, &algo)) {printf ("Unknown hash algorithm '%s'\n" , algo_name);return CMD_RET_USAGE ; }
include/hash.h +48 -0
58 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 6/8 gen: Add progressive hash API
Quoted 10 lines · Heiko Schocher
From: Hung-ying Tyan <[email protected]>
Add
hash_init(),hash_update()andhash_finish()to thehash_algostruct. Addhash_lookup_algo()to look up the struct given an algorithm name.Signed-off-by Hung-ying Tyan <[email protected]>Signed-off-by Simon Glass <[email protected]>Signed-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/a05ac8d8/attachment.pgp>
PATCH v3 7/8 tools, fit: add fit_info host command
In reply to Heiko Schocheradd fit_info command to the host tools. This command prints the name, offset and the len from a property from a node in a fit file. This info can be used to extract a properties data with linux tools, for example "dd".
---
- no changes for v2
- changes for v3:
- add comment from Marek Vasut:
- do not call unlink() unconditionally
- set errno = 0 and check errno after mmap() call
- add comment from Simon Glass:
- remove get_blob, as it is not needed
- use getopt
- rebased against current head eeb72e67619b98d2502fe634a3a5d9953de92ad0
-> Makefile adaptions necessary introduced from kbuild changes --- tools/.gitignore | 1 + tools/Makefile | 8 +++++ tools/fit_common.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/fit_common.h | 22 +++++++++++++ tools/fit_image.c | 62 +++-------------------------------- tools/fit_info.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 217 insertions(+), 58 deletions(-) create mode 100644 tools/fit_common.c create mode 100644 tools/fit_common.h create mode 100644 tools/fit_info.c
tools/.gitignore +1 -0
@@ -1,5 +1,6 @@ /bmp_logo /envcrc +/fit_info /gen_eth_addr /img2srec /kwboot
tools/Makefile +8 -0
@@ -60,6 +60,9 @@ hostprogs-y += mkenvimage$(SFX) mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o hostprogs-y += dumpimage$(SFX) mkimage$(SFX) +ifdef CONFIG_FIT_SIGNATURE +hostprogs-y += fit_info$(SFX) +endif FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o # Flattened device tree objects
@@ -71,6 +74,8 @@ dumpimage-mkimage-objs := aisimage.o \ $(FIT_SIG_OBJS-y) \ crc32.o \ default_image.o \ + fdtdec.o \ + fit_common.o \ fit_image.o \ image-fit.o \ image-host.o \
@@ -91,6 +96,7 @@ dumpimage-mkimage-objs := aisimage.o \ dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o +fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o # TODO(sjg at chromium.org): Is this correct on Mac OS?
@@ -98,6 +104,7 @@ mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto +HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
@@ -106,6 +113,7 @@ endif ifdef CONFIG_FIT_SIGNATURE HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto +HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto # This affects include/image.h, but including the board config file # is tricky, so manually define this options here.
tools/fit_common.c new file +86 -0
86 lines not on this page · raw message
tools/fit_common.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* (C) Copyright 2014 +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _FIT_COMMON_H_ +#define _FIT_COMMON_H_ + +#include "imagetool.h" +#include "mkimage.h" +#include <image.h> + +int fit_verify_header (unsigned char *ptr,int image_size, +struct image_tool_params *params); + +int fit_check_image_types (uint8_t type); + +int mmap_fdt (char *cmdname,const char *fname,void **blobp, +struct stat *sbuf,int useunlink); + +#endif /* _FIT_COMMON_H_ */
tools/fit_image.c +4 -58
85 lines not on this page · raw message
tools/fit_info.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 7/8 tools, fit: add fit_info host command
Hi Heiko,
Quoted 3 lines · Heiko Schocher
add
fit_infocommand to the host tools. This command prints the name, offset and the len from a property from a node in a fit file. This info can be used to extract a properties
property's I think?
Quoted 3 lines
data with linux tools, for example "dd".
Signed-off-by Heiko Schocher <[email protected]>
Seems OK to me. Note that there is an fdtget utility available which can sort-of do this - it is part of the dtc package. However I don't think it has an option to extract data in binary form (the -ts option may work but I'm not sure).
I don't understand the mmap() errno thing that Marek mentions, but it can do no harm.
Regards,
Simon
PATCH v3 7/8 tools, fit: add fit_info host command
In reply to Heiko SchocherQuoted 7 lines · Heiko Schocher
add
fit_infocommand to the host tools. This command prints the name, offset and the len from a property from a node in a fit file. This info can be used to extract a properties data with linux tools, for example "dd".Signed-off-by Heiko Schocher <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/ab68cd1a/attachment.pgp>
PATCH v3 8/8 tools, fit_check_sign: verify a signed fit image
In reply to Heiko Schocheradd host tool "fit_check_sign" which verifies, if a fit image is signed correct.
---
- changes for v2:
- fixed compile error for sandbox
- add fit_check_sign test to test/vboot/vboot_test.sh
- changes for v3:
- add comment from Marek Vasut:
- do not use unlink
- add comment from Simon Glass:
- get_blob not weak, rename it to image_get_host_blob()
- use getopt
- as we not write the file, get rid of some unneccessary checks
- move fdtdec_get_int() from lib/libfdt/fdt_wip.c to lib/fdtdec.c for HOSTCC compiles
- rebased against current head eeb72e67619b98d2502fe634a3a5d9953de92ad0
-> Makefile adaptions necessary introduced from kbuild changes --- common/image-sig.c | 18 +++++----- doc/uImage.FIT/signature.txt | 6 ++++ include/fdt_support.h | 5 +++ include/image.h | 17 +++++---- lib/fdtdec.c | 20 +++++++++++ lib/rsa/rsa-checksum.c | 10 ++++-- lib/rsa/rsa-sign.c | 2 +- lib/rsa/rsa-verify.c | 18 +++++++--- test/vboot/vboot_test.sh | 20 +++++++++++ tools/.gitignore | 1 + tools/Makefile | 7 ++-- tools/fdt_host.h | 2 ++ tools/fdtdec.c | 1 + tools/fit_check_sign.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ tools/image-host.c | 15 ++++++++ tools/rsa-checksum.c | 1 + tools/rsa-verify.c | 1 + 17 files changed, 204 insertions(+), 25 deletions(-) create mode 100644 tools/fdtdec.c create mode 100644 tools/fit_check_sign.c create mode 100644 tools/rsa-checksum.c create mode 100644 tools/rsa-verify.c
common/image-sig.c +10 -8
@@ -19,9 +19,14 @@ DECLARE_GLOBAL_DATA_PTR;#define IMAGE_MAX_HASHED_NODES 100#ifdef USE_HOSTCC -__attribute__((weak))void *get_blob (void ) +void *host_blob; +void image_set_host_blob (void *blob) { -return NULL ; + host_blob = blob; +} +void *image_get_host_blob (void ) +{ +return host_blob; }#endif
@@ -32,10 +37,9 @@ struct checksum_algo checksum_algos[] = { RSA2048_BYTES, #if IMAGE_ENABLE_SIGN EVP_sha1, -#else +#endif sha1_calculate, padding_sha1_rsa2048, -#endif }, { "sha256",
@@ -43,10 +47,9 @@ struct checksum_algo checksum_algos[] = { RSA2048_BYTES, #if IMAGE_ENABLE_SIGN EVP_sha256, -#else +#endif sha256_calculate, padding_sha256_rsa2048, -#endif }, { "sha256",
@@ -54,10 +57,9 @@ struct checksum_algo checksum_algos[] = { RSA4096_BYTES,#if IMAGE_ENABLE_SIGN EVP_sha256, -#else +#endif sha256_calculate, padding_sha256_rsa4096, -#endif } };
doc/uImage.FIT/signature.txt +6 -0
@@ -357,6 +357,9 @@ Build FIT with signed configuration Test Verified Boot Run: unsigned config: OK Sign images Test Verified Boot Run: signed config: OK +check signed config on the host +OK +Test Verified Boot Run: signed config: OK Test Verified Boot Run: signed config with bad hash: OK do sha256 test Build FIT with signed images
@@ -367,6 +370,9 @@ Build FIT with signed configuration Test Verified Boot Run: unsigned config: OK Sign images Test Verified Boot Run: signed config: OK +check signed config on the host +OK +Test Verified Boot Run: signed config: OK Test Verified Boot Run: signed config with bad hash: OK Test passed
include/fdt_support.h +5 -0
@@ -115,4 +115,9 @@ static inline int fdt_status_disabled_by_alias(void *fdt, const char* alias) }#endif /* ifdef CONFIG_OF_LIBFDT */ + +#ifdef USE_HOSTCC +int fdtdec_get_int (const void *blob,int node,const char *prop_name, +int default_val); +#endif #endif /* ifndef __FDT_SUPPORT_H */
include/image.h +10 -7
@@ -832,7 +832,7 @@ int calculate_hash(const void *data, int data_len, const char *algo,#if defined(CONFIG_FIT_SIGNATURE )# ifdef USE_HOSTCC # define IMAGE_ENABLE_SIGN 1 -# define IMAGE_ENABLE_VERIFY 0 +# define IMAGE_ENABLE_VERIFY 1# include <openssl/evp.h> #else # define IMAGE_ENABLE_SIGN 0
@@ -844,7 +844,9 @@ int calculate_hash(const void *data, int data_len, const char *algo,#endif #ifdef USE_HOSTCC -# define gd_fdt_blob () NULL +void *image_get_host_blob (void ); +void image_set_host_blob (void *host_blob); +# define gd_fdt_blob () image_get_host_blob()#else # define gd_fdt_blob () (gd->fdt_blob)#endif
@@ -881,14 +883,11 @@ struct checksum_algo {const int checksum_len;const int pad_len;#if IMAGE_ENABLE_SIGN -const EVP_MD *(*calculate)(void ); -#else -#if IMAGE_ENABLE_VERIFY +const EVP_MD *(*calculate_sign)(void ); +#endif void (*calculate)(const struct image_region region[],int region_count,uint8_t *checksum);const uint8_t *rsa_padding; -#endif -#endif };struct image_sig_algo {
@@ -1009,7 +1008,11 @@ struct image_region *fit_region_make_list(const void *fit,static inline int fit_image_check_target_arch (const void *fdt,int node) { +#ifndef USE_HOSTCC return fit_image_check_arch (fdt, node,IH_ARCH_DEFAULT ); +#else +return 0 ; +#endif }#ifdef CONFIG_FIT_VERBOSE
lib/fdtdec.c +20 -0
@@ -3,6 +3,7 @@* SPDX-License-Identifier: GPL-2.0+ */ +#ifndef USE_HOSTCC #include <common.h> #include <serial.h> #include <libfdt.h>
@@ -617,3 +618,22 @@ int fdtdec_decode_region(const void *blob, int node,debug ("%s: size=%zx\n" , __func__, *size); return 0; } +#else +#include "libfdt.h" +#include "fdt_support.h" + +int fdtdec_get_int (const void *blob,int node,const char *prop_name, +int default_val) +{ +const int *cell; +int len; + + cell =fdt_getprop_w ((void *)blob, node, prop_name, &len); +if (cell && len >=sizeof (int )) { +int val =fdt32_to_cpu (cell[0 ]); + +return val; + } +return default_val; +} +#endif
lib/rsa/rsa-checksum.c +7 -3
@@ -4,14 +4,18 @@* SPDX-License-Identifier: GPL-2.0+ */ +#ifndef USE_HOSTCC #include <common.h> #include <fdtdec.h> -#include <rsa.h> -#include <sha1.h> -#include <sha256.h> #include <asm/byteorder.h> #include <asm/errno.h> #include <asm/unaligned.h> +#else +#include "fdt_host.h" +#endif +#include <rsa.h> +#include <sha1.h> +#include <sha256.h> /* PKCS 1.5 paddings as described in the RSA PKCS#1 v2.1 standard. */
lib/rsa/rsa-sign.c +1 -1
@@ -193,7 +193,7 @@ static int rsa_sign_with_key(RSA *rsa, struct checksum_algo *checksum_algo, goto err_create; }EVP_MD_CTX_init (context); -if (!EVP_SignInit (context, checksum_algo->calculate ())) { +if (!EVP_SignInit (context, checksum_algo->calculate_sign ())) { ret =rsa_err ("Signer setup failed" ); goto err_sign; }
lib/rsa/rsa-verify.c +14 -4
@@ -4,17 +4,28 @@* SPDX-License-Identifier: GPL-2.0+ */ +#ifndef USE_HOSTCC #include <common.h> #include <fdtdec.h> -#include <rsa.h> -#include <sha1.h> -#include <sha256.h> +#include <asm/types.h> #include <asm/byteorder.h> #include <asm/errno.h> +#include <asm/types.h> #include <asm/unaligned.h> +#else +#include "fdt_host.h" +#include "mkimage.h" +#include <fdt_support.h> +#endif +#include <rsa.h> +#include <sha1.h> +#include <sha256.h> #define UINT64_MULT32 (v, multby) (((uint64_t)(v)) * ((uint32_t)(multby))) +#define get_unaligned_be32 (a) fdt32_to_cpu(*(uint32_t *)a) +#define put_unaligned_be32 (a, b) (*(uint32_t *)(b) = cpu_to_fdt32(a)) +/** * subtract_modulus() - subtract modulus from the given value *
@@ -150,7 +161,6 @@ static int pow_mod(const struct rsa_public_key *key, uint32_t *inout)/* Convert to bigendian byte array */ for (i = key->len -1 , ptr = inout; (int )i >=0 ; i--, ptr++)put_unaligned_be32 (result[i], ptr); -return 0 ; }
test/vboot/vboot_test.sh +20 -0
@@ -47,6 +47,7 @@ O=$(readlink -f ${O}) dtc="-I dts -O dtb -p 2000" uboot="${O}/u-boot" mkimage="${O}/tools/mkimage" +fit_check_sign="${O}/tools/fit_check_sign" keys="${dir}/dev-keys" echo ${mkimage} -D "${dtc}"
@@ -99,6 +100,25 @@ function do_test { run_uboot "signed config" "dev+" + echo check signed config on the host + if ! ${fit_check_sign} -f test.fit -k sandbox-u-boot.dtb >${tmp}; then + echo + echo "Verified boot key check on host failed, output follows:" + cat ${tmp} + false + else + if ! grep -q "dev+" ${tmp}; then + echo + echo "Verified boot key check failed, output follows:" + cat ${tmp} + false + else + echo "OK" + fi + fi + + run_uboot "signed config" "dev+" + # Increment the first byte of the signature, which should cause failure sig=$(fdtget -t bx test.fit /configurations/conf at 1/signature at 1 value) newbyte=$(printf %x $((0x${sig:0:2} + 1)))
tools/.gitignore +1 -0
@@ -1,5 +1,6 @@ /bmp_logo /envcrc +/fit_check_sign /fit_info /gen_eth_addr /img2srec
tools/Makefile +5 -2
@@ -61,13 +61,13 @@ mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o hostprogs-y += dumpimage$(SFX) mkimage$(SFX) ifdef CONFIG_FIT_SIGNATURE -hostprogs-y += fit_info$(SFX) +hostprogs-y += fit_info$(SFX) fit_check_sign$(SFX) endif FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o # Flattened device tree objects LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o -RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o +RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o # common objs for dumpimage and mkimage dumpimage-mkimage-objs := aisimage.o \
@@ -97,6 +97,7 @@ dumpimage-mkimage-objs := aisimage.o \ dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o +fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o # TODO(sjg at chromium.org): Is this correct on Mac OS?
@@ -105,6 +106,7 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto +HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
@@ -114,6 +116,7 @@ ifdef CONFIG_FIT_SIGNATURE HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto +HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto # This affects include/image.h, but including the board config file # is tricky, so manually define this options here.
tools/fdt_host.h +2 -0
@@ -11,4 +11,6 @@#include "../include/libfdt.h" #include "../include/fdt_support.h" +int fit_check_sign (const void *working_fdt,const void *key); +#endif /* __FDT_HOST_H__ */
tools/fdtdec.c new file +1 -0
@@ -0,0 +1 @@ +#include "../lib/fdtdec.c"
tools/fit_check_sign.c new file +85 -0
85 lines not on this page · raw message
tools/image-host.c +15 -0
@@ -695,3 +695,18 @@ int fit_add_verification_data(const char *keydir, void *keydest, void *fit,return 0 ; } + +#ifdef CONFIG_FIT_SIGNATURE +int fit_check_sign (const void *working_fdt,const void *key) +{ +int cfg_noffset; +int ret; + + cfg_noffset =fit_conf_get_node (working_fdt,NULL ); +if (!cfg_noffset) +return -1 ; + + ret =fit_config_verify (working_fdt, cfg_noffset); +return ret; +} +#endif
tools/rsa-checksum.c new file +1 -0
@@ -0,0 +1 @@ +#include "../lib/rsa/rsa-checksum.c"
tools/rsa-verify.c new file +1 -0
@@ -0,0 +1 @@ +#include "../lib/rsa/rsa-verify.c"
Signature · 1 line
1.8.3.1
PATCH v3 8/8 tools, fit_check_sign: verify a signed fit image
+Charles for HOSTCC comments
Hi Heiko,
Quoted 5 lines · Heiko Schocher
add host tool "
fit_check_sign" which verifies, if a fit image is signed correct.Signed-off-by Heiko Schocher <[email protected]>Cc Simon Glass <[email protected]>
Looks good - a few nits and the crash I mentioned.
It's interesting that the host and target environments are so different - much of it is unavoidable but your patch is a good example of what is needed when we 'bridge the gap.
Regards,
Simon
PATCH v3 8/8 tools, fit_check_sign: verify a signed fit image
In reply to Heiko SchocherQuoted 5 lines · Heiko Schocher
add host tool "
fit_check_sign" which verifies, if a fit image is signed correct.Signed-off-by Heiko Schocher <[email protected]>Cc Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140327/a0eacbe2/attachment.pgp>