diff --git a/applets/oath/oath.c b/applets/oath/oath.c index 42fbf935..b1e00e4d 100644 --- a/applets/oath/oath.c +++ b/applets/oath/oath.c @@ -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); } diff --git a/applets/pass/pass.c b/applets/pass/pass.c index a67907d1..f9ac9ea7 100644 --- a/applets/pass/pass.c +++ b/applets/pass/pass.c @@ -123,10 +123,10 @@ 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; @@ -134,9 +134,21 @@ int pass_update_oath(uint8_t slot_index, uint32_t offset, uint8_t name_len, cons 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; diff --git a/include/pass.h b/include/pass.h index 4ca88f32..b5a40b08 100644 --- a/include/pass.h +++ b/include/pass.h @@ -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