Skip to content

Commit

Permalink
Fix bad error on too long resetting code
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Oct 10, 2022
1 parent b9f850a commit c885fe7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ fn reset_retry_conter_with_code<const R: usize, T: trussed::Client>(
Ok(()) => {}
}

if new.len() > MAX_PIN_LENGTH {
warn!("Attempt to set resetting code too short");
return Err(Status::IncorrectDataParameter);
}

ctx.state
.internal
.change_pin(ctx.backend.client_mut(), new, Password::Pw1)
Expand Down
4 changes: 3 additions & 1 deletion tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ fn verify() {
tx.reset_retry_counter_pw1(b"new code", None).unwrap();
assert_checks!(tx, Some(3), Some(3), None);
tx.verify_pw1_user(b"new code").unwrap();
tx.set_resetting_code(&[0; 127]).unwrap();
tx.set_resetting_code(&[0; 128]).unwrap_err();
});
card.reset();
card.with_tx(|mut tx| {
assert!(tx.verify_pw1_user(b"bad code").is_err());
assert!(tx.verify_pw1_user(b"bad code").is_err());
assert!(tx.verify_pw1_user(b"bad code").is_err());
assert_checks!(tx, Some(0), Some(0), Some(3));
tx.reset_retry_counter_pw1(b"123456", Some(b"1234567890"))
tx.reset_retry_counter_pw1(b"123456", Some(&[0; 127]))
.unwrap();
assert_checks!(tx, Some(3), Some(3), Some(3));
tx.verify_pw1_user(b"123456").unwrap();
Expand Down

0 comments on commit c885fe7

Please sign in to comment.