lib/ecdsa: Use the 'keydir' argument from mkimage if appropriate
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>
Fri, 19 Feb 2021 18:45:19 +0000 (12:45 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 14 Apr 2021 19:23:01 +0000 (15:23 -0400)
Keys can be derived from keydir, and the "key-name-hint" property of
the FIT. They can also be specified ad-literam via 'keyfile'. Update
the ECDSA signing path to use the appropriate one.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
lib/ecdsa/ecdsa-libcrypto.c

index 3228809..1757a14 100644 (file)
@@ -140,8 +140,20 @@ static int read_key(struct signer *ctx, const char *key_name)
 /* Prepare a 'signer' context that's ready to sign and verify. */
 static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info)
 {
-       const char *kname = info->keydir;
        int key_len_bytes, ret;
+       char kname[1024];
+
+       memset(ctx, 0, sizeof(*ctx));
+
+       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,
+                        info->keyname);
+       } else {
+               fprintf(stderr, "keyfile, keyname, or key-name-hint missing\n");
+               return -EINVAL;
+       }
 
        ret = alloc_ctx(ctx, info);
        if (ret)