Skip to content

Commit 2acb0d3

Browse files
t8mtmshort
authored andcommitted
When exporting/importing decoded keys do not use 0 as selection
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 #21493 Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Todd Short <[email protected]> (Merged from #21519)
1 parent 1ae4678 commit 2acb0d3

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

crypto/encode_decode/decoder_pkey.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ static int decoder_construct_pkey(OSSL_DECODER_INSTANCE *decoder_inst,
155155

156156
import_data.keymgmt = keymgmt;
157157
import_data.keydata = NULL;
158-
import_data.selection = data->selection;
158+
if (data->selection == 0)
159+
/* import/export functions do not tolerate 0 selection */
160+
import_data.selection = OSSL_KEYMGMT_SELECT_ALL;
161+
else
162+
import_data.selection = data->selection;
159163

160164
/*
161165
* No need to check for errors here, the value of

providers/implementations/encode_decode/decode_der2key.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,14 @@ static int der2key_export_object(void *vctx,
317317
void *keydata;
318318

319319
if (reference_sz == sizeof(keydata) && export != NULL) {
320+
int selection = ctx->selection;
321+
322+
if (selection == 0)
323+
selection = OSSL_KEYMGMT_SELECT_ALL;
320324
/* The contents of the reference is the address to our object */
321325
keydata = *(void **)reference;
322326

323-
return export(keydata, ctx->selection, export_cb, export_cbarg);
327+
return export(keydata, selection, export_cb, export_cbarg);
324328
}
325329
return 0;
326330
}

providers/implementations/encode_decode/decode_msblob2key.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,14 @@ msblob2key_export_object(void *vctx,
221221
void *keydata;
222222

223223
if (reference_sz == sizeof(keydata) && export != NULL) {
224+
int selection = ctx->selection;
225+
226+
if (selection == 0)
227+
selection = OSSL_KEYMGMT_SELECT_ALL;
224228
/* The contents of the reference is the address to our object */
225229
keydata = *(void **)reference;
226230

227-
return export(keydata, ctx->selection, export_cb, export_cbarg);
231+
return export(keydata, selection, export_cb, export_cbarg);
228232
}
229233
return 0;
230234
}

providers/implementations/encode_decode/decode_pvk2key.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,14 @@ static int pvk2key_export_object(void *vctx,
190190
void *keydata;
191191

192192
if (reference_sz == sizeof(keydata) && export != NULL) {
193+
int selection = ctx->selection;
194+
195+
if (selection == 0)
196+
selection = OSSL_KEYMGMT_SELECT_ALL;
193197
/* The contents of the reference is the address to our object */
194198
keydata = *(void **)reference;
195199

196-
return export(keydata, ctx->selection, export_cb, export_cbarg);
200+
return export(keydata, selection, export_cb, export_cbarg);
197201
}
198202
return 0;
199203
}

0 commit comments

Comments
 (0)