Skip to content

Commit

Permalink
delete touch item when deleting oath item
Browse files Browse the repository at this point in the history
  • Loading branch information
dangfan committed Jan 12, 2024
1 parent 06ee655 commit 6a415fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
9 changes: 1 addition & 8 deletions applets/oath/oath.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,7 @@ static int oath_delete(const CAPDU *capdu, RAPDU *rapdu) {
for (size_t i = 0; i != n_records; ++i) {
if (read_file(OATH_FILE, &record, i * sizeof(OATH_RECORD), sizeof(OATH_RECORD)) < 0) return -1;
if (record.name_len == name_len && memcmp(record.name, name_ptr, name_len) == 0) {
// uint32_t default_item;
// if (read_attr(OATH_FILE, ATTR_DEFAULT_RECORD, &default_item, sizeof(default_item)) < 0) return -1;
// if (default_item == i) { // clear the default set if it is to be deleted
// default_item = 0xffffffff;
// if (write_attr(OATH_FILE, ATTR_DEFAULT_RECORD, &default_item, sizeof(default_item)) < 0) return -1;
// }
// TODO: delete pass config

if (pass_delete_oath(i * sizeof(OATH_RECORD)) < 0) return -1;
record.name_len = 0;
return write_file(OATH_FILE, &record, i * sizeof(OATH_RECORD), sizeof(OATH_RECORD), 0);
}
Expand Down
20 changes: 16 additions & 4 deletions applets/pass/pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,32 @@ 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, uint8_t with_enter) {
int pass_update_oath(uint8_t slot_index, uint32_t file_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->oath_offset = file_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);
}

static int oath_process_offset(uint32_t offset, char *output) {
int pass_delete_oath(uint32_t file_offset) {
if (slots[0].type == PASS_SLOT_OATH && slots[0].oath_offset == file_offset) {
slots[0].type = PASS_SLOT_OFF;
return write_file(PASS_FILE, slots, 0, sizeof(slots), 1);
}
if (slots[1].type == PASS_SLOT_OATH && slots[1].oath_offset == file_offset) {
slots[1].type = PASS_SLOT_OFF;
return write_file(PASS_FILE, slots, 0, sizeof(slots), 1);
}
return 0;
}

static int oath_process_offset(uint32_t file_offset, char *output) {
uint32_t otp_code;
int ret = oath_calculate_by_offset(offset, (uint8_t *)&otp_code);
int ret = oath_calculate_by_offset(file_offset, (uint8_t *)&otp_code);
if (ret < 0) return ret;
const int len = ret;

Expand Down
3 changes: 2 additions & 1 deletion include/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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, uint8_t with_enter);
int pass_update_oath(uint8_t slot_index, uint32_t file_offset, uint8_t name_len, const uint8_t *name, uint8_t with_enter);
int pass_delete_oath(uint32_t file_offset);

#endif // CANOKEY_CORE_INCLUDE_PASS_H

0 comments on commit 6a415fb

Please sign in to comment.