aboutsummaryrefslogtreecommitdiff
path: root/lib/rsa
diff options
context:
space:
mode:
authorCsókás Bence2024-01-05 15:08:04 +0100
committerTom Rini2024-01-18 17:50:27 -0500
commitf055d6e8f0d63a80d72ab5b092a26bedc652ac3b (patch)
treeab7c113b2f723ed40f5d92cce2dcd211601b88f4 /lib/rsa
parent11ad2bbfa2d83501a3d7b9fdbd567f55214fde0d (diff)
lib: rsa: Allow legacy URI specification without "pkcs11:"
But emit a warning for it. Then we can remove support when everyone had time to update their scripts, docs, CI etc. Fixes: ece85cc020 rsa: use pkcs11 uri as defined in rfc7512 Signed-off-by: Csókás Bence <csokas.bence@prolan.hu>
Diffstat (limited to 'lib/rsa')
-rw-r--r--lib/rsa/rsa-sign.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index fd587d8deb6..2304030e32f 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -104,6 +104,8 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
const char *engine_id;
char key_id[1024];
EVP_PKEY *key = NULL;
+ const char *const pkcs11_schema = "pkcs11:";
+ const char *pkcs11_uri_prepend = "";
if (!evpp)
return -EINVAL;
@@ -113,19 +115,26 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
engine_id = ENGINE_get_id(engine);
if (engine_id && !strcmp(engine_id, "pkcs11")) {
- if (keydir)
+ if (keydir) {
+ // Check for legacy keydir spec and prepend
+ if (strncmp(pkcs11_schema, keydir, strlen(pkcs11_schema))) {
+ pkcs11_uri_prepend = pkcs11_schema;
+ fprintf(stderr, "WARNING: Legacy URI specified. Please add '%s'.\n", pkcs11_schema);
+ }
+
if (strstr(keydir, "object="))
snprintf(key_id, sizeof(key_id),
- "%s;type=public",
- keydir);
+ "%s%s;type=public",
+ pkcs11_uri_prepend, keydir);
else
snprintf(key_id, sizeof(key_id),
- "%s;object=%s;type=public",
- keydir, name);
- else
+ "%s%s;object=%s;type=public",
+ pkcs11_uri_prepend, keydir, name);
+ } else {
snprintf(key_id, sizeof(key_id),
"pkcs11:object=%s;type=public",
name);
+ }
} else if (engine_id) {
if (keydir)
snprintf(key_id, sizeof(key_id),
@@ -224,6 +233,8 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
const char *engine_id;
char key_id[1024];
EVP_PKEY *key = NULL;
+ const char *const pkcs11_schema = "pkcs11:";
+ const char *pkcs11_uri_prepend = "";
if (!evpp)
return -EINVAL;
@@ -235,19 +246,26 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
fprintf(stderr, "Please use 'keydir' with PKCS11\n");
return -EINVAL;
}
- if (keydir)
+ if (keydir) {
+ // Check for legacy keydir spec and prepend
+ if (strncmp(pkcs11_schema, keydir, strlen(pkcs11_schema))) {
+ pkcs11_uri_prepend = pkcs11_schema;
+ fprintf(stderr, "WARNING: Legacy URI specified. Please add '%s'.\n", pkcs11_schema);
+ }
+
if (strstr(keydir, "object="))
snprintf(key_id, sizeof(key_id),
- "%s;type=private",
- keydir);
+ "%s%s;type=private",
+ pkcs11_uri_prepend, keydir);
else
snprintf(key_id, sizeof(key_id),
- "%s;object=%s;type=private",
- keydir, name);
- else
+ "%s%s;object=%s;type=private",
+ pkcs11_uri_prepend, keydir, name);
+ } else {
snprintf(key_id, sizeof(key_id),
"pkcs11:object=%s;type=private",
name);
+ }
} else if (engine_id) {
if (keydir && name)
snprintf(key_id, sizeof(key_id),