diff options
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index fc1daa5..ed9c7b4 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -6,6 +6,7 @@ namespace nitrokey{ template <typename T> void strcpyT(T& dest, const char* src){ + assert(src != nullptr); const int s = sizeof dest; assert(strlen(src) <= s); strncpy((char*) &dest, src, s); @@ -138,8 +139,9 @@ namespace nitrokey{ } - bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, const char *temporary_password) { + bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter, + bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, + const char *temporary_password) { assert(is_valid_hotp_slot_number(slot_number)); assert(strlen(secret)==20); //160 bits assert(strlen(slot_name)<=15); @@ -149,8 +151,11 @@ namespace nitrokey{ payload.slot_number = slot_number; strcpyT(payload.slot_secret, secret); strcpyT(payload.slot_name, slot_name); + strcpyT(payload.slot_token_id, token_ID); payload.slot_counter = hotp_counter; payload.use_8_digits = use_8_digits; + payload.use_enter = use_enter; + payload.use_tokenID = use_tokenID; auto auth = get_payload<Authorize>(); strcpyT(auth.temporary_password, temporary_password); @@ -161,8 +166,9 @@ namespace nitrokey{ return true; } - bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, - uint16_t time_window, bool use_8_digits, const char *temporary_password) { + bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, + bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, + const char *temporary_password) { auto payload = get_payload<WriteToTOTPSlot>(); assert(is_valid_totp_slot_number(slot_number)); assert(strlen(secret) == sizeof payload.slot_secret); //160 bits @@ -172,18 +178,18 @@ namespace nitrokey{ payload.slot_number = slot_number; strcpyT(payload.slot_secret, secret); strcpyT(payload.slot_name, slot_name); + strcpyT(payload.slot_token_id, token_ID); payload.slot_interval = time_window; //FIXME naming payload.use_8_digits = use_8_digits; + payload.use_enter = use_enter; + payload.use_tokenID = use_tokenID; auto auth = get_payload<Authorize>(); strcpyT(auth.temporary_password, temporary_password); auth.crc_to_authorize = WriteToTOTPSlot::CommandTransaction::getCRC(payload); Authorize::CommandTransaction::run(*device, auth); -// auto auth_successful = device->last_command_sucessfull(); auto resp = WriteToTOTPSlot::CommandTransaction::run(*device, payload); -// auto write_successful = device->last_command_sucessfull(); -// return auth_successful && write_successful; //left to show alternative approach return true; } @@ -270,6 +276,11 @@ namespace nitrokey{ } void NitrokeyManager::enable_password_safe(const char *user_pin) { + //The following command will cancel enabling PWS if it is not supported + auto a = get_payload<IsAESSupported>(); + strcpyT(a.user_password, user_pin); + IsAESSupported::CommandTransaction::run(*device, a); + auto p = get_payload<EnablePasswordSafe>(); strcpyT(p.user_password, user_pin); EnablePasswordSafe::CommandTransaction::run(*device, p); @@ -363,14 +374,16 @@ namespace nitrokey{ FactoryReset::CommandTransaction::run(*device, p); } - void NitrokeyManager::unlock_user_password(const char *admin_password) { + void NitrokeyManager::unlock_user_password(const char *admin_password, const char *new_user_password) { auto p = get_payload<UnlockUserPassword>(); strcpyT(p.admin_password, admin_password); + strcpyT(p.user_new_password, new_user_password); UnlockUserPassword::CommandTransaction::run(*device, p); } - void NitrokeyManager::write_config(bool numlock, bool capslock, bool scrolllock, bool enable_user_password, bool delete_user_password, const char *admin_temporary_password) { + void NitrokeyManager::write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, + bool delete_user_password, const char *admin_temporary_password) { auto p = get_payload<WriteGeneralConfig>(); p.numlock = (uint8_t) numlock; p.capslock = (uint8_t) capslock; @@ -390,4 +403,11 @@ namespace nitrokey{ return v; } + bool NitrokeyManager::is_AES_supported(const char *user_password) { + auto a = get_payload<IsAESSupported>(); + strcpyT(a.user_password, user_password); + IsAESSupported::CommandTransaction::run(*device, a); + return true; + } + }
\ No newline at end of file |