]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mkimage: use environment variable MKIMAGE_SIGN_PIN to set pin for OpenSSL Engine
authorMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 23 Jul 2021 20:17:50 +0000 (22:17 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 29 Jul 2021 00:46:34 +0000 (20:46 -0400)
This patch adds the possibility to pass the PIN the OpenSSL Engine
used during signing via the environment variable MKIMAGE_SIGN_PIN.
This follows the approach used during kernel module
signing ("KBUILD_SIGN_PIN") or UBIFS image
signing ("MKIMAGE_SIGN_PIN").

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
doc/uImage.FIT/signature.txt
lib/rsa/rsa-sign.c

index 7cb1c15e5e1586c561f6845fd5a81900a17b454e..61a72db3c74fb078237f46ab9ffcca92624373b5 100644 (file)
@@ -533,8 +533,8 @@ Generic engine key ids:
 or
   "<key-name-hint>"
 
-As mkimage does not at this time support prompting for passwords HSM may need
-key preloading wrapper to be used when invoking mkimage.
+In order to set the pin in the HSM, an environment variable "MKIMAGE_SIGN_PIN"
+can be specified.
 
 The following examples use the Nitrokey Pro using pkcs11 engine. Instructions
 for other devices may vary.
index c64deac31f4868912a7086c22cb776db375efd2e..085dc89bf7bb3d30a0de6e81d930f017b4ec019f 100644 (file)
@@ -338,6 +338,7 @@ static int rsa_init(void)
 
 static int rsa_engine_init(const char *engine_id, ENGINE **pe)
 {
+       const char *key_pass;
        ENGINE *e;
        int ret;
 
@@ -362,10 +363,20 @@ static int rsa_engine_init(const char *engine_id, ENGINE **pe)
                goto err_set_rsa;
        }
 
+       key_pass = getenv("MKIMAGE_SIGN_PIN");
+       if (key_pass) {
+               if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) {
+                       fprintf(stderr, "Couldn't set PIN\n");
+                       ret = -1;
+                       goto err_set_pin;
+               }
+       }
+
        *pe = e;
 
        return 0;
 
+err_set_pin:
 err_set_rsa:
        ENGINE_finish(e);
 err_engine_init: