diff --git a/src/openpgp/piv.c b/src/openpgp/piv.c index 1ea393f..51a86e3 100644 --- a/src/openpgp/piv.c +++ b/src/openpgp/piv.c @@ -806,12 +806,12 @@ static int cmd_asym_keygen() { if (!has_mgm) { return SW_SECURITY_STATUS_NOT_SATISFIED(); } - if (key_ref == 0x93) { - key_ref = EF_PIV_KEY_RETIRED18; - } if (key_ref != EF_PIV_KEY_AUTHENTICATION && key_ref != EF_PIV_KEY_SIGNATURE && key_ref != EF_PIV_KEY_KEYMGM && key_ref != EF_PIV_KEY_CARDAUTH && !(key_ref >= EF_PIV_KEY_RETIRED1 && key_ref <= EF_PIV_KEY_RETIRED20)) { return SW_INCORRECT_P1P2(); } + if (key_ref == 0x93) { + key_ref = EF_PIV_KEY_RETIRED18; + } asn1_ctx_t ctxi, aac = {0}; asn1_ctx_init(apdu.data, (uint16_t)apdu.nc, &ctxi); if (!asn1_find_tag(&ctxi, 0xAC, &aac) || asn1_len(&aac) == 0) { @@ -889,6 +889,9 @@ static int cmd_asym_keygen() { } else if (a80.data[0] == PIV_ALGO_X25519) { } + else { + return SW_DATA_INVALID(); + } uint8_t def_pinpol = PINPOLICY_ONCE; if (key_ref == EF_PIV_KEY_SIGNATURE) { def_pinpol = PINPOLICY_ALWAYS;