Skip to content

Commit

Permalink
test covers static password
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Feb 3, 2024
1 parent 6e232c7 commit d9f31d9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion applets/pass/pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int dump_slot(const pass_slot_t *slot, uint8_t *buffer) {
break;

default:
ERR_MSG("Invalid type %p %d\n", slot, slot->type);
// ERR_MSG("Invalid type %p %d\n", slot, slot->type);
return 0;
}

Expand Down
52 changes: 51 additions & 1 deletion test/test_oath.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static void check_pass_config(bool present, uint8_t slot, uint8_t *data) {
int i, s;
uint8_t c_buf[1024], r_buf[1024];
CAPDU C = {.data = c_buf}; RAPDU R = {.data = r_buf};
pass_read_config(&C, &R);
s = pass_read_config(&C, &R);
assert_int_equal(s, 0);
print_hex(R.data, R.len);
printf(" R\n");
for (i = 0, s = 1; i < R.len; s++) {
Expand Down Expand Up @@ -228,6 +229,54 @@ static void test_hotp_touch(void **state) {
check_pass_config(false, 2, rfc4226example);
}

static void test_static_pass(void **state) {
int len, ret;
uint8_t c_buf[1024], r_buf[1024];
const char static_pass[PASS_MAX_PASSWORD_LENGTH+1] =
"a0aaa0a0a0aaaaa0a0a00a0a0bbabba0";
char readback[PASS_MAX_PASSWORD_LENGTH*2];
CAPDU C = {.data = c_buf}; RAPDU R = {.data = r_buf};
CAPDU *capdu = &C;
RAPDU *rapdu = &R;

P1 = 2;
c_buf[0] = PASS_SLOT_STATIC;
c_buf[1] = sizeof(static_pass);
memcpy(c_buf+2, static_pass, c_buf[1]);
c_buf[c_buf[1]+2] = 0;
LC = c_buf[1]+3;
pass_write_config(&C, &R);
assert_int_equal(SW, SW_WRONG_LENGTH);

len = c_buf[1] = PASS_MAX_PASSWORD_LENGTH;
memcpy(c_buf+2, static_pass, c_buf[1]);
c_buf[c_buf[1]+2] = 0;
LC = c_buf[1]+3;
ret = pass_write_config(&C, &R);
assert_int_equal(ret, 0);

ret = pass_handle_touch(TOUCH_LONG, readback);
assert_int_equal(ret, len);
assert_memory_equal(readback, static_pass, len);

c_buf[c_buf[1]+2] = 1;
LC = c_buf[1]+3;
ret = pass_write_config(&C, &R);
assert_int_equal(ret, 0);

ret = pass_handle_touch(TOUCH_LONG, readback);
assert_int_equal(ret, len+1);
assert_memory_equal(readback, static_pass, len);
assert_int_equal(readback[len], '\r');

pass_install(0); // reload from file

ret = pass_handle_touch(TOUCH_LONG, readback);
assert_int_equal(ret, len+1);
assert_memory_equal(readback, static_pass, len);
assert_int_equal(readback[len], '\r');
}

// should be called after test_put
static void test_calc(void **state) {
(void)state;
Expand Down Expand Up @@ -510,6 +559,7 @@ int main() {
cmocka_unit_test(test_list),
cmocka_unit_test(test_calc_all),
cmocka_unit_test(test_hotp_touch),
cmocka_unit_test(test_static_pass),
cmocka_unit_test(test_space_full),
cmocka_unit_test(test_regression_fuzz),
};
Expand Down

0 comments on commit d9f31d9

Please sign in to comment.