Skip to contentSkip to conversation

lib: ecdsa: use .key extension for keydir keys

PATCH In review James Hilliard 2 participants 3 messages Jul 3 – Jul 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: ecdsa: use .key extension for keydir keys

The keydir/keyname path should follow the FIT signing key convention and read <key-name-hint>.key. Using .pem here is incorrect and does not match the filenames used by mkimage and binman key-directory flows.

---
 lib/ecdsa/ecdsa-libcrypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ecdsa/ecdsa-libcrypto.c +1 -1
index c4bfb2cec61..ef3e42cb0f8 100644
@@ -338,7 +338,7 @@ static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info)
 	} else if (info->keyfile) {
 		snprintf(kname,  sizeof(kname), "%s", info->keyfile);
 	} else if (info->keydir && info->keyname) {
-		snprintf(kname, sizeof(kname), "%s/%s.pem", info->keydir,
+		snprintf(kname, sizeof(kname), "%s/%s.key", info->keydir,
 			 info->keyname);
 	} else {
 		fprintf(stderr, "keyfile, keyname, or key-name-hint missing\n");
Signature · 1 line
2.53.0
#1 lore raw

Hi James,

Quoted 6 lines · James Hilliard

lib: ecdsa: use .key extension for keydir keys

The keydir/keyname path should follow the FIT signing key convention and read <key-name-hint>.key. Using .pem here is incorrect and does not match the filenames used by mkimage and binman key-directory flows.

Quoted 7 lines

lib/ecdsa/ecdsa-libcrypto.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

Using .pem here is incorrect and does not match
the filenames used by mkimage and binman key-directory flows.

Not quite - this has been the ECDSA behaviour since 2021 (commit eb22759e2be). It is inconsistent with the RSA path in rsa_get_priv_key() and binman's fit etype (which look for '<hint>.key'), but not incorrect as such. Anyone signing with 'mkimage -k <keydir>' and ECDSA today has keys named '<hint>.pem' and this patch silently breaks them. Please can you mention the compatibility impact in the commit message, rather than describing it as a straight bug fix?

lib/ecdsa/ecdsa-libcrypto.c static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info) · line 339

Quoted 5 lines
lib/ecdsa/ecdsa-libcrypto.c +1 -1
@@ -338,7 +338,7 @@ static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info)
-             snprintf(kname, sizeof(kname), "%s/%s.pem", info->keydir,
+             snprintf(kname, sizeof(kname), "%s/%s.key", info->keydir,
                       info->keyname);

Given the existing users, I suspect this should try '<keydir>/<keyname>.key' first and fall back to .pem if the file does not exist, perhaps with a deprecation warning. That gives people a migration path instead of an abrupt failure. What do you think?

BTW test/py/tests/test_fit_ecdsa.py only exercises the keyfile path, so neither extension is covered by tests - it would be good to extend it to use keydir so this does not regress again.

Regards,
Simon

#2 lore raw
Quoted 18 lines · Simon Glass

Hi James,

Quoted 6 lines · James Hilliard

lib: ecdsa: use .key extension for keydir keys

The keydir/keyname path should follow the FIT signing key convention and read <key-name-hint>.key. Using .pem here is incorrect and does not match the filenames used by mkimage and binman key-directory flows.

Quoted 7 lines

lib/ecdsa/ecdsa-libcrypto.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

Using .pem here is incorrect and does not match
the filenames used by mkimage and binman key-directory flows.

Quoted 8 lines

Not quite - this has been the ECDSA behaviour since 2021 (commit eb22759e2be). It is inconsistent with the RSA path in rsa_get_priv_key() and binman's fit etype (which look for '<hint>.key'), but not incorrect as such. Anyone signing with 'mkimage -k <keydir>' and ECDSA today has keys named '<hint>.pem' and this patch silently breaks them. Please can you mention the compatibility impact in the commit message, rather than describing it as a straight bug fix?

Yeah, I can add something like that.

Quoted 11 lines

lib/ecdsa/ecdsa-libcrypto.c static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info) · line 339

Quoted 6 lines
lib/ecdsa/ecdsa-libcrypto.c +1 -1
@@ -338,7 +338,7 @@ static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info)
-             snprintf(kname, sizeof(kname), "%s/%s.pem", info->keydir,
+             snprintf(kname, sizeof(kname), "%s/%s.key", info->keydir,
                       info->keyname);

Given the existing users, I suspect this should try '<keydir>/<keyname>.key' first and fall back to .pem if the file does not exist, perhaps with a deprecation warning. That gives people a migration path instead of an abrupt failure. What do you think?

I figured people were passing the full keyfile rather than the key directory for ecdsa, if that's the case(since binman is kinda broken with the current naming) then I figure should be safe enough to just fix this. I don't think ecdsa signing is particularly common in general so this would be a fairly rare issue. I can re-spin with fallback or warning if you think that really is necessary but since the failure isn't silent it should be easy/obvious enough to fix if someone does run into the error. Let me know what you think.

Quoted 7 lines

BTW test/py/tests/test_fit_ecdsa.py only exercises the keyfile path, so neither extension is covered by tests - it would be good to extend it to use keydir so this does not regress again.

Regards,
Simon