GENERAL AUTHENTICATE rejects truncated/inconsistent envelopes before TLV parsing.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-07-16 00:56:32 +02:00
parent 3e4f73870a
commit e9b12c6ccd
+9
View File
@@ -26,7 +26,13 @@
int cmd_general_authenticate(void) {
if (P1(apdu) == 0x0 && P2(apdu) == 0x0) {
if (apdu.nc < 2) {
return SW_WRONG_LENGTH();
}
if (apdu.data[0] == 0x7C) {
if (apdu.data[1] != apdu.nc - 2) {
return SW_WRONG_DATA();
}
int r = 0;
uint16_t pubkey_len = 0;
const uint8_t *pubkey = NULL;
@@ -41,6 +47,9 @@ int cmd_general_authenticate(void) {
pubkey_len = tag_len + 1;
}
}
if (!pubkey) {
return SW_WRONG_DATA();
}
file_t *fkey = file_search(EF_KEY_DEV);
if (!fkey) {
return SW_EXEC_ERROR();