Reject impossible PIN lengths without retry

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-08-14 14:32:45 +02:00
parent 6cb6198609
commit b1b956b18f
+12
View File
@@ -204,6 +204,15 @@ int check_pin_len(uint16_t fid, size_t len) {
return SW_OK();
}
static bool offered_pin_len_impossible(const file_t *pin, size_t len) {
if (!pin || (pin->fid != EF_PW1 && pin->fid != EF_PW3 && pin->fid != EF_RC)) {
return false;
}
size_t min_len = pin->fid == EF_PW1 ? 6u : 8u;
size_t stored_len = file_get_data(pin)[0];
return stored_len >= min_len && stored_len <= 127u && (len < min_len || len > 127u);
}
static bool reset_code_is_public_default(const file_t *rc) {
static const uint8_t default_reset_code[] = "12345678";
@@ -896,6 +905,9 @@ int check_pin(const file_t *pin, const uint8_t *data, size_t len) {
if (!file_has_data(pin)) {
return SW_REFERENCE_NOT_FOUND();
}
if (offered_pin_len_impossible(pin, len)) {
return SW_WRONG_DATA();
}
isUserAuthenticated = false;
//has_pw1 = has_pw3 = false;