Accept arbitrary SO-PIN length on reset retry.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2023-09-05 19:46:32 +02:00
parent 3d7f714936
commit 173ca7678d

View File

@@ -36,16 +36,15 @@ int cmd_reset_retry() {
if (P1(apdu) == 0x0 || P1(apdu) == 0x2) { if (P1(apdu) == 0x0 || P1(apdu) == 0x2) {
int newpin_len = 0; int newpin_len = 0;
if (P1(apdu) == 0x0) { if (P1(apdu) == 0x0) {
if (apdu.nc <= 8) { uint8_t so_pin_len = file_read_uint8(file_get_data(file_sopin));
if (apdu.nc <= so_pin_len + 1) {
return SW_WRONG_LENGTH(); return SW_WRONG_LENGTH();
} }
uint16_t r = check_pin(file_sopin, apdu.data, 8); uint16_t r = check_pin(file_sopin, apdu.data, so_pin_len);
if (r != 0x9000) { if (r != 0x9000) {
return r; return r;
} }
newpin_len = apdu.nc - 8; newpin_len = apdu.nc - so_pin_len;
has_session_sopin = true;
hash_multi(apdu.data, 8, session_sopin);
} }
else if (P1(apdu) == 0x2) { else if (P1(apdu) == 0x2) {
if (!has_session_sopin) { if (!has_session_sopin) {
@@ -83,15 +82,14 @@ int cmd_reset_retry() {
return SW_COMMAND_NOT_ALLOWED(); return SW_COMMAND_NOT_ALLOWED();
} }
if (P1(apdu) == 0x1) { if (P1(apdu) == 0x1) {
if (apdu.nc != 8) { uint8_t so_pin_len = file_read_uint8(file_get_data(file_sopin));
if (apdu.nc != so_pin_len) {
return SW_WRONG_LENGTH(); return SW_WRONG_LENGTH();
} }
uint16_t r = check_pin(file_sopin, apdu.data, 8); uint16_t r = check_pin(file_sopin, apdu.data, so_pin_len);
if (r != 0x9000) { if (r != 0x9000) {
return r; return r;
} }
has_session_sopin = true;
hash_multi(apdu.data, 8, session_sopin);
} }
else if (P1(apdu) == 0x3) { else if (P1(apdu) == 0x3) {
if (!has_session_sopin) { if (!has_session_sopin) {