From e674ab1028392a8a6057455fc9cf234bb772f453 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Fri, 14 Aug 2026 21:34:10 +0200 Subject: [PATCH] Normalize VERIFY framing and reset handling Signed-off-by: Pol Henarejos --- src/openpgp/piv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/openpgp/piv.c b/src/openpgp/piv.c index 669a356..67731d5 100644 --- a/src/openpgp/piv.c +++ b/src/openpgp/piv.c @@ -385,10 +385,10 @@ static int cmd_get_serial(void) { static int cmd_piv_verify(void) { uint8_t key_ref = P2(apdu); if (P1(apdu) != 0x00 && P1(apdu) != 0xFF) { - return SW_INCORRECT_P1P2(); + return SW_INCORRECT_PARAMS(); } if (key_ref != 0x80) { - return SW_REFERENCE_NOT_FOUND(); + return SW_INCORRECT_PARAMS(); } file_t *pw, *pw_status; uint16_t fid = EF_PIV_PIN; @@ -401,6 +401,14 @@ static int cmd_piv_verify(void) { if (file_get_data(pw)[0] == 0) { //not initialized return SW_REFERENCE_NOT_FOUND(); } + if (P1(apdu) == 0xFF) { + if (apdu.nc != 0) { + return SW_INCORRECT_PARAMS(); + } + has_pwpiv = false; + mbedtls_platform_zeroize(session_pwpiv, sizeof(session_pwpiv)); + return SW_OK(); + } if (apdu.nc > 0) { uint16_t ret = check_pin(pw, apdu.data, apdu.nc); if (ret == 0x9000) {