Skip to content

Commit

Permalink
When exporting/importing decoded keys do not use 0 as selection
Browse files Browse the repository at this point in the history
When decoding 0 as the selection means to decode anything
you get.

However when exporting and then importing the key data 0 as
selection is not meaningful.
So we set it to OSSL_KEYMGMT_SELECT_ALL to make the export/import
function export/import everything that we have decoded.

Fixes openssl#21493

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from openssl#21519)

(cherry picked from commit 2acb0d3)
(cherry picked from commit 137ba05)
  • Loading branch information
t8m authored and xl32 committed Sep 29, 2023
1 parent 9128484 commit 72ec2b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion crypto/encode_decode/decoder_pkey.c
Expand Up @@ -150,7 +150,11 @@ static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst,

import_data.keymgmt = keymgmt;
import_data.keydata = NULL;
import_data.selection = data->selection;
if (data->selection == 0)
/* import/export functions do not tolerate 0 selection */
import_data.selection = OSSL_KEYMGMT_SELECT_ALL;
else
import_data.selection = data->selection;

/*
* No need to check for errors here, the value of
Expand Down
6 changes: 5 additions & 1 deletion providers/implementations/encode_decode/decode_der2key.c
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion providers/implementations/encode_decode/decode_msblob2key.c
Expand Up @@ -223,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;
}
Expand Down
6 changes: 5 additions & 1 deletion providers/implementations/encode_decode/decode_pvk2key.c
Expand Up @@ -190,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;
}
Expand Down

0 comments on commit 72ec2b1

Please sign in to comment.