From ba97d2efd73bd004bc3d1b0bf76e32e17e739144 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 13 Oct 2016 16:56:44 +0200 Subject: NK Storage: update counters before getting Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index d827292..ac6ce77 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -312,10 +312,16 @@ namespace nitrokey{ } uint8_t NitrokeyManager::get_user_retry_count() { + if(device->get_device_model() == DeviceModel::STORAGE){ + stick20::GetDeviceStatus::CommandTransaction::run(*device); + } auto response = GetUserPasswordRetryCount::CommandTransaction::run(*device); return response.data().password_retry_count; } uint8_t NitrokeyManager::get_admin_retry_count() { + if(device->get_device_model() == DeviceModel::STORAGE){ + stick20::GetDeviceStatus::CommandTransaction::run(*device); + } auto response = GetPasswordRetryCount::CommandTransaction::run(*device); return response.data().password_retry_count; } -- cgit v1.2.1 From 443e50b1a447dee6181aa721fb310060cecd63ae Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 14 Oct 2016 12:55:42 +0200 Subject: Fixed too long string test fail caused by different behavior of Storage Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index ac6ce77..872ebb4 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -280,11 +280,10 @@ namespace nitrokey{ auto p = get_payload(); strcpyT(p.old_pin, current_PIN); p.set_kind(StoKind); - ChangeAdminUserPin20Current::CommandTransaction::run(*device, p); - auto p2 = get_payload(); strcpyT(p2.new_pin, new_PIN); p2.set_kind(StoKind); + ChangeAdminUserPin20Current::CommandTransaction::run(*device, p); ChangeAdminUserPin20New::CommandTransaction::run(*device, p2); } break; -- cgit v1.2.1 From 48786a730bbbdd75719069e81e620eb916e98be0 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 14 Oct 2016 13:00:30 +0200 Subject: C/C++ API: make connection and disconnection more robust Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 872ebb4..e5d912d 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -45,7 +45,7 @@ namespace nitrokey{ } bool NitrokeyManager::connect() { - device = nullptr; + this->disconnect(); vector< shared_ptr > devices = { make_shared(), make_shared() }; for( auto & d : devices ){ if (d->connect()){ @@ -57,7 +57,8 @@ namespace nitrokey{ bool NitrokeyManager::connect(const char *device_model) { - switch (device_model[0]){ + this->disconnect(); + switch (device_model[0]){ case 'P': device = make_shared(); break; @@ -78,7 +79,12 @@ namespace nitrokey{ } bool NitrokeyManager::disconnect() { - return device->disconnect(); + if (device == nullptr){ + return false; + } + const auto res = device->disconnect(); + device = nullptr; + return res; } void NitrokeyManager::set_debug(bool state) { -- cgit v1.2.1 From fe62a51c052dfa13b91b760188cd57e73971ddbf Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 14 Oct 2016 13:47:16 +0200 Subject: Command unlock user password for NK Storage Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index e5d912d..78b5d84 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -403,10 +403,26 @@ namespace nitrokey{ } void NitrokeyManager::unlock_user_password(const char *admin_password, const char *new_user_password) { - auto p = get_payload(); - strcpyT(p.admin_password, admin_password); - strcpyT(p.user_new_password, new_user_password); - UnlockUserPassword::CommandTransaction::run(*device, p); + switch (device->get_device_model()){ + case DeviceModel::PRO: { + auto p = get_payload(); + strcpyT(p.admin_password, admin_password); + strcpyT(p.user_new_password, new_user_password); + stick10::UnlockUserPassword::CommandTransaction::run(*device, p); + break; + } + case DeviceModel::STORAGE : { + auto p2 = get_payload(); + p2.set_kind(PasswordKind::Admin); + strcpyT(p2.old_pin, admin_password); + ChangeAdminUserPin20Current::CommandTransaction::run(*device, p2); + auto p3 = get_payload(); + p3.set_kind(PasswordKind::Admin); + strcpyT(p3.user_new_password, new_user_password); + stick20::UnlockUserPassword::CommandTransaction::run(*device, p3); + break; + } + } } -- cgit v1.2.1 From c0ffb01dd42b21023c00cb57f8d22bc5b53e244b Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 14 Oct 2016 13:50:57 +0200 Subject: Log strcpyT argument sizes info Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 78b5d84..20657a5 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -8,10 +8,15 @@ namespace nitrokey{ template void strcpyT(T& dest, const char* src){ - if (src == nullptr) + + if (src == nullptr) // throw EmptySourceStringException(slot_number); return; const size_t s_dest = sizeof dest; + nitrokey::log::Log::instance()(std::string("strcpyT sizes ") + +std::to_string(s_dest)+ " " + +std::to_string(strlen(src))+ " " + ,nitrokey::log::Loglevel::DEBUG); if (strlen(src) > s_dest){ throw TooLongStringException(strlen(src), s_dest, src); } -- cgit v1.2.1 From 801fcc59dbf04dfce4323d2a3cad99f9d643e525 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 14 Oct 2016 15:00:04 +0200 Subject: Support regenerating AES keys on NK Storage Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 20657a5..47b68d4 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -396,9 +396,21 @@ namespace nitrokey{ } void NitrokeyManager::build_aes_key(const char *admin_password) { - auto p = get_payload(); - strcpyT(p.admin_password, admin_password); - BuildAESKey::CommandTransaction::run(*device, p); + switch (device->get_device_model()) { + case DeviceModel::PRO: { + auto p = get_payload(); + strcpyT(p.admin_password, admin_password); + BuildAESKey::CommandTransaction::run(*device, p); + break; + } + case DeviceModel::STORAGE : { + auto p = get_payload(); + strcpyT(p.admin_password, admin_password); + p.setKindPrefixed(); + stick20::CreateNewKeys::CommandTransaction::run(*device, p); + break; + } + } } void NitrokeyManager::factory_reset(const char *admin_password) { -- cgit v1.2.1 From 945db76ab4c6eb42224f4d18f45e67390540b5d0 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 19 Oct 2016 11:54:01 +0200 Subject: Fix bug for setting HOTP counters - send uint64 (was uint8) Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 47b68d4..a01dbec 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -179,9 +179,9 @@ namespace nitrokey{ std::copy(vec.begin(), vec.end(), dest); } - 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) { + bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, + bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, + const char *temporary_password) { if (!is_valid_hotp_slot_number(slot_number)) throw InvalidSlotException(slot_number); slot_number = get_internal_slot_number_for_hotp(slot_number); -- cgit v1.2.1 From d26e07e7a4a5066f69364aebf13eda35490bea5c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 19 Oct 2016 12:30:34 +0200 Subject: Handle HOTP counters as strings for Storage Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index a01dbec..7f3bfd0 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -13,7 +13,7 @@ namespace nitrokey{ // throw EmptySourceStringException(slot_number); return; const size_t s_dest = sizeof dest; - nitrokey::log::Log::instance()(std::string("strcpyT sizes ") + nitrokey::log::Log::instance()(std::string("strcpyT sizes dest src ") +std::to_string(s_dest)+ " " +std::to_string(strlen(src))+ " " ,nitrokey::log::Loglevel::DEBUG); @@ -191,7 +191,22 @@ namespace nitrokey{ vector_copy(payload.slot_secret, secret_bin); strcpyT(payload.slot_name, slot_name); strcpyT(payload.slot_token_id, token_ID); - payload.slot_counter = hotp_counter; + switch (device->get_device_model() ){ + case DeviceModel::PRO: { + payload.slot_counter = hotp_counter; + break; + } + case DeviceModel::STORAGE: { + std::string counter = std::to_string(hotp_counter); + strcpyT(payload.slot_counter, counter.c_str()); + break; + } + default: + nitrokey::log::Log::instance()( std::string(__FILE__) + std::to_string(__LINE__) + + std::string(__FUNCTION__) + std::string(" Unhandled device model for HOTP") + , nitrokey::log::Loglevel::DEBUG); + break; + } payload.use_8_digits = use_8_digits; payload.use_enter = use_enter; payload.use_tokenID = use_tokenID; -- cgit v1.2.1