lib: rsa: avoid overriding the object name when already specified
authorJan Luebbe <jlu@pengutronix.de>
Wed, 13 May 2020 10:26:24 +0000 (12:26 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 15 May 2020 18:47:35 +0000 (14:47 -0400)
If "object=" is specified in "keydir" when using the pkcs11 engine do
not append another "object=<key-name-hint>". This makes it possible to
use object names other than the key name hint. These two string
identifiers are not necessarily equal.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Bastian Krause <bst@pengutronix.de>
Reviewed-by: George McCollister <george.mccollister@gmail.com>
doc/uImage.FIT/signature.txt
lib/rsa/rsa-sign.c

index 3591225a6edd87ea60b9424b130fcf11a1a903d6..d4afd755e9fc7336a9390c050ec37a4cd0f2e42b 100644 (file)
@@ -481,12 +481,14 @@ openssl. This may require setting up LD_LIBRARY_PATH if engine is not installed
 to openssl's default search paths.
 
 PKCS11 engine support forms "key id" based on "keydir" and with
-"key-name-hint". "key-name-hint" is used as "object" name and "keydir" if
-defined is used to define (prefix for) which PKCS11 source is being used for
-lookup up for the key.
+"key-name-hint". "key-name-hint" is used as "object" name (if not defined in
+keydir). "keydir" (if defined) is used to define (prefix for) which PKCS11 source
+is being used for lookup up for the key.
 
 PKCS11 engine key ids:
    "pkcs11:<keydir>;object=<key-name-hint>;type=<public|private>"
+or, if keydir contains "object="
+   "pkcs11:<keydir>;type=<public|private>"
 or
    "pkcs11:object=<key-name-hint>;type=<public|private>",
 
index 621ddc43504527721033d4ce48ed85825e19eb9b..40ca1e1f57320aaf52d3c1aa2a8d1a76d7817fb5 100644 (file)
@@ -135,9 +135,14 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 
        if (engine_id && !strcmp(engine_id, "pkcs11")) {
                if (keydir)
-                       snprintf(key_id, sizeof(key_id),
-                                "pkcs11:%s;object=%s;type=public",
-                                keydir, name);
+                       if (strstr(keydir, "object="))
+                               snprintf(key_id, sizeof(key_id),
+                                        "pkcs11:%s;type=public",
+                                        keydir);
+                       else
+                               snprintf(key_id, sizeof(key_id),
+                                        "pkcs11:%s;object=%s;type=public",
+                                        keydir, name);
                else
                        snprintf(key_id, sizeof(key_id),
                                 "pkcs11:object=%s;type=public",
@@ -255,9 +260,14 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 
        if (engine_id && !strcmp(engine_id, "pkcs11")) {
                if (keydir)
-                       snprintf(key_id, sizeof(key_id),
-                                "pkcs11:%s;object=%s;type=private",
-                                keydir, name);
+                       if (strstr(keydir, "object="))
+                               snprintf(key_id, sizeof(key_id),
+                                        "pkcs11:%s;type=private",
+                                        keydir);
+                       else
+                               snprintf(key_id, sizeof(key_id),
+                                        "pkcs11:%s;object=%s;type=private",
+                                        keydir, name);
                else
                        snprintf(key_id, sizeof(key_id),
                                 "pkcs11:object=%s;type=private",