diff --git a/CMakeLists.txt b/CMakeLists.txt index b1103db5..270d13e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,12 +48,12 @@ set(SOURCE_FILES include/log.h include/misc.h include/NitrokeyManager.h - include/stick10_commands.h - include/stick20_commands.h + include/NKPro_commands.h + include/NKStorage_commands.h include/CommandFailedException.h include/LibraryException.h include/LongOperationInProgressException.h - include/stick10_commands_0.8.h + include/NKPro_commands_0.8.h command_id.cc device.cc log.cc diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 60c1a24f..32e4614b 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -4,7 +4,7 @@ #include "include/LibraryException.h" #include #include -#include +#include #include "include/misc.h" #include #include "include/cxx_semantics.h" @@ -86,7 +86,7 @@ namespace nitrokey{ bool NitrokeyManager::connect() { std::lock_guard lock(mex_dev_com); - vector< shared_ptr > devices = { make_shared(), make_shared() }; + vector< shared_ptr > devices = { make_shared(), make_shared() }; for( auto & d : devices ){ if (d->connect()){ device = std::shared_ptr(d); @@ -115,10 +115,10 @@ namespace nitrokey{ LOG(__FUNCTION__, nitrokey::log::Loglevel::DEBUG_L2); switch (device_model[0]){ case 'P': - device = make_shared(); + device = make_shared(); break; case 'S': - device = make_shared(); + device = make_shared(); break; default: throw std::runtime_error("Unknown model"); @@ -198,7 +198,7 @@ namespace nitrokey{ case DeviceModel::STORAGE: { - auto response = stick20::GetDeviceStatus::CommandTransaction::run(device); + auto response = NKStorage::GetDeviceStatus::CommandTransaction::run(device); return nitrokey::misc::toHex(response.data().ActiveSmartCardID_u32); } break; @@ -206,7 +206,7 @@ namespace nitrokey{ return "NA"; } - stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){ + NKPro::GetStatus::ResponsePayload NitrokeyManager::get_status(){ try{ auto response = GetStatus::CommandTransaction::run(device); return response.data(); @@ -240,12 +240,12 @@ namespace nitrokey{ auto resp = GetHOTP::CommandTransaction::run(device, gh); return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); } else { - auto gh = get_payload(); + auto gh = get_payload(); gh.slot_number = get_internal_slot_number_for_hotp(slot_number); if(user_temporary_password != nullptr && strlen(user_temporary_password)!=0) { strcpyT(gh.temporary_user_password, user_temporary_password); } - auto resp = stick10_08::GetHOTP::CommandTransaction::run(device, gh); + auto resp = NKPro_08::GetHOTP::CommandTransaction::run(device, gh); return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); } return ""; @@ -277,10 +277,10 @@ namespace nitrokey{ auto resp = GetTOTP::CommandTransaction::run(device, gt); return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); } else { - auto gt = get_payload(); + auto gt = get_payload(); strcpyT(gt.temporary_user_password, user_temporary_password); gt.slot_number = slot_number; - auto resp = stick10_08::GetTOTP::CommandTransaction::run(device, gt); + auto resp = NKPro_08::GetTOTP::CommandTransaction::run(device, gt); return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); } return ""; @@ -293,10 +293,10 @@ namespace nitrokey{ authorize_packet(p, temporary_password, device); auto resp = EraseSlot::CommandTransaction::run(device,p); } else { - auto p = get_payload(); + auto p = get_payload(); p.slot_number = slot_number; strcpyT(p.temporary_admin_password, temporary_password); - auto resp = stick10_08::EraseSlot::CommandTransaction::run(device,p); + auto resp = NKPro_08::EraseSlot::CommandTransaction::run(device,p); } return true; } @@ -406,11 +406,11 @@ namespace nitrokey{ bool use_tokenID, const char *token_ID, const char *temporary_password) const { - auto payload2 = get_payload(); + auto payload2 = get_payload(); strcpyT(payload2.temporary_admin_password, temporary_password); strcpyT(payload2.data, slot_name); payload2.setTypeName(); - stick10_08::SendOTPData::CommandTransaction::run(device, payload2); + NKPro_08::SendOTPData::CommandTransaction::run(device, payload2); payload2.setTypeSecret(); payload2.id = 0; @@ -426,12 +426,12 @@ namespace nitrokey{ const auto start = secret_bin.size() - remaining_secret_length; memset(payload2.data, 0, sizeof(payload2.data)); vector_copy_ranged(payload2.data, secret_bin, start, bytesToCopy); - stick10_08::SendOTPData::CommandTransaction::run(device, payload2); + NKPro_08::SendOTPData::CommandTransaction::run(device, payload2); remaining_secret_length -= bytesToCopy; payload2.id++; } - auto payload = get_payload(); + auto payload = get_payload(); strcpyT(payload.temporary_admin_password, temporary_password); strcpyT(payload.slot_token_id, token_ID); payload.use_8_digits = use_8_digits; @@ -439,7 +439,7 @@ namespace nitrokey{ payload.use_tokenID = use_tokenID; payload.slot_counter_or_interval = counter_or_interval; payload.slot_number = internal_slot_number; - stick10_08::WriteToOTPSlot::CommandTransaction::run(device, payload); + NKPro_08::WriteToOTPSlot::CommandTransaction::run(device, payload); } void NitrokeyManager::write_TOTP_slot_authorize(uint8_t slot_number, const char *slot_name, const char *secret, @@ -562,7 +562,7 @@ namespace nitrokey{ uint8_t NitrokeyManager::get_user_retry_count() { if(device->get_device_model() == DeviceModel::STORAGE){ - stick20::GetDeviceStatus::CommandTransaction::run(device); + NKStorage::GetDeviceStatus::CommandTransaction::run(device); } auto response = GetUserPasswordRetryCount::CommandTransaction::run(device); return response.data().password_retry_count; @@ -570,7 +570,7 @@ namespace nitrokey{ uint8_t NitrokeyManager::get_admin_retry_count() { if(device->get_device_model() == DeviceModel::STORAGE){ - stick20::GetDeviceStatus::CommandTransaction::run(device); + NKStorage::GetDeviceStatus::CommandTransaction::run(device); } auto response = GetPasswordRetryCount::CommandTransaction::run(device); return response.data().password_retry_count; @@ -644,10 +644,10 @@ namespace nitrokey{ break; } case DeviceModel::STORAGE : { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.password, admin_password); p.set_defaults(); - stick20::CreateNewKeys::CommandTransaction::run(device, p); + NKStorage::CreateNewKeys::CommandTransaction::run(device, p); break; } } @@ -662,10 +662,10 @@ namespace nitrokey{ void NitrokeyManager::unlock_user_password(const char *admin_password, const char *new_user_password) { switch (device->get_device_model()){ case DeviceModel::PRO: { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.admin_password, admin_password); strcpyT(p.user_new_password, new_user_password); - stick10::UnlockUserPassword::CommandTransaction::run(device, p); + NKPro::UnlockUserPassword::CommandTransaction::run(device, p); break; } case DeviceModel::STORAGE : { @@ -673,10 +673,10 @@ namespace nitrokey{ p2.set_defaults(); strcpyT(p2.password, admin_password); ChangeAdminUserPin20Current::CommandTransaction::run(device, p2); - auto p3 = get_payload(); + auto p3 = get_payload(); p3.set_defaults(); strcpyT(p3.password, new_user_password); - stick20::UnlockUserPin::CommandTransaction::run(device, p3); + NKStorage::UnlockUserPin::CommandTransaction::run(device, p3); break; } } @@ -685,18 +685,18 @@ namespace nitrokey{ 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(); + auto p = get_payload(); p.numlock = (uint8_t) numlock; p.capslock = (uint8_t) capslock; p.scrolllock = (uint8_t) scrolllock; p.enable_user_password = (uint8_t) enable_user_password; p.delete_user_password = (uint8_t) delete_user_password; if (is_authorization_command_supported()){ - authorize_packet(p, admin_temporary_password, device); + authorize_packet(p, admin_temporary_password, device); } else { strcpyT(p.temporary_admin_password, admin_temporary_password); } - stick10_08::WriteGeneralConfig::CommandTransaction::run(device, p); + NKPro_08::WriteGeneralConfig::CommandTransaction::run(device, p); } vector NitrokeyManager::read_config() { @@ -739,7 +739,7 @@ namespace nitrokey{ return status_p.data().firmware_version; //7 or 8 } case DeviceModel::STORAGE:{ - auto status = stick20::GetDeviceStatus::CommandTransaction::run(device); + auto status = NKStorage::GetDeviceStatus::CommandTransaction::run(device); return status.data().versionInfo.minor; } } @@ -756,89 +756,89 @@ namespace nitrokey{ //storage commands void NitrokeyManager::send_startup(uint64_t seconds_from_epoch){ - auto p = get_payload(); + auto p = get_payload(); // p.set_defaults(); //set current time p.localtime = seconds_from_epoch; - stick20::SendStartup::CommandTransaction::run(device, p); + NKStorage::SendStartup::CommandTransaction::run(device, p); } void NitrokeyManager::unlock_encrypted_volume(const char* user_pin){ - misc::execute_password_command(device, user_pin); + misc::execute_password_command(device, user_pin); } void NitrokeyManager::unlock_hidden_volume(const char* hidden_volume_password) { - misc::execute_password_command(device, hidden_volume_password); + misc::execute_password_command(device, hidden_volume_password); } //TODO check is encrypted volume unlocked before execution //if not return library exception void NitrokeyManager::create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, const char *hidden_volume_password) { - auto p = get_payload(); + auto p = get_payload(); p.SlotNr_u8 = slot_nr; p.StartBlockPercent_u8 = start_percent; p.EndBlockPercent_u8 = end_percent; strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password); - stick20::SetupHiddenVolume::CommandTransaction::run(device, p); + NKStorage::SetupHiddenVolume::CommandTransaction::run(device, p); } void NitrokeyManager::set_unencrypted_read_only(const char* user_pin) { - misc::execute_password_command(device, user_pin); + misc::execute_password_command(device, user_pin); } void NitrokeyManager::set_unencrypted_read_write(const char* user_pin) { - misc::execute_password_command(device, user_pin); + misc::execute_password_command(device, user_pin); } void NitrokeyManager::export_firmware(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); + misc::execute_password_command(device, admin_pin); } void NitrokeyManager::enable_firmware_update(const char* firmware_pin) { - misc::execute_password_command(device, firmware_pin); + misc::execute_password_command(device, firmware_pin); } void NitrokeyManager::clear_new_sd_card_warning(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); + misc::execute_password_command(device, admin_pin); } void NitrokeyManager::fill_SD_card_with_random_data(const char* admin_pin) { - auto p = get_payload(); + auto p = get_payload(); p.set_defaults(); strcpyT(p.admin_pin, admin_pin); - stick20::FillSDCardWithRandomChars::CommandTransaction::run(device, p); + NKStorage::FillSDCardWithRandomChars::CommandTransaction::run(device, p); } void NitrokeyManager::change_update_password(const char* current_update_password, const char* new_update_password) { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.current_update_password, current_update_password); strcpyT(p.new_update_password, new_update_password); - stick20::ChangeUpdatePassword::CommandTransaction::run(device, p); + NKStorage::ChangeUpdatePassword::CommandTransaction::run(device, p); } const char * NitrokeyManager::get_status_storage_as_string(){ - auto p = stick20::GetDeviceStatus::CommandTransaction::run(device); + auto p = NKStorage::GetDeviceStatus::CommandTransaction::run(device); return strndup(p.data().dissect().c_str(), max_string_field_length); } - stick20::DeviceConfigurationResponsePacket::ResponsePayload NitrokeyManager::get_status_storage(){ - auto p = stick20::GetDeviceStatus::CommandTransaction::run(device); + NKStorage::DeviceConfigurationResponsePacket::ResponsePayload NitrokeyManager::get_status_storage(){ + auto p = NKStorage::GetDeviceStatus::CommandTransaction::run(device); return p.data(); } const char * NitrokeyManager::get_SD_usage_data_as_string(){ - auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(device); + auto p = NKStorage::GetSDCardOccupancy::CommandTransaction::run(device); return strndup(p.data().dissect().c_str(), max_string_field_length); } std::pair NitrokeyManager::get_SD_usage_data(){ - auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(device); + auto p = NKStorage::GetSDCardOccupancy::CommandTransaction::run(device); return std::make_pair(p.data().WriteLevelMin, p.data().WriteLevelMax); } int NitrokeyManager::get_progress_bar_value(){ try{ - stick20::GetDeviceStatus::CommandTransaction::run(device); + NKStorage::GetDeviceStatus::CommandTransaction::run(device); return -1; } catch (LongOperationInProgressException &e){ @@ -850,18 +850,18 @@ namespace nitrokey{ return get_TOTP_code(slot_number, 0, 0, 0, user_temporary_password); } - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_OTP_slot_data(const uint8_t slot_number) { - auto p = get_payload(); + NKPro::ReadSlot::ResponsePayload NitrokeyManager::get_OTP_slot_data(const uint8_t slot_number) { + auto p = get_payload(); p.slot_number = slot_number; - auto data = stick10::ReadSlot::CommandTransaction::run(device, p); + auto data = NKPro::ReadSlot::CommandTransaction::run(device, p); return data.data(); } - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_TOTP_slot_data(const uint8_t slot_number) { + NKPro::ReadSlot::ResponsePayload NitrokeyManager::get_TOTP_slot_data(const uint8_t slot_number) { return get_OTP_slot_data(get_internal_slot_number_for_totp(slot_number)); } - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_HOTP_slot_data(const uint8_t slot_number) { + NKPro::ReadSlot::ResponsePayload NitrokeyManager::get_HOTP_slot_data(const uint8_t slot_number) { auto slot_data = get_OTP_slot_data(get_internal_slot_number_for_hotp(slot_number)); if (device->get_device_model() == DeviceModel::STORAGE){ //convert counter from string to ull @@ -872,15 +872,15 @@ namespace nitrokey{ } void NitrokeyManager::lock_encrypted_volume() { - misc::execute_password_command(device, ""); + misc::execute_password_command(device, ""); } void NitrokeyManager::lock_hidden_volume() { - misc::execute_password_command(device, ""); + misc::execute_password_command(device, ""); } uint8_t NitrokeyManager::get_SD_card_size() { - auto data = stick20::ProductionTest::CommandTransaction::run(device); + auto data = NKStorage::ProductionTest::CommandTransaction::run(device); return data.data().SD_Card_Size_u8; } diff --git a/README.md b/README.md index 99c4a444..ce65da06 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # libnitrokey Libnitrokey is a project to communicate with Nitrokey Pro and Storage devices in a clean and easy manner. Written in C++14, testable with `py.test` and `Catch` frameworks, with C API, Python access (through CFFI and C API, in future with Pybind11). -The development of this project is aimed to make it itself a living documentation of communication protocol between host and the Nitrokey stick devices. The command packets' format is described here: [Pro v0.7](include/stick10_commands.h), [Pro v0.8](include/stick10_commands_0.8.h), [Storage](include/stick20_commands.h). Handling and additional operations are described here: [NitrokeyManager.cc](NitrokeyManager.cc). +The development of this project is aimed to make it itself a living documentation of communication protocol between host and the Nitrokey stick devices. The command packets' format is described here: [Pro v0.7](include/NKPro_commands.h), [Pro v0.8](include/NKPro_commands_0.8.h), [Storage](include/NKStorage_commands.h). Handling and additional operations are described here: [NitrokeyManager.cc](NitrokeyManager.cc). A C++14 complying compiler is required due to heavy use of variable templates. For feature support tables please check [table 1](https://gcc.gnu.org/projects/cxx-status.html#cxx14) or [table 2](http://en.cppreference.com/w/cpp/compiler_support). @@ -131,7 +131,7 @@ All available functions for C and Python are listed in [NK_C_API.h](NK_C_API.h). ## Documentation The documentation of C API is included in the sources (could be generated with doxygen if requested). -Please check NK_C_API.h (C API) for high level commands and include/NitrokeyManager.h (C++ API). All devices' commands are listed along with packet format in include/stick10_commands.h and include/stick20_commands.h respectively for Nitrokey Pro and Nitrokey Storage products. +Please check NK_C_API.h (C API) for high level commands and include/NitrokeyManager.h (C++ API). All devices' commands are listed along with packet format in include/NKPro_commands.h and include/NKStorage_commands.h respectively for Nitrokey Pro and Nitrokey Storage products. # Tests Warning! Before you run unittests please either change both your Admin and User PINs on your Nitrostick to defaults (`12345678` and `123456` respectively) or change the values in tests source code. If you do not change them the tests might lock your device. If it's too late, you can always reset your Nitrokey using instructions from [homepage](https://www.nitrokey.com/de/documentation/how-reset-nitrokey). diff --git a/device.cc b/device.cc index 101ebd03..217980de 100644 --- a/device.cc +++ b/device.cc @@ -190,14 +190,14 @@ void Device::set_retry_delay(const std::chrono::milliseconds delay){ m_retry_timeout = delay; } -Stick10::Stick10(): +Device_NKPro::Device_NKPro(): Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 5, 100ms) { setDefaultDelay(); } -Stick20::Stick20(): +Device_NKStorage::Device_NKStorage(): Device(0x20a0, 0x4109, DeviceModel::STORAGE, 20ms, 20, 20ms) { setDefaultDelay(); diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 417e8503..84343015 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -10,7 +10,7 @@ #include "log.h" #include "command_id.h" -using cs = nitrokey::proto::stick10::command_status; +using cs = nitrokey::proto::NKPro::command_status; class CommandFailedException : public std::exception { public: diff --git a/include/stick10_commands.h b/include/NKPro_commands.h similarity index 99% rename from include/stick10_commands.h rename to include/NKPro_commands.h index 74b73a8e..cefc9b4b 100644 --- a/include/stick10_commands.h +++ b/include/NKPro_commands.h @@ -1,5 +1,5 @@ -#ifndef STICK10_COMMANDS_H -#define STICK10_COMMANDS_H +#ifndef NKPRO_COMMANDS_H +#define NKPRO_COMMANDS_H #include #include @@ -17,9 +17,9 @@ namespace proto { /* - * Stick10 protocol definition + * Device_NKPro protocol definition */ -namespace stick10 { +namespace NKPro { class GetSlotName : public Command { public: // reachable as a typedef in Transaction diff --git a/include/stick10_commands_0.8.h b/include/NKPro_commands_0.8.h similarity index 89% rename from include/stick10_commands_0.8.h rename to include/NKPro_commands_0.8.h index ead5add7..9cee5e5f 100644 --- a/include/stick10_commands_0.8.h +++ b/include/NKPro_commands_0.8.h @@ -2,8 +2,8 @@ // Created by sz on 08.11.16. // -#ifndef LIBNITROKEY_STICK10_COMMANDS_0_8_H -#define LIBNITROKEY_STICK10_COMMANDS_0_8_H +#ifndef LIBNITROKEY_NKPRO_COMMANDS_0_8_H +#define LIBNITROKEY_NKPRO_COMMANDS_0_8_H #include #include @@ -12,40 +12,40 @@ #include #include "command.h" #include "device_proto.h" -#include "stick10_commands.h" +#include "NKPro_commands.h" namespace nitrokey { namespace proto { /* - * Stick10 protocol definition + * Device_NKPro protocol definition */ - namespace stick10_08 { - using stick10::FirstAuthenticate; - using stick10::UserAuthenticate; - using stick10::SetTime; - using stick10::GetStatus; - using stick10::BuildAESKey; - using stick10::ChangeAdminPin; - using stick10::ChangeUserPin; - using stick10::EnablePasswordSafe; - using stick10::ErasePasswordSafeSlot; - using stick10::FactoryReset; - using stick10::GetPasswordRetryCount; - using stick10::GetUserPasswordRetryCount; - using stick10::GetPasswordSafeSlotLogin; - using stick10::GetPasswordSafeSlotName; - using stick10::GetPasswordSafeSlotPassword; - using stick10::GetPasswordSafeSlotStatus; - using stick10::GetSlotName; - using stick10::IsAESSupported; - using stick10::LockDevice; - using stick10::PasswordSafeInitKey; - using stick10::PasswordSafeSendSlotViaHID; - using stick10::SetPasswordSafeSlotData; - using stick10::SetPasswordSafeSlotData2; - using stick10::UnlockUserPassword; - using stick10::ReadSlot; + namespace NKPro_08 { + using NKPro::FirstAuthenticate; + using NKPro::UserAuthenticate; + using NKPro::SetTime; + using NKPro::GetStatus; + using NKPro::BuildAESKey; + using NKPro::ChangeAdminPin; + using NKPro::ChangeUserPin; + using NKPro::EnablePasswordSafe; + using NKPro::ErasePasswordSafeSlot; + using NKPro::FactoryReset; + using NKPro::GetPasswordRetryCount; + using NKPro::GetUserPasswordRetryCount; + using NKPro::GetPasswordSafeSlotLogin; + using NKPro::GetPasswordSafeSlotName; + using NKPro::GetPasswordSafeSlotPassword; + using NKPro::GetPasswordSafeSlotStatus; + using NKPro::GetSlotName; + using NKPro::IsAESSupported; + using NKPro::LockDevice; + using NKPro::PasswordSafeInitKey; + using NKPro::PasswordSafeSendSlotViaHID; + using NKPro::SetPasswordSafeSlotData; + using NKPro::SetPasswordSafeSlotData2; + using NKPro::UnlockUserPassword; + using NKPro::ReadSlot; class EraseSlot : Command { public: @@ -309,4 +309,4 @@ namespace nitrokey { } } } -#endif //LIBNITROKEY_STICK10_COMMANDS_0_8_H +#endif //LIBNITROKEY_NKPRO_COMMANDS_0_8_H diff --git a/include/stick20_commands.h b/include/NKStorage_commands.h similarity index 98% rename from include/stick20_commands.h rename to include/NKStorage_commands.h index 61758f68..ba09b2aa 100644 --- a/include/stick20_commands.h +++ b/include/NKStorage_commands.h @@ -1,5 +1,5 @@ -#ifndef STICK20_COMMANDS_H -#define STICK20_COMMANDS_H +#ifndef NKSTORAGE_COMMANDS_H +#define NKSTORAGE_COMMANDS_H @@ -15,11 +15,11 @@ namespace nitrokey { namespace proto { /* -* STICK20 protocol command ids -* a superset (almost) of STICK10 +* NKSTORAGE protocol command ids +* a superset (almost) of NKPRO */ #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); - namespace stick20 { + namespace NKStorage { class ChangeAdminUserPin20Current : public PasswordCommand {}; diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 51cd9663..2edb0a4b 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -4,17 +4,17 @@ #include "device.h" #include "log.h" #include "device_proto.h" -#include "stick10_commands.h" -#include "stick10_commands_0.8.h" -#include "stick20_commands.h" +#include "NKPro_commands.h" +#include "NKPro_commands_0.8.h" +#include "NKStorage_commands.h" #include #include namespace nitrokey { using namespace nitrokey::device; using namespace std; - using namespace nitrokey::proto::stick10; - using namespace nitrokey::proto::stick20; + using namespace nitrokey::proto::NKPro; + using namespace nitrokey::proto::NKStorage; using namespace nitrokey::proto; using namespace nitrokey::log; @@ -34,8 +34,8 @@ namespace nitrokey { uint8_t last_interval, const char *user_temporary_password); string get_TOTP_code(uint8_t slot_number, const char *user_temporary_password); - stick10::ReadSlot::ResponsePayload get_TOTP_slot_data(const uint8_t slot_number); - stick10::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number); + NKPro::ReadSlot::ResponsePayload get_TOTP_slot_data(const uint8_t slot_number); + NKPro::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number); bool set_time(uint64_t time); bool get_time(uint64_t time = 0); @@ -50,7 +50,7 @@ namespace nitrokey { DeviceModel get_connected_device_model() const; void set_debug(bool state); - stick10::GetStatus::ResponsePayload get_status(); + NKPro::GetStatus::ResponsePayload get_status(); string get_status_as_string(); string get_serial_number(); @@ -121,7 +121,7 @@ namespace nitrokey { void send_startup(uint64_t seconds_from_epoch); const char * get_status_storage_as_string(); - stick20::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage(); + NKStorage::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage(); const char *get_SD_usage_data_as_string(); std::pair get_SD_usage_data(); @@ -145,7 +145,7 @@ namespace nitrokey { static shared_ptr _instance; std::shared_ptr device; - stick10::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number); + NKPro::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number); bool is_valid_hotp_slot_number(uint8_t slot_number) const; bool is_valid_totp_slot_number(uint8_t slot_number) const; bool is_valid_password_safe_slot_number(uint8_t slot_number) const; diff --git a/include/command.h b/include/command.h index fc374f72..be3c7878 100644 --- a/include/command.h +++ b/include/command.h @@ -19,7 +19,7 @@ namespace nitrokey { }; #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); -namespace stick20{ +namespace NKStorage{ enum class PasswordKind : uint8_t { User = 'P', Admin = 'A', diff --git a/include/command_id.h b/include/command_id.h index d1246dd4..cde75f13 100644 --- a/include/command_id.h +++ b/include/command_id.h @@ -4,7 +4,7 @@ namespace nitrokey { namespace proto { - namespace stick20 { + namespace NKStorage { enum class device_status : uint8_t { idle = 0, ok, @@ -19,7 +19,7 @@ namespace proto { const int CMD_START_VALUE = 0x20; const int CMD_END_VALUE = 0x60; } - namespace stick10 { + namespace NKPro { enum class command_status : uint8_t { ok = 0, wrong_CRC, diff --git a/include/device.h b/include/device.h index 8bc661a1..b928dc29 100644 --- a/include/device.h +++ b/include/device.h @@ -127,15 +127,15 @@ class Device { static std::chrono::milliseconds default_delay ; }; -class Stick10 : public Device { +class Device_NKPro : public Device { public: - Stick10(); + Device_NKPro(); }; -class Stick20 : public Device { +class Device_NKStorage : public Device { public: - Stick20(); + Device_NKStorage(); }; } } diff --git a/include/device_proto.h b/include/device_proto.h index 964c2d9d..ac67a096 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -17,8 +17,8 @@ #include "CommandFailedException.h" #include "LongOperationInProgressException.h" -#define STICK20_UPDATE_MODE_VID 0x03EB -#define STICK20_UPDATE_MODE_PID 0x2FF1 +#define NKSTORAGE_UPDATE_MODE_VID 0x03EB +#define NKSTORAGE_UPDATE_MODE_PID 0x2FF1 #define PAYLOAD_SIZE 53 #define PWS_SLOT_COUNT 16 @@ -120,7 +120,7 @@ namespace nitrokey { uint8_t _storage_status_padding[storage_status_padding_size]; uint8_t command_counter; uint8_t command_id; - uint8_t device_status; //@see stick20::device_status + uint8_t device_status; //@see NKStorage::device_status uint8_t progress_bar_value; } __packed storage_status; } __packed; @@ -268,24 +268,24 @@ namespace nitrokey { status = dev->recv(&resp); if (dev->get_device_model() == DeviceModel::STORAGE && - resp.command_id >= stick20::CMD_START_VALUE && - resp.command_id < stick20::CMD_END_VALUE ) { + resp.command_id >= NKStorage::CMD_START_VALUE && + resp.command_id < NKStorage::CMD_END_VALUE ) { LOG(std::string("Detected storage device cmd, status: ") + std::to_string(resp.storage_status.device_status), Loglevel::DEBUG_L2); - resp.last_command_status = static_cast(stick10::command_status::ok); - switch (static_cast(resp.storage_status.device_status)) { - case stick20::device_status::idle : - case stick20::device_status::ok: - resp.device_status = static_cast(stick10::device_status::ok); + resp.last_command_status = static_cast(NKPro::command_status::ok); + switch (static_cast(resp.storage_status.device_status)) { + case NKStorage::device_status::idle : + case NKStorage::device_status::ok: + resp.device_status = static_cast(NKPro::device_status::ok); break; - case stick20::device_status::busy: - case stick20::device_status::busy_progressbar: //TODO this will be modified later for getting progressbar status - resp.device_status = static_cast(stick10::device_status::busy); + case NKStorage::device_status::busy: + case NKStorage::device_status::busy_progressbar: //TODO this will be modified later for getting progressbar status + resp.device_status = static_cast(NKPro::device_status::busy); break; - case stick20::device_status::wrong_password: - resp.last_command_status = static_cast(stick10::command_status::wrong_password); - resp.device_status = static_cast(stick10::device_status::ok); + case NKStorage::device_status::wrong_password: + resp.last_command_status = static_cast(NKPro::command_status::wrong_password); + resp.device_status = static_cast(NKPro::device_status::ok); break; default: LOG(std::string("Unknown storage device status, cannot translate: ") + @@ -298,12 +298,12 @@ namespace nitrokey { //SENDPASSWORD gives wrong CRC , for now rely on !=0 (TODO report) // if (resp.device_status == 0 && resp.last_command_crc == outp.crc && resp.isCRCcorrect()) break; auto CRC_equal_awaited = resp.last_command_crc == outp.crc; - if (resp.device_status == static_cast(stick10::device_status::ok) && + if (resp.device_status == static_cast(NKPro::device_status::ok) && CRC_equal_awaited && resp.isValid()){ successful_communication = true; break; } - if (resp.device_status == static_cast(stick10::device_status::busy)) { + if (resp.device_status == static_cast(NKPro::device_status::busy)) { dev->m_counters.busy++; if (busy_counter++<10) { receiving_retry_counter++; @@ -317,9 +317,9 @@ namespace nitrokey { + std::to_string(retry_timeout.count()), Loglevel::DEBUG); } } - if (resp.device_status == static_cast(stick10::device_status::busy) && - static_cast(resp.storage_status.device_status) - == stick20::device_status::busy_progressbar){ + if (resp.device_status == static_cast(NKPro::device_status::busy) && + static_cast(resp.storage_status.device_status) + == NKStorage::device_status::busy_progressbar){ successful_communication = true; break; } @@ -363,9 +363,9 @@ namespace nitrokey { LOG(std::string("receiving_retry_counter count: ") + std::to_string(receiving_retry_counter), Loglevel::DEBUG); - if (resp.device_status == static_cast(stick10::device_status::busy) && - static_cast(resp.storage_status.device_status) - == stick20::device_status::busy_progressbar){ + if (resp.device_status == static_cast(NKPro::device_status::busy) && + static_cast(resp.storage_status.device_status) + == NKStorage::device_status::busy_progressbar){ dev->m_counters.busy_progressbar++; throw LongOperationInProgressException( resp.command_id, resp.device_status, resp.storage_status.progress_bar_value); @@ -377,7 +377,7 @@ namespace nitrokey { "Maximum receiving_retry_counter count reached for receiving response from the device!"); dev->m_counters.communication_successful++; - if (resp.last_command_status != static_cast(stick10::command_status::ok)){ + if (resp.last_command_status != static_cast(NKPro::command_status::ok)){ dev->m_counters.command_result_not_equal_0_recv++; throw CommandFailedException(resp.command_id, resp.last_command_status); } @@ -385,8 +385,8 @@ namespace nitrokey { dev->m_counters.command_successful_recv++; if (dev->get_device_model() == DeviceModel::STORAGE && - resp.command_id >= stick20::CMD_START_VALUE && - resp.command_id < stick20::CMD_END_VALUE ) { + resp.command_id >= NKStorage::CMD_START_VALUE && + resp.command_id < NKStorage::CMD_END_VALUE ) { dev->m_counters.successful_storage_commands++; } diff --git a/include/dissect.h b/include/dissect.h index 8992c561..fe12464b 100644 --- a/include/dissect.h +++ b/include/dissect.h @@ -43,12 +43,12 @@ template class ResponseDissector : semantics::non_constructible { public: static std::string status_translate_device(int status){ - auto enum_status = static_cast(status); + auto enum_status = static_cast(status); switch (enum_status){ - case stick10::device_status::ok: return "OK"; - case stick10::device_status::busy: return "BUSY"; - case stick10::device_status::error: return "ERROR"; - case stick10::device_status::received_report: return "RECEIVED_REPORT"; + case NKPro::device_status::ok: return "OK"; + case NKPro::device_status::busy: return "BUSY"; + case NKPro::device_status::error: return "ERROR"; + case NKPro::device_status::received_report: return "RECEIVED_REPORT"; } return std::string("UNKNOWN: ") + std::to_string(status); } @@ -58,20 +58,20 @@ class ResponseDissector : semantics::non_constructible { return str; } static std::string status_translate_command(int status){ - auto enum_status = static_cast(status); + auto enum_status = static_cast(status); switch (enum_status) { #define p(X) case X: return to_upper(std::string(#X)); - p(stick10::command_status::ok) - p(stick10::command_status::wrong_CRC) - p(stick10::command_status::wrong_slot) - p(stick10::command_status::slot_not_programmed) - p(stick10::command_status::wrong_password) - p(stick10::command_status::not_authorized) - p(stick10::command_status::timestamp_warning) - p(stick10::command_status::no_name_error) - p(stick10::command_status::not_supported) - p(stick10::command_status::unknown_command) - p(stick10::command_status::AES_dec_failed) + p(NKPro::command_status::ok) + p(NKPro::command_status::wrong_CRC) + p(NKPro::command_status::wrong_slot) + p(NKPro::command_status::slot_not_programmed) + p(NKPro::command_status::wrong_password) + p(NKPro::command_status::not_authorized) + p(NKPro::command_status::timestamp_warning) + p(NKPro::command_status::no_name_error) + p(NKPro::command_status::not_supported) + p(NKPro::command_status::unknown_command) + p(NKPro::command_status::AES_dec_failed) #undef p } return std::string("UNKNOWN: ") + std::to_string(status); diff --git a/unittest/test.cc b/unittest/test.cc index 15235bda..c877d33f 100644 --- a/unittest/test.cc +++ b/unittest/test.cc @@ -4,15 +4,15 @@ #include #include "device_proto.h" #include "log.h" -#include "stick10_commands.h" +#include "NKPro_commands.h" using namespace std; using namespace nitrokey::device; -using namespace nitrokey::proto::stick10; +using namespace nitrokey::proto::NKPro; using namespace nitrokey::log; using namespace nitrokey::misc; -using Dev10 = std::shared_ptr; +using Dev10 = std::shared_ptr; std::string getSlotName(Dev10 stick, int slotNo) { auto slot_req = get_payload(); @@ -23,7 +23,7 @@ std::string getSlotName(Dev10 stick, int slotNo) { } TEST_CASE("Slot names are correct", "[slotNames]") { - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); diff --git a/unittest/test2.cc b/unittest/test2.cc index 31dbce8f..e477afa4 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -9,13 +9,13 @@ static const char *const default_user_pin = "123456"; #include #include "device_proto.h" #include "log.h" -//#include "stick10_commands.h" -#include "stick20_commands.h" +//#include "NKPro_commands.h" +#include "NKStorage_commands.h" using namespace std; using namespace nitrokey::device; using namespace nitrokey::proto; -using namespace nitrokey::proto::stick20; +using namespace nitrokey::proto::NKStorage; using namespace nitrokey::log; using namespace nitrokey::misc; @@ -47,7 +47,7 @@ void SKIP_TEST() { TEST_CASE("long operation test", "[test_long]") { SKIP_TEST(); - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -67,7 +67,7 @@ TEST_CASE("long operation test", "[test_long]") { for (int i = 0; i < 30; ++i) { try { - stick10::GetStatus::CommandTransaction::run(stick); + NKPro::GetStatus::CommandTransaction::run(stick); } catch (LongOperationInProgressException &progressException){ CHECK((int)progressException.progress_bar_value>=0); @@ -84,62 +84,62 @@ TEST_CASE("long operation test", "[test_long]") { TEST_CASE("test device commands ids", "[fast]") { -// REQUIRE(STICK20_CMD_START_VALUE == static_cast(CommandID::START_VALUE)); - REQUIRE(STICK20_CMD_ENABLE_CRYPTED_PARI == static_cast(CommandID::ENABLE_CRYPTED_PARI)); - REQUIRE(STICK20_CMD_DISABLE_CRYPTED_PARI == static_cast(CommandID::DISABLE_CRYPTED_PARI)); - REQUIRE(STICK20_CMD_ENABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::ENABLE_HIDDEN_CRYPTED_PARI)); - REQUIRE(STICK20_CMD_DISABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::DISABLE_HIDDEN_CRYPTED_PARI)); - REQUIRE(STICK20_CMD_ENABLE_FIRMWARE_UPDATE == static_cast(CommandID::ENABLE_FIRMWARE_UPDATE)); - REQUIRE(STICK20_CMD_EXPORT_FIRMWARE_TO_FILE == static_cast(CommandID::EXPORT_FIRMWARE_TO_FILE)); - REQUIRE(STICK20_CMD_GENERATE_NEW_KEYS == static_cast(CommandID::GENERATE_NEW_KEYS)); - REQUIRE(STICK20_CMD_FILL_SD_CARD_WITH_RANDOM_CHARS == static_cast(CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS)); +// REQUIRE(NKSTORAGE_CMD_START_VALUE == static_cast(CommandID::START_VALUE)); + REQUIRE(NKSTORAGE_CMD_ENABLE_CRYPTED_PARI == static_cast(CommandID::ENABLE_CRYPTED_PARI)); + REQUIRE(NKSTORAGE_CMD_DISABLE_CRYPTED_PARI == static_cast(CommandID::DISABLE_CRYPTED_PARI)); + REQUIRE(NKSTORAGE_CMD_ENABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::ENABLE_HIDDEN_CRYPTED_PARI)); + REQUIRE(NKSTORAGE_CMD_DISABLE_HIDDEN_CRYPTED_PARI == static_cast(CommandID::DISABLE_HIDDEN_CRYPTED_PARI)); + REQUIRE(NKSTORAGE_CMD_ENABLE_FIRMWARE_UPDATE == static_cast(CommandID::ENABLE_FIRMWARE_UPDATE)); + REQUIRE(NKSTORAGE_CMD_EXPORT_FIRMWARE_TO_FILE == static_cast(CommandID::EXPORT_FIRMWARE_TO_FILE)); + REQUIRE(NKSTORAGE_CMD_GENERATE_NEW_KEYS == static_cast(CommandID::GENERATE_NEW_KEYS)); + REQUIRE(NKSTORAGE_CMD_FILL_SD_CARD_WITH_RANDOM_CHARS == static_cast(CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS)); - REQUIRE(STICK20_CMD_WRITE_STATUS_DATA == static_cast(CommandID::WRITE_STATUS_DATA)); - REQUIRE(STICK20_CMD_ENABLE_READONLY_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READONLY_UNCRYPTED_LUN)); - REQUIRE(STICK20_CMD_ENABLE_READWRITE_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READWRITE_UNCRYPTED_LUN)); + REQUIRE(NKSTORAGE_CMD_WRITE_STATUS_DATA == static_cast(CommandID::WRITE_STATUS_DATA)); + REQUIRE(NKSTORAGE_CMD_ENABLE_READONLY_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READONLY_UNCRYPTED_LUN)); + REQUIRE(NKSTORAGE_CMD_ENABLE_READWRITE_UNCRYPTED_LUN == static_cast(CommandID::ENABLE_READWRITE_UNCRYPTED_LUN)); - REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX == static_cast(CommandID::SEND_PASSWORD_MATRIX)); - REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX_PINDATA == static_cast(CommandID::SEND_PASSWORD_MATRIX_PINDATA)); - REQUIRE(STICK20_CMD_SEND_PASSWORD_MATRIX_SETUP == static_cast(CommandID::SEND_PASSWORD_MATRIX_SETUP)); + REQUIRE(NKSTORAGE_CMD_SEND_PASSWORD_MATRIX == static_cast(CommandID::SEND_PASSWORD_MATRIX)); + REQUIRE(NKSTORAGE_CMD_SEND_PASSWORD_MATRIX_PINDATA == static_cast(CommandID::SEND_PASSWORD_MATRIX_PINDATA)); + REQUIRE(NKSTORAGE_CMD_SEND_PASSWORD_MATRIX_SETUP == static_cast(CommandID::SEND_PASSWORD_MATRIX_SETUP)); - REQUIRE(STICK20_CMD_GET_DEVICE_STATUS == static_cast(CommandID::GET_DEVICE_STATUS)); - REQUIRE(STICK20_CMD_SEND_DEVICE_STATUS == static_cast(CommandID::SEND_DEVICE_STATUS)); + REQUIRE(NKSTORAGE_CMD_GET_DEVICE_STATUS == static_cast(CommandID::GET_DEVICE_STATUS)); + REQUIRE(NKSTORAGE_CMD_SEND_DEVICE_STATUS == static_cast(CommandID::SEND_DEVICE_STATUS)); - REQUIRE(STICK20_CMD_SEND_HIDDEN_VOLUME_PASSWORD == static_cast(CommandID::SEND_HIDDEN_VOLUME_PASSWORD)); - REQUIRE(STICK20_CMD_SEND_HIDDEN_VOLUME_SETUP == static_cast(CommandID::SEND_HIDDEN_VOLUME_SETUP)); - REQUIRE(STICK20_CMD_SEND_PASSWORD == static_cast(CommandID::SEND_PASSWORD)); - REQUIRE(STICK20_CMD_SEND_NEW_PASSWORD == static_cast(CommandID::SEND_NEW_PASSWORD)); - REQUIRE(STICK20_CMD_CLEAR_NEW_SD_CARD_FOUND == static_cast(CommandID::CLEAR_NEW_SD_CARD_FOUND)); + REQUIRE(NKSTORAGE_CMD_SEND_HIDDEN_VOLUME_PASSWORD == static_cast(CommandID::SEND_HIDDEN_VOLUME_PASSWORD)); + REQUIRE(NKSTORAGE_CMD_SEND_HIDDEN_VOLUME_SETUP == static_cast(CommandID::SEND_HIDDEN_VOLUME_SETUP)); + REQUIRE(NKSTORAGE_CMD_SEND_PASSWORD == static_cast(CommandID::SEND_PASSWORD)); + REQUIRE(NKSTORAGE_CMD_SEND_NEW_PASSWORD == static_cast(CommandID::SEND_NEW_PASSWORD)); + REQUIRE(NKSTORAGE_CMD_CLEAR_NEW_SD_CARD_FOUND == static_cast(CommandID::CLEAR_NEW_SD_CARD_FOUND)); - REQUIRE(STICK20_CMD_SEND_STARTUP == static_cast(CommandID::SEND_STARTUP)); - REQUIRE(STICK20_CMD_SEND_CLEAR_STICK_KEYS_NOT_INITIATED == static_cast(CommandID::SEND_CLEAR_STICK_KEYS_NOT_INITIATED)); - REQUIRE(STICK20_CMD_SEND_LOCK_STICK_HARDWARE == static_cast(CommandID::SEND_LOCK_STICK_HARDWARE)); + REQUIRE(NKSTORAGE_CMD_SEND_STARTUP == static_cast(CommandID::SEND_STARTUP)); + REQUIRE(NKSTORAGE_CMD_SEND_CLEAR_STICK_KEYS_NOT_INITIATED == static_cast(CommandID::SEND_CLEAR_STICK_KEYS_NOT_INITIATED)); + REQUIRE(NKSTORAGE_CMD_SEND_LOCK_STICK_HARDWARE == static_cast(CommandID::SEND_LOCK_STICK_HARDWARE)); - REQUIRE(STICK20_CMD_PRODUCTION_TEST == static_cast(CommandID::PRODUCTION_TEST)); - REQUIRE(STICK20_CMD_SEND_DEBUG_DATA == static_cast(CommandID::SEND_DEBUG_DATA)); + REQUIRE(NKSTORAGE_CMD_PRODUCTION_TEST == static_cast(CommandID::PRODUCTION_TEST)); + REQUIRE(NKSTORAGE_CMD_SEND_DEBUG_DATA == static_cast(CommandID::SEND_DEBUG_DATA)); - REQUIRE(STICK20_CMD_CHANGE_UPDATE_PIN == static_cast(CommandID::CHANGE_UPDATE_PIN)); + REQUIRE(NKSTORAGE_CMD_CHANGE_UPDATE_PIN == static_cast(CommandID::CHANGE_UPDATE_PIN)); } TEST_CASE("test device internal status with various commands", "[fast]") { - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); - auto p = get_payload(); + auto p = get_payload(); p.set_defaults(); - auto device_status = stick20::SendStartup::CommandTransaction::run(stick, p); + auto device_status = NKStorage::SendStartup::CommandTransaction::run(stick, p); REQUIRE(device_status.data().AdminPwRetryCount == 3); REQUIRE(device_status.data().UserPwRetryCount == 3); REQUIRE(device_status.data().ActiveSmartCardID_u32 != 0); - auto production_status = stick20::ProductionTest::CommandTransaction::run(stick); + auto production_status = NKStorage::ProductionTest::CommandTransaction::run(stick); REQUIRE(production_status.data().SD_Card_Size_u8 == 8); REQUIRE(production_status.data().SD_CardID_u32 != 0); - auto sdcard_occupancy = stick20::GetSDCardOccupancy::CommandTransaction::run(stick); + auto sdcard_occupancy = NKStorage::GetSDCardOccupancy::CommandTransaction::run(stick); REQUIRE((int) sdcard_occupancy.data().ReadLevelMin >= 0); REQUIRE((int) sdcard_occupancy.data().ReadLevelMax <= 100); REQUIRE((int) sdcard_occupancy.data().WriteLevelMin >= 0); @@ -147,48 +147,48 @@ TEST_CASE("test device internal status with various commands", "[fast]") { } TEST_CASE("setup hidden volume test", "[hidden]") { - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); - stick10::LockDevice::CommandTransaction::run(stick); + NKPro::LockDevice::CommandTransaction::run(stick); this_thread::sleep_for(2000ms); auto user_pin = default_user_pin; execute_password_command(stick, user_pin); - auto p = get_payload(); + auto p = get_payload(); p.SlotNr_u8 = 0; p.StartBlockPercent_u8 = 70; p.EndBlockPercent_u8 = 90; auto hidden_volume_password = "123123123"; strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password); - stick20::SetupHiddenVolume::CommandTransaction::run(stick, p); + NKStorage::SetupHiddenVolume::CommandTransaction::run(stick, p); this_thread::sleep_for(2000ms); execute_password_command(stick, hidden_volume_password); } TEST_CASE("setup multiple hidden volumes", "[hidden]") { - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); auto user_pin = default_user_pin; - stick10::LockDevice::CommandTransaction::run(stick); + NKPro::LockDevice::CommandTransaction::run(stick); this_thread::sleep_for(2000ms); execute_password_command(stick, user_pin); constexpr int volume_count = 4; for (int i = 0; i < volume_count; ++i) { - auto p = get_payload(); + auto p = get_payload(); p.SlotNr_u8 = i; p.StartBlockPercent_u8 = 20 + 10*i; p.EndBlockPercent_u8 = p.StartBlockPercent_u8+i+1; auto hidden_volume_password = std::string("123123123")+std::to_string(i); strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password.c_str()); - stick20::SetupHiddenVolume::CommandTransaction::run(stick, p); + NKStorage::SetupHiddenVolume::CommandTransaction::run(stick, p); this_thread::sleep_for(2000ms); } @@ -207,7 +207,7 @@ TEST_CASE("setup multiple hidden volumes", "[hidden]") { TEST_CASE("update password change", "[dangerous]") { SKIP_TEST(); - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -220,21 +220,21 @@ TEST_CASE("update password change", "[dangerous]") { make_pair(pass2, pass1), }; for (auto && password: data) { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.current_update_password, password.first); strcpyT(p.new_update_password, password.second); - stick20::ChangeUpdatePassword::CommandTransaction::run(stick, p); + NKStorage::ChangeUpdatePassword::CommandTransaction::run(stick, p); } } TEST_CASE("general test", "[test]") { - auto stick = make_shared(); + auto stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); - stick10::LockDevice::CommandTransaction::run(stick); + NKPro::LockDevice::CommandTransaction::run(stick); // execute_password_command(stick, "123456"); // execute_password_command(stick, "123456"); // execute_password_command(stick, "123123123"); @@ -242,7 +242,7 @@ TEST_CASE("general test", "[test]") { execute_password_command(stick, default_user_pin); execute_password_command(stick, default_user_pin); execute_password_command(stick, default_admin_pin, 'A'); - stick20::GetDeviceStatus::CommandTransaction::run(stick); + NKStorage::GetDeviceStatus::CommandTransaction::run(stick); this_thread::sleep_for(1000ms); // execute_password_command(stick, "123123123"); //CAUTION // execute_password_command(stick, "123123123"); //CAUTION FIRMWARE PIN @@ -250,5 +250,5 @@ TEST_CASE("general test", "[test]") { execute_password_command(stick, "12345678", 'A'); // execute_password_command(stick, "12345678", 'A'); - stick10::LockDevice::CommandTransaction::run(stick); + NKPro::LockDevice::CommandTransaction::run(stick); } diff --git a/unittest/test3.cc b/unittest/test3.cc index 9e0ef118..cfb63a04 100644 --- a/unittest/test3.cc +++ b/unittest/test3.cc @@ -11,17 +11,17 @@ const char * RFC_SECRET = "12345678901234567890"; #include #include "device_proto.h" #include "log.h" -#include "stick10_commands_0.8.h" -//#include "stick20_commands.h" +#include "NKPro_commands_0.8.h" +//#include "NKStorage_commands.h" using namespace std; using namespace nitrokey::device; using namespace nitrokey::proto; -using namespace nitrokey::proto::stick10_08; +using namespace nitrokey::proto::NKPro_08; using namespace nitrokey::log; using namespace nitrokey::misc; -using Dev = Stick10; +using Dev = Device_NKPro; using Dev10 = std::shared_ptr; void connect_and_setup(Dev10 stick) { @@ -52,20 +52,20 @@ TEST_CASE("write slot", "[pronew]"){ strcpyT(p2.temporary_admin_password, temporary_password); p2.setTypeName(); strcpyT(p2.data, "test name aaa"); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); p2 = get_payload(); strcpyT(p2.temporary_admin_password, temporary_password); strcpyT(p2.data, RFC_SECRET); p2.setTypeSecret(); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); auto p = get_payload(); strcpyT(p.temporary_admin_password, temporary_password); p.use_8_digits = true; p.slot_number = 0 + 0x10; p.slot_counter_or_interval = 0; - stick10_08::WriteToOTPSlot::CommandTransaction::run(stick, p); + NKPro_08::WriteToOTPSlot::CommandTransaction::run(stick, p); auto pc = get_payload(); pc.enable_user_password = 0; @@ -135,20 +135,20 @@ TEST_CASE("authorize user HOTP", "[pronew]") { strcpyT(p2.temporary_admin_password, temporary_password); p2.setTypeName(); strcpyT(p2.data, "test name aaa"); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); p2 = get_payload(); strcpyT(p2.temporary_admin_password, temporary_password); strcpyT(p2.data, RFC_SECRET); p2.setTypeSecret(); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); auto p = get_payload(); strcpyT(p.temporary_admin_password, temporary_password); p.use_8_digits = true; p.slot_number = 0 + 0x10; p.slot_counter_or_interval = 0; - stick10_08::WriteToOTPSlot::CommandTransaction::run(stick, p); + NKPro_08::WriteToOTPSlot::CommandTransaction::run(stick, p); auto p3 = get_payload(); @@ -186,20 +186,20 @@ TEST_CASE("authorize user TOTP", "[pronew]") { strcpyT(p2.temporary_admin_password, temporary_password); p2.setTypeName(); strcpyT(p2.data, "test name TOTP"); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); p2 = get_payload(); strcpyT(p2.temporary_admin_password, temporary_password); strcpyT(p2.data, RFC_SECRET); p2.setTypeSecret(); - stick10_08::SendOTPData::CommandTransaction::run(stick, p2); + NKPro_08::SendOTPData::CommandTransaction::run(stick, p2); auto p = get_payload(); strcpyT(p.temporary_admin_password, temporary_password); p.use_8_digits = true; p.slot_number = 0 + 0x20; p.slot_counter_or_interval = 30; - stick10_08::WriteToOTPSlot::CommandTransaction::run(stick, p); + NKPro_08::WriteToOTPSlot::CommandTransaction::run(stick, p); auto p_get_totp = get_payload(); p_get_totp.slot_number = 0 + 0x20; diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index e6f7d7cc..e1d682b5 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -2,13 +2,13 @@ #include #include "device_proto.h" #include "log.h" -#include "stick10_commands.h" +#include "NKPro_commands.h" #include #include "misc.h" using namespace std; using namespace nitrokey::device; -using namespace nitrokey::proto::stick10; +using namespace nitrokey::proto::NKPro; using namespace nitrokey::log; using namespace nitrokey::misc; @@ -33,7 +33,7 @@ TEST_CASE("test secret", "[functions]") { } TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { - std::shared_ptr stick = make_shared(); + std::shared_ptr stick = make_shared(); bool connected = stick->connect(); REQUIRE(connected == true); diff --git a/unittest/test_command_ids_header.h b/unittest/test_command_ids_header.h index cd55c8a2..56bc2d6c 100644 --- a/unittest/test_command_ids_header.h +++ b/unittest/test_command_ids_header.h @@ -1,41 +1,41 @@ #ifndef LIBNITROKEY_TEST_COMMAND_IDS_HEADER_H_H #define LIBNITROKEY_TEST_COMMAND_IDS_HEADER_H_H -#define STICK20_CMD_START_VALUE 0x20 -#define STICK20_CMD_ENABLE_CRYPTED_PARI (STICK20_CMD_START_VALUE + 0) -#define STICK20_CMD_DISABLE_CRYPTED_PARI (STICK20_CMD_START_VALUE + 1) -#define STICK20_CMD_ENABLE_HIDDEN_CRYPTED_PARI (STICK20_CMD_START_VALUE + 2) -#define STICK20_CMD_DISABLE_HIDDEN_CRYPTED_PARI (STICK20_CMD_START_VALUE + 3) -#define STICK20_CMD_ENABLE_FIRMWARE_UPDATE (STICK20_CMD_START_VALUE + 4) -#define STICK20_CMD_EXPORT_FIRMWARE_TO_FILE (STICK20_CMD_START_VALUE + 5) -#define STICK20_CMD_GENERATE_NEW_KEYS (STICK20_CMD_START_VALUE + 6) -#define STICK20_CMD_FILL_SD_CARD_WITH_RANDOM_CHARS (STICK20_CMD_START_VALUE + 7) - -#define STICK20_CMD_WRITE_STATUS_DATA (STICK20_CMD_START_VALUE + 8) -#define STICK20_CMD_ENABLE_READONLY_UNCRYPTED_LUN (STICK20_CMD_START_VALUE + 9) -#define STICK20_CMD_ENABLE_READWRITE_UNCRYPTED_LUN (STICK20_CMD_START_VALUE + 10) - -#define STICK20_CMD_SEND_PASSWORD_MATRIX (STICK20_CMD_START_VALUE + 11) -#define STICK20_CMD_SEND_PASSWORD_MATRIX_PINDATA (STICK20_CMD_START_VALUE + 12) -#define STICK20_CMD_SEND_PASSWORD_MATRIX_SETUP (STICK20_CMD_START_VALUE + 13) - -#define STICK20_CMD_GET_DEVICE_STATUS (STICK20_CMD_START_VALUE + 14) -#define STICK20_CMD_SEND_DEVICE_STATUS (STICK20_CMD_START_VALUE + 15) - -#define STICK20_CMD_SEND_HIDDEN_VOLUME_PASSWORD (STICK20_CMD_START_VALUE + 16) -#define STICK20_CMD_SEND_HIDDEN_VOLUME_SETUP (STICK20_CMD_START_VALUE + 17) -#define STICK20_CMD_SEND_PASSWORD (STICK20_CMD_START_VALUE + 18) -#define STICK20_CMD_SEND_NEW_PASSWORD (STICK20_CMD_START_VALUE + 19) -#define STICK20_CMD_CLEAR_NEW_SD_CARD_FOUND (STICK20_CMD_START_VALUE + 20) - -#define STICK20_CMD_SEND_STARTUP (STICK20_CMD_START_VALUE + 21) -#define STICK20_CMD_SEND_CLEAR_STICK_KEYS_NOT_INITIATED (STICK20_CMD_START_VALUE + 22) -#define STICK20_CMD_SEND_LOCK_STICK_HARDWARE (STICK20_CMD_START_VALUE + 23) - -#define STICK20_CMD_PRODUCTION_TEST (STICK20_CMD_START_VALUE + 24) -#define STICK20_CMD_SEND_DEBUG_DATA (STICK20_CMD_START_VALUE + 25) - -#define STICK20_CMD_CHANGE_UPDATE_PIN (STICK20_CMD_START_VALUE + 26) +#define NKSTORAGE_CMD_START_VALUE 0x20 +#define NKSTORAGE_CMD_ENABLE_CRYPTED_PARI (NKSTORAGE_CMD_START_VALUE + 0) +#define NKSTORAGE_CMD_DISABLE_CRYPTED_PARI (NKSTORAGE_CMD_START_VALUE + 1) +#define NKSTORAGE_CMD_ENABLE_HIDDEN_CRYPTED_PARI (NKSTORAGE_CMD_START_VALUE + 2) +#define NKSTORAGE_CMD_DISABLE_HIDDEN_CRYPTED_PARI (NKSTORAGE_CMD_START_VALUE + 3) +#define NKSTORAGE_CMD_ENABLE_FIRMWARE_UPDATE (NKSTORAGE_CMD_START_VALUE + 4) +#define NKSTORAGE_CMD_EXPORT_FIRMWARE_TO_FILE (NKSTORAGE_CMD_START_VALUE + 5) +#define NKSTORAGE_CMD_GENERATE_NEW_KEYS (NKSTORAGE_CMD_START_VALUE + 6) +#define NKSTORAGE_CMD_FILL_SD_CARD_WITH_RANDOM_CHARS (NKSTORAGE_CMD_START_VALUE + 7) + +#define NKSTORAGE_CMD_WRITE_STATUS_DATA (NKSTORAGE_CMD_START_VALUE + 8) +#define NKSTORAGE_CMD_ENABLE_READONLY_UNCRYPTED_LUN (NKSTORAGE_CMD_START_VALUE + 9) +#define NKSTORAGE_CMD_ENABLE_READWRITE_UNCRYPTED_LUN (NKSTORAGE_CMD_START_VALUE + 10) + +#define NKSTORAGE_CMD_SEND_PASSWORD_MATRIX (NKSTORAGE_CMD_START_VALUE + 11) +#define NKSTORAGE_CMD_SEND_PASSWORD_MATRIX_PINDATA (NKSTORAGE_CMD_START_VALUE + 12) +#define NKSTORAGE_CMD_SEND_PASSWORD_MATRIX_SETUP (NKSTORAGE_CMD_START_VALUE + 13) + +#define NKSTORAGE_CMD_GET_DEVICE_STATUS (NKSTORAGE_CMD_START_VALUE + 14) +#define NKSTORAGE_CMD_SEND_DEVICE_STATUS (NKSTORAGE_CMD_START_VALUE + 15) + +#define NKSTORAGE_CMD_SEND_HIDDEN_VOLUME_PASSWORD (NKSTORAGE_CMD_START_VALUE + 16) +#define NKSTORAGE_CMD_SEND_HIDDEN_VOLUME_SETUP (NKSTORAGE_CMD_START_VALUE + 17) +#define NKSTORAGE_CMD_SEND_PASSWORD (NKSTORAGE_CMD_START_VALUE + 18) +#define NKSTORAGE_CMD_SEND_NEW_PASSWORD (NKSTORAGE_CMD_START_VALUE + 19) +#define NKSTORAGE_CMD_CLEAR_NEW_SD_CARD_FOUND (NKSTORAGE_CMD_START_VALUE + 20) + +#define NKSTORAGE_CMD_SEND_STARTUP (NKSTORAGE_CMD_START_VALUE + 21) +#define NKSTORAGE_CMD_SEND_CLEAR_STICK_KEYS_NOT_INITIATED (NKSTORAGE_CMD_START_VALUE + 22) +#define NKSTORAGE_CMD_SEND_LOCK_STICK_HARDWARE (NKSTORAGE_CMD_START_VALUE + 23) + +#define NKSTORAGE_CMD_PRODUCTION_TEST (NKSTORAGE_CMD_START_VALUE + 24) +#define NKSTORAGE_CMD_SEND_DEBUG_DATA (NKSTORAGE_CMD_START_VALUE + 25) + +#define NKSTORAGE_CMD_CHANGE_UPDATE_PIN (NKSTORAGE_CMD_START_VALUE + 26) #endif //LIBNITROKEY_TEST_COMMAND_IDS_HEADER_H_H