Skip to content

Commit

Permalink
wip: fix password length issue and oath with_enter
Browse files Browse the repository at this point in the history
  • Loading branch information
dangfan committed Jan 12, 2024
1 parent f82ec90 commit a9c2b76
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions applets/oath/oath.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int oath_install(const uint8_t reset) {
static int oath_select(const CAPDU *capdu, RAPDU *rapdu) {
if (P2 != 0x00) EXCEPT(SW_WRONG_P1P2);

memcpy(RDATA, (uint8_t[]){OATH_TAG_VERSION, 3, 0x05, 0x05, 0x05, OATH_TAG_NAME, HANDLE_LEN}, 7);
memcpy(RDATA, (uint8_t[]){OATH_TAG_VERSION, 3, 0x06, 0x00, 0x00, OATH_TAG_NAME, HANDLE_LEN}, 7);
if (read_attr(OATH_FILE, ATTR_HANDLE, RDATA + 7, HANDLE_LEN) < 0) return -1;
LL = 7 + HANDLE_LEN;

Expand Down Expand Up @@ -418,7 +418,7 @@ int oath_calculate_by_offset(size_t file_offset, uint8_t result[4]) {

static int oath_set_default(const CAPDU *capdu, RAPDU *rapdu) {
if (P1 != 0x01 && P1 != 0x02) EXCEPT(SW_WRONG_P1P2);
if (P2 != 0x00) EXCEPT(SW_WRONG_P1P2);
if (P2 != 0x00 && P2 != 0x01) EXCEPT(SW_WRONG_P1P2);

uint16_t offset = 0;
if (offset + 1 >= LC) EXCEPT(SW_WRONG_LENGTH);
Expand All @@ -444,7 +444,7 @@ static int oath_set_default(const CAPDU *capdu, RAPDU *rapdu) {
if (i == n_records) EXCEPT(SW_DATA_INVALID);
if ((record.key[0] & OATH_TYPE_MASK) == OATH_TYPE_TOTP) EXCEPT(SW_CONDITIONS_NOT_SATISFIED);

return pass_update_oath(P1 -1, file_offset, record.name_len, record.name);
return pass_update_oath(P1 -1, file_offset, record.name_len, record.name, P2);
}

static int oath_calculate(const CAPDU *capdu, RAPDU *rapdu) {
Expand Down
7 changes: 4 additions & 3 deletions applets/pass/pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ int pass_write_config(const CAPDU *capdu, RAPDU *rapdu) {
return write_file(PASS_FILE, slots, 0, sizeof(slots), 1);
}

int pass_update_oath(uint8_t slot_index, uint32_t offset, uint8_t name_len, const uint8_t *name) {
int pass_update_oath(uint8_t slot_index, uint32_t offset, uint8_t name_len, const uint8_t *name, uint8_t with_enter) {
pass_slot_t *slot = &slots[slot_index];
slot->type = PASS_SLOT_OATH;
slot->oath_offset = offset;
slot->name_len = name_len;
memcpy(slot->name, name, name_len);
slot->with_enter = with_enter;

return write_file(PASS_FILE, slots, 0, sizeof(slots), 1);
}
Expand Down Expand Up @@ -166,8 +167,8 @@ int pass_handle_touch(uint8_t touch_type, char *output) {
length = oath_process_offset(slot->oath_offset, output);
break;
case PASS_SLOT_STATIC:
memcpy(output, slot->password + 1, slot->password[0]);
length = slot->password[0];
memcpy(output, slot->password, slot->password_len);
length = slot->password_len;
break;
default:
return -1;
Expand Down
2 changes: 1 addition & 1 deletion include/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ int pass_install(uint8_t reset);
int pass_read_config(const CAPDU *capdu, RAPDU *rapdu);
int pass_write_config(const CAPDU *capdu, RAPDU *rapdu);
int pass_handle_touch(uint8_t touch_type, char *output);
int pass_update_oath(uint8_t slot_index, uint32_t offset, uint8_t name_len, const uint8_t *name);
int pass_update_oath(uint8_t slot_index, uint32_t offset, uint8_t name_len, const uint8_t *name, uint8_t with_enter);

#endif // CANOKEY_CORE_INCLUDE_PASS_H

0 comments on commit a9c2b76

Please sign in to comment.