aboutsummaryrefslogtreecommitdiff
path: root/providers/implementations/encode_decode
diff options
context:
space:
mode:
authorPierre Pronchery <pierre@freebsdfoundation.org>2023-09-22 14:52:58 +0000
committerEd Maste <emaste@FreeBSD.org>2023-09-22 15:55:26 +0000
commit315108b81694de474bbc273c0050b195047f5eed (patch)
treee3f2a313c74d0ae64bb2f0da5ecd9edb258e361f /providers/implementations/encode_decode
parentcf2fc1b0f5ce501f5a29d307294e5637e0f5aba6 (diff)
Diffstat (limited to 'providers/implementations/encode_decode')
-rw-r--r--providers/implementations/encode_decode/decode_der2key.c6
-rw-r--r--providers/implementations/encode_decode/decode_msblob2key.c22
-rw-r--r--providers/implementations/encode_decode/decode_pvk2key.c21
-rw-r--r--providers/implementations/encode_decode/encode_key2any.c7
4 files changed, 49 insertions, 7 deletions
diff --git a/providers/implementations/encode_decode/decode_der2key.c b/providers/implementations/encode_decode/decode_der2key.c
index b9cee2571bf3..d598f7eba1ac 100644
--- a/providers/implementations/encode_decode/decode_der2key.c
+++ b/providers/implementations/encode_decode/decode_der2key.c
@@ -316,10 +316,14 @@ static int der2key_export_object(void *vctx,
void *keydata;
if (reference_sz == sizeof(keydata) && export != NULL) {
+ int selection = ctx->selection;
+
+ if (selection == 0)
+ selection = OSSL_KEYMGMT_SELECT_ALL;
/* The contents of the reference is the address to our object */
keydata = *(void **)reference;
- return export(keydata, ctx->selection, export_cb, export_cbarg);
+ return export(keydata, selection, export_cb, export_cbarg);
}
return 0;
}
diff --git a/providers/implementations/encode_decode/decode_msblob2key.c b/providers/implementations/encode_decode/decode_msblob2key.c
index 501957faba01..b9d0cabadae2 100644
--- a/providers/implementations/encode_decode/decode_msblob2key.c
+++ b/providers/implementations/encode_decode/decode_msblob2key.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -79,6 +79,18 @@ static void msblob2key_freectx(void *vctx)
OPENSSL_free(ctx);
}
+static int msblob2key_does_selection(void *provctx, int selection)
+{
+ if (selection == 0)
+ return 1;
+
+ if ((selection & (OSSL_KEYMGMT_SELECT_PRIVATE_KEY
+ | OSSL_KEYMGMT_SELECT_PUBLIC_KEY)) != 0)
+ return 1;
+
+ return 0;
+}
+
static int msblob2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection,
OSSL_CALLBACK *data_cb, void *data_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
@@ -211,10 +223,14 @@ msblob2key_export_object(void *vctx,
void *keydata;
if (reference_sz == sizeof(keydata) && export != NULL) {
+ int selection = ctx->selection;
+
+ if (selection == 0)
+ selection = OSSL_KEYMGMT_SELECT_ALL;
/* The contents of the reference is the address to our object */
keydata = *(void **)reference;
- return export(keydata, ctx->selection, export_cb, export_cbarg);
+ return export(keydata, selection, export_cb, export_cbarg);
}
return 0;
}
@@ -260,6 +276,8 @@ static void rsa_adjust(void *key, struct msblob2key_ctx_st *ctx)
(void (*)(void))msblob2##keytype##_newctx }, \
{ OSSL_FUNC_DECODER_FREECTX, \
(void (*)(void))msblob2key_freectx }, \
+ { OSSL_FUNC_DECODER_DOES_SELECTION, \
+ (void (*)(void))msblob2key_does_selection }, \
{ OSSL_FUNC_DECODER_DECODE, \
(void (*)(void))msblob2key_decode }, \
{ OSSL_FUNC_DECODER_EXPORT_OBJECT, \
diff --git a/providers/implementations/encode_decode/decode_pvk2key.c b/providers/implementations/encode_decode/decode_pvk2key.c
index c6424165b03b..2d7cb15e53e0 100644
--- a/providers/implementations/encode_decode/decode_pvk2key.c
+++ b/providers/implementations/encode_decode/decode_pvk2key.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -79,6 +79,17 @@ static void pvk2key_freectx(void *vctx)
OPENSSL_free(ctx);
}
+static int pvk2key_does_selection(void *provctx, int selection)
+{
+ if (selection == 0)
+ return 1;
+
+ if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
+ return 1;
+
+ return 0;
+}
+
static int pvk2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection,
OSSL_CALLBACK *data_cb, void *data_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
@@ -179,10 +190,14 @@ static int pvk2key_export_object(void *vctx,
void *keydata;
if (reference_sz == sizeof(keydata) && export != NULL) {
+ int selection = ctx->selection;
+
+ if (selection == 0)
+ selection = OSSL_KEYMGMT_SELECT_ALL;
/* The contents of the reference is the address to our object */
keydata = *(void **)reference;
- return export(keydata, ctx->selection, export_cb, export_cbarg);
+ return export(keydata, selection, export_cb, export_cbarg);
}
return 0;
}
@@ -226,6 +241,8 @@ static void rsa_adjust(void *key, struct pvk2key_ctx_st *ctx)
(void (*)(void))pvk2##keytype##_newctx }, \
{ OSSL_FUNC_DECODER_FREECTX, \
(void (*)(void))pvk2key_freectx }, \
+ { OSSL_FUNC_DECODER_DOES_SELECTION, \
+ (void (*)(void))pvk2key_does_selection }, \
{ OSSL_FUNC_DECODER_DECODE, \
(void (*)(void))pvk2key_decode }, \
{ OSSL_FUNC_DECODER_EXPORT_OBJECT, \
diff --git a/providers/implementations/encode_decode/encode_key2any.c b/providers/implementations/encode_decode/encode_key2any.c
index c7b01cb2b3e5..0f4c62962ddc 100644
--- a/providers/implementations/encode_decode/encode_key2any.c
+++ b/providers/implementations/encode_decode/encode_key2any.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -858,14 +858,17 @@ static int prepare_rsa_params(const void *rsa, int nid, int save,
case 1:
if ((str = OPENSSL_malloc(str_sz)) == NULL
|| !WPACKET_init_der(&pkt, str, str_sz)) {
+ WPACKET_cleanup(&pkt);
goto err;
}
break;
}
if (!ossl_DER_w_RSASSA_PSS_params(&pkt, -1, pss)
|| !WPACKET_finish(&pkt)
- || !WPACKET_get_total_written(&pkt, &str_sz))
+ || !WPACKET_get_total_written(&pkt, &str_sz)) {
+ WPACKET_cleanup(&pkt);
goto err;
+ }
WPACKET_cleanup(&pkt);
/*