mkimage: allow to specify signing algorithm
cover mkimage: allow to specify signing algorithm
Another step to decouple the FIT image specification from the actual
signing: With these changes, the signature nodes can leave out an algo property, mkimage will initialize that as well while signing. This way, in-tree FIT source files can be prepared for gaining signatures without defining the key type or size upfront, forcing users to patch the code to change that.
Patch 1 is preparatory for this, patch 2 a drive-by cleanup.
A better solution would actually be if the algorithm was derived from the provided key. But the underlying crypto layer seems to be rather unprepared for that.
Jan
Jan Kiszka (3):
image-fit: Make string of algo parameter constant
mkimage: Drop unused OPT_STRING constant
mkimage: Allow to specify the signature algorithm on the command line
boot/image-fit-sig.c | 2 +- boot/image-fit.c | 8 +++---- doc/mkimage.1 | 5 +++++ include/image.h | 5 +++-- tools/fit_image.c | 3 ++- tools/image-host.c | 50 +++++++++++++++++++++++++------------------- tools/imagetool.h | 1 + tools/mkimage.c | 6 ++++-- 8 files changed, 49 insertions(+), 31 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/3 image-fit: Make string of algo parameter constant
From: Jan Kiszka <[email protected]>
Modifications would be invalid.
--- boot/image-fit-sig.c | 2 +- boot/image-fit.c | 8 ++++---- include/image.h | 2 +- tools/image-host.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
boot/image-fit-sig.c +1 -1
@@ -67,7 +67,7 @@ static int fit_image_setup_verify(struct image_sign_info *info, const void *fit, int noffset, int required_keynode, char **err_msgp) { - char *algo_name; + const char *algo_name;const char *padding_name;if (fdt_totalsize (fit) >CONFIG_VAL (FIT_SIGNATURE_MAX_SIZE )) {
boot/image-fit.c +4 -4
@@ -191,7 +191,7 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p,const char *keyname;uint8_t *value;int value_len; -char *algo; +const char *algo;const char *padding;bool required;int ret, i;
@@ -1063,11 +1063,11 @@ int fit_image_get_data_and_size(const void *fit, int noffset,* 0, on success * -1, on failure */ -int fit_image_hash_get_algo (const void *fit,int noffset,char **algo) +int fit_image_hash_get_algo (const void *fit,int noffset,const char **algo) {int len; - *algo = (char *)fdt_getprop (fit, noffset,FIT_ALGO_PROP , &len); + *algo = (const char *)fdt_getprop (fit, noffset,FIT_ALGO_PROP , &len);if (*algo ==NULL ) {fit_get_debug (fit, noffset,FIT_ALGO_PROP , len);return -1 ;
@@ -1265,7 +1265,7 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data, {uint8_t value[FIT_MAX_HASH_LEN ];int value_len; -char *algo; +const char *algo;uint8_t *fit_value;int fit_value_len;int ignore;
include/image.h +1 -1
@@ -1011,7 +1011,7 @@ int fit_image_get_data_size_unciphered(const void *fit, int noffset,int fit_image_get_data_and_size (const void *fit,int noffset,const void **data,size_t *size); -int fit_image_hash_get_algo (const void *fit,int noffset,char **algo); +int fit_image_hash_get_algo (const void *fit,int noffset,const char **algo);int fit_image_hash_get_value (const void *fit,int noffset,uint8_t **value,int *value_len);
tools/image-host.c +2 -2
@@ -63,7 +63,7 @@ static int fit_image_process_hash(void *fit, const char *image_name,uint8_t value[FIT_MAX_HASH_LEN ];const char *node_name;int value_len; -char *algo; +const char *algo;int ret; node_name =fit_get_name (fit, noffset,NULL );
@@ -160,7 +160,7 @@ static int fit_image_setup_sig(struct image_sign_info *info, const char *engine_id) {const char *node_name; -char *algo_name; +const char *algo_name;const char *padding_name; node_name =fit_get_name (fit, noffset,NULL );
Signature · 1 line
2.31.1
PATCH 2/3 mkimage: Drop unused OPT_STRING constant
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
The actual opt string is inlined - and different. Seems this was a left-over from older versions of 603e26f76346.
--- tools/mkimage.c | 1 - 1 file changed, 1 deletion(-)
tools/mkimage.c +0 -1
@@ -146,7 +146,6 @@ static int add_content(int type, const char *fname)return 0 ; } -#define OPT_STRING "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qstT:vVx"static void process_args (int argc,char **argv) {char *ptr;
Signature · 1 line
2.31.1
PATCH 3/3 mkimage: Allow to specify the signature algorithm on the command line
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This permits to prepare FIT image description that do not hard-code the final choice of the signature algorithm, possibly requiring the user to patch the sources.
When -o <algo> is specified, this information is used in favor of the 'algo' property in the signature node. Furthermore, that property is set accordingly when writing the image.
--- doc/mkimage.1 | 5 +++++ include/image.h | 3 ++- tools/fit_image.c | 3 ++- tools/image-host.c | 48 +++++++++++++++++++++++++++------------------- tools/imagetool.h | 1 + tools/mkimage.c | 5 ++++- 6 files changed, 42 insertions(+), 23 deletions(-)
doc/mkimage.1 +5 -0
@@ -155,6 +155,11 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot. +.TP +.BI "\-o [" "signing algorithm" "]" +Specifies the algorithm to be used for signing a FIT image. The default is +taken from the target signature nodes 'algo' properties. + .TP .BI "\-p [" "external position" "]" Place external data at a static external position. See \-E. Instead of writing
include/image.h +2 -1
@@ -1031,6 +1031,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 +* @algo_name: Algorithm name, or NULL if to be read from FIT * * Adds hash values for all component images in the FIT blob. * Hashes are calculated for all component images which have hash subnodes
@@ -1045,7 +1046,7 @@ 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,const char *algo_name);int fit_image_verify_with_data (const void *fit,int image_noffset,const void *data,size_t size);
tools/fit_image.c +2 -1
@@ -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->algo_name); }if (dest_blob) {
tools/image-host.c +28 -20
149 lines not on this page · raw message
tools/imagetool.h +1 -0
@@ -69,6 +69,7 @@ struct image_tool_params {const char *keydest;/* Destination .dtb for public key */ const char *keyfile;/* Filename of private or public key */ const char *comment;/* Comment to add to signature node */ +const char *algo_name;/* Algorithm name to use hashing/signing */ int require_keys;/* 1 to mark signing keys as 'required' */ int file_size;/* Total size of output file */ int orig_file_size;/* Original size for file before padding */
tools/mkimage.c +4 -1
@@ -154,7 +154,7 @@ static void process_args(int argc, char **argv)int opt;while ((opt =getopt (argc, argv, -"a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:O:rR:qstT:vVx" )) !=-1 ) { +"a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:o:O:rR:qstT:vVx" )) !=-1 ) {switch (opt) {case 'a' : params.addr =strtoull (optarg, &ptr,16 );
@@ -250,6 +250,9 @@ static void process_args(int argc, char **argv)case 'N' : params.engine_id = optarg;break ; +case 'o' : + params.algo_name = optarg; +break ;case 'O' : params.os =genimg_get_os_id (optarg);if (params.os <0 ) {
Signature · 1 line
2.31.1
Quoted 20 lines · Jan Kiszka
Another step to decouple the FIT image specification from the actual
signing: With these changes, the signature nodes can leave out an algo property, mkimage will initialize that as well while signing. This way, in-tree FIT source files can be prepared for gaining signatures without defining the key type or size upfront, forcing users to patch the code to change that.Patch 1 is preparatory for this, patch 2 a drive-by cleanup.
A better solution would actually be if the algorithm was derived from the provided key. But the underlying crypto layer seems to be rather unprepared for that.
Jan
Jan Kiszka (3):
image-fit: Make string of algo parameter constant
mkimage: Drop unusedOPT_STRINGconstant
mkimage: Allow to specify the signature algorithm on the command line
Quoted 10 lines
boot/image-fit-sig.c | 2 +- boot/image-fit.c | 8 +++---- doc/mkimage.1 | 5 +++++ include/image.h | 5 +++-- tools/fit_image.c | 3 ++- tools/image-host.c | 50 +++++++++++++++++++++++++------------------- tools/imagetool.h | 1 + tools/mkimage.c | 6 ++++-- 8 files changed, 49 insertions(+), 31 deletions(-)
Ping on this series.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Hi Jan,
Quoted 33 lines · Jan Kiszka
Quoted 20 lines · Jan Kiszka
Another step to decouple the FIT image specification from the actual
signing: With these changes, the signature nodes can leave out an algo property, mkimage will initialize that as well while signing. This way, in-tree FIT source files can be prepared for gaining signatures without defining the key type or size upfront, forcing users to patch the code to change that.Patch 1 is preparatory for this, patch 2 a drive-by cleanup.
A better solution would actually be if the algorithm was derived from the provided key. But the underlying crypto layer seems to be rather unprepared for that.
Jan
Jan Kiszka (3):
image-fit: Make string of algo parameter constant
mkimage: Drop unusedOPT_STRINGconstant
mkimage: Allow to specify the signature algorithm on the command lineQuoted 10 lines
boot/image-fit-sig.c | 2 +- boot/image-fit.c | 8 +++---- doc/mkimage.1 | 5 +++++ include/image.h | 5 +++-- tools/fit_image.c | 3 ++- tools/image-host.c | 50 +++++++++++++++++++++++++------------------- tools/imagetool.h | 1 + tools/mkimage.c | 6 ++++-- 8 files changed, 49 insertions(+), 31 deletions(-)
Quoted 7 lines
Ping on this series.
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
Somehow I did not get this. Can you please resend it? I have lost some patches to spam filters.
Regards,
Simon
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Jan Kiszka
Another step to decouple the FIT image specification from the actual
signing: With these changes, the signature nodes can leave out an algo property, mkimage will initialize that as well while signing. This way, in-tree FIT source files can be prepared for gaining signatures without defining the key type or size upfront, forcing users to patch the code to change that.
[resend to the list]
While encryption algo (rsa2048 vs rsa4096, etc) shouldn't need to be explicitly specified as you noted below, how does it help to add it to (already exhaustive) mkimage args? Parsing OID / length from keyfile would be real change.
While rotating keys is common, how often algo is changed?
Quoted 6 lines
Quoted 6 lines
Patch 1 is preparatory for this, patch 2 a drive-by cleanup.
A better solution would actually be if the algorithm was derived from the provided key. But the underlying crypto layer seems to be rather unprepared for that.
Thanks,
DHananjay
Quoted 9 lines · Dhananjay Phadke
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Jan Kiszka
Another step to decouple the FIT image specification from the actual
signing: With these changes, the signature nodes can leave out an algo property, mkimage will initialize that as well while signing. This way, in-tree FIT source files can be prepared for gaining signatures without defining the key type or size upfront, forcing users to patch the code to change that.
Quoted 9 lines
[resend to the list]
While encryption algo (rsa2048 vs rsa4096, etc) shouldn't need to be explicitly specified as you noted below, how does it help to add it to (already exhaustive) mkimage args? Parsing OID / length from keyfile would be real change.
While rotating keys is common, how often algo is changed?
The use case is decoupling of signature preparation from actual signing. Means, we would like to prepare binman image device trees for applying signature but without making the decision which key type and width should be used. That shall be up to the user (integrator) of the firmware image.
This series will enable a patch like https://github.com/siemens/u-boot/commit/1215a357ec1f58acde56c8ca4085aa43f8fdbf5a and a signature workflow that does not require to patch the U-Boot source anymore. It still makes the decision of using hash algo SHA256, but that is acceptable.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux