From f5b5339a0cd272b3be33013f01e14f5bcc6e5aa8 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 26 Jul 2016 23:35:24 +0200 Subject: Erasing slot - initial version with some authorization issues Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index ef0eb5e..69b2059 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -82,23 +82,29 @@ namespace nitrokey{ return resp.code; } - bool NitrokeyManager::erase_slot(uint8_t slot_number) { + bool NitrokeyManager::erase_slot(uint8_t slot_number, const char *temporary_password) { auto p = get_payload(); p.slot_number = slot_number; + + auto auth = get_payload(); + strcpyT(auth.temporary_password, temporary_password); + auth.crc_to_authorize = EraseSlot::CommandTransaction::getCRC(p); + Authorize::CommandTransaction::run(*device, auth); + auto resp = EraseSlot::CommandTransaction::run(*device,p); return true; } - bool NitrokeyManager::erase_hotp_slot(uint8_t slot_number) { + bool NitrokeyManager::erase_hotp_slot(uint8_t slot_number, const char *temporary_password) { assert(is_valid_hotp_slot_number(slot_number)); slot_number = get_internal_slot_number_for_hotp(slot_number); - return erase_slot(slot_number); + return erase_slot(slot_number, temporary_password); } - bool NitrokeyManager::erase_totp_slot(uint8_t slot_number) { + bool NitrokeyManager::erase_totp_slot(uint8_t slot_number, const char *temporary_password) { assert(is_valid_totp_slot_number(slot_number)); slot_number = get_internal_slot_number_for_totp(slot_number); - return erase_slot(slot_number); + return erase_slot(slot_number, temporary_password); } @@ -173,7 +179,7 @@ namespace nitrokey{ return (uint8_t *) strdup((const char *) resp.slot_name); } - bool NitrokeyManager::authorize(const char *pin, const char *temporary_password) { + bool NitrokeyManager::first_authenticate(const char *pin, const char *temporary_password) { auto authreq = get_payload(); assert(strlen(pin) < sizeof authreq.card_password); @@ -294,4 +300,11 @@ namespace nitrokey{ ErasePasswordSafeSlot::CommandTransaction::run(*device, p); } + void NitrokeyManager::user_authenticate(const char *user_password, const char *temporary_password) { + auto p = get_payload(); + strcpyT(p.card_password, user_password); + strcpyT(p.temporary_password, temporary_password); + UserAuthenticate::CommandTransaction::run(*device, p); + } + } \ No newline at end of file -- cgit v1.2.1