From 42f9402f8b79d0e50cdffc16675145fb6188aec9 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 27 Mar 2024 15:18:01 +0100 Subject: [PATCH] Fix key deletion. Signed-off-by: Pol Henarejos --- src/openpgp/piv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/openpgp/piv.c b/src/openpgp/piv.c index 51a86e3..888c51d 100644 --- a/src/openpgp/piv.c +++ b/src/openpgp/piv.c @@ -981,10 +981,12 @@ static int cmd_move_key() { to = EF_PIV_KEY_RETIRED18; } file_t *efs, *efd; - if (!(efs = search_by_fid(from, NULL, SPECIFY_EF)) || !(efd = search_by_fid(to, NULL, SPECIFY_EF))) { + if (!(efs = search_by_fid(from, NULL, SPECIFY_EF)) || (!(efd = search_by_fid(to, NULL, SPECIFY_EF)) && to != 0xFF)) { return SW_FILE_NOT_FOUND(); } - flash_write_data_to_file(efd, file_get_data(efs), file_get_size(efs)); + if (to != 0xFF) { + flash_write_data_to_file(efd, file_get_data(efs), file_get_size(efs)); + } flash_clear_file(efs); low_flash_available(); return SW_OK();