Adding P1=0x2 and P1=0x3 for reset retry counter.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2022-04-03 20:59:50 +02:00
parent 85ff92c4de
commit a619527482

View File

@@ -478,57 +478,63 @@ static int cmd_verify() {
} }
static int cmd_reset_retry() { static int cmd_reset_retry() {
uint16_t opts = get_device_options(); if (P2(apdu) != 0x81)
if (P1(apdu) == 0x0) { return SW_REFERENCE_NOT_FOUND();
if (P2(apdu) == 0x81) {
if (!file_sopin || !file_pin1) { if (!file_sopin || !file_pin1) {
return SW_FILE_NOT_FOUND(); return SW_FILE_NOT_FOUND();
} }
if (!file_sopin->data) { if (!file_sopin->data) {
return SW_REFERENCE_NOT_FOUND(); return SW_REFERENCE_NOT_FOUND();
} }
if (apdu.cmd_apdu_data_len <= 8) uint16_t opts = get_device_options();
return SW_WRONG_LENGTH();
if (!(opts & HSM_OPT_RRC)) if (!(opts & HSM_OPT_RRC))
return SW_COMMAND_NOT_ALLOWED(); return SW_COMMAND_NOT_ALLOWED();
if (P1(apdu) == 0x0 || P1(apdu) == 0x2) {
int newpin_len = 0;
if (P1(apdu) == 0x0) {
if (apdu.cmd_apdu_data_len <= 8)
return SW_WRONG_LENGTH();
uint16_t r = check_pin(file_sopin, apdu.cmd_apdu_data, 8); uint16_t r = check_pin(file_sopin, apdu.cmd_apdu_data, 8);
if (r != 0x9000) if (r != 0x9000)
return r; return r;
newpin_len = apdu.cmd_apdu_data_len-8;
}
else if (P1(apdu) == 0x2) {
if (!has_session_sopin)
return SW_CONDITIONS_NOT_SATISFIED();
if (apdu.cmd_apdu_data_len > 16)
return SW_WRONG_LENGTH();
newpin_len = apdu.cmd_apdu_data_len;
}
uint8_t dhash[33]; uint8_t dhash[33];
dhash[0] = apdu.cmd_apdu_data_len-8; dhash[0] = newpin_len;
double_hash_pin(apdu.cmd_apdu_data+8, apdu.cmd_apdu_data_len-8, dhash+1); double_hash_pin(apdu.cmd_apdu_data+(apdu.cmd_apdu_data_len-newpin_len), newpin_len, dhash+1);
flash_write_data_to_file(file_pin1, dhash, sizeof(dhash)); flash_write_data_to_file(file_pin1, dhash, sizeof(dhash));
if (pin_reset_retries(file_pin1, true) != HSM_OK) if (pin_reset_retries(file_pin1, true) != HSM_OK)
return SW_MEMORY_FAILURE(); return SW_MEMORY_FAILURE();
low_flash_available(); low_flash_available();
return SW_OK(); return SW_OK();
} }
else else if (P1(apdu) == 0x1 || P1(apdu) == 0x3) {
return SW_REFERENCE_NOT_FOUND(); if (!(opts & HSM_OPT_RRC_RESET_ONLY))
} return SW_COMMAND_NOT_ALLOWED();
else if (P1(apdu) == 0x1) { if (P1(apdu) == 0x1) {
if (P2(apdu) == 0x81) {
if (!file_sopin || !file_pin1) {
return SW_FILE_NOT_FOUND();
}
if (!file_sopin->data) {
return SW_REFERENCE_NOT_FOUND();
}
if (apdu.cmd_apdu_data_len != 8) if (apdu.cmd_apdu_data_len != 8)
return SW_WRONG_LENGTH(); return SW_WRONG_LENGTH();
if (!(opts & HSM_OPT_RRC) || !(opts & HSM_OPT_RRC_RESET_ONLY))
return SW_COMMAND_NOT_ALLOWED();
uint16_t r = check_pin(file_sopin, apdu.cmd_apdu_data, 8); uint16_t r = check_pin(file_sopin, apdu.cmd_apdu_data, 8);
if (r != 0x9000) if (r != 0x9000)
return r; return r;
}
else if (P1(apdu) == 0x3) {
if (!has_session_sopin)
return SW_CONDITIONS_NOT_SATISFIED();
if (apdu.cmd_apdu_data_len != 0)
return SW_WRONG_LENGTH();
}
if (pin_reset_retries(file_pin1, true) != HSM_OK) if (pin_reset_retries(file_pin1, true) != HSM_OK)
return SW_MEMORY_FAILURE(); return SW_MEMORY_FAILURE();
low_flash_available();
return SW_OK(); return SW_OK();
} }
else
return SW_REFERENCE_NOT_FOUND();
}
return SW_INCORRECT_P1P2(); return SW_INCORRECT_P1P2();
} }