aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NitrokeyManager.cc108
-rw-r--r--README.md2
-rw-r--r--include/CommandFailedException.h2
-rw-r--r--include/NKPro_commands.h2
-rw-r--r--include/NKPro_commands_0.8.h52
-rw-r--r--include/NKStorage_commands.h3
-rw-r--r--include/NitrokeyManager.h14
-rw-r--r--include/command.h2
-rw-r--r--include/command_id.h4
-rw-r--r--include/device_proto.h50
-rw-r--r--include/dissect.h34
-rw-r--r--unittest/test.cc2
-rw-r--r--unittest/test2.cc34
-rw-r--r--unittest/test3.cc24
-rw-r--r--unittest/test_HOTP.cc2
15 files changed, 167 insertions, 168 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index d491fa9..3ff34f2 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -194,7 +194,7 @@ using nitrokey::misc::strcpyT;
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;
@@ -202,7 +202,7 @@ using nitrokey::misc::strcpyT;
return "NA";
}
- stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){
+ NKPro::GetStatus::ResponsePayload NitrokeyManager::get_status(){
try{
auto response = GetStatus::CommandTransaction::run(device);
return response.data();
@@ -236,12 +236,12 @@ using nitrokey::misc::strcpyT;
auto resp = GetHOTP::CommandTransaction::run(device, gh);
return getFilledOTPCode(resp.data().code, resp.data().use_8_digits);
} else {
- auto gh = get_payload<stick10_08::GetHOTP>();
+ auto gh = get_payload<NKPro_08::GetHOTP>();
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 "";
@@ -273,10 +273,10 @@ using nitrokey::misc::strcpyT;
auto resp = GetTOTP::CommandTransaction::run(device, gt);
return getFilledOTPCode(resp.data().code, resp.data().use_8_digits);
} else {
- auto gt = get_payload<stick10_08::GetTOTP>();
+ auto gt = get_payload<NKPro_08::GetTOTP>();
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 "";
@@ -289,10 +289,10 @@ using nitrokey::misc::strcpyT;
authorize_packet<EraseSlot, Authorize>(p, temporary_password, device);
auto resp = EraseSlot::CommandTransaction::run(device,p);
} else {
- auto p = get_payload<stick10_08::EraseSlot>();
+ auto p = get_payload<NKPro_08::EraseSlot>();
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;
}
@@ -402,11 +402,11 @@ using nitrokey::misc::strcpyT;
bool use_tokenID, const char *token_ID,
const char *temporary_password) const {
- auto payload2 = get_payload<stick10_08::SendOTPData>();
+ auto payload2 = get_payload<NKPro_08::SendOTPData>();
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;
@@ -422,12 +422,12 @@ using nitrokey::misc::strcpyT;
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<stick10_08::WriteToOTPSlot>();
+ auto payload = get_payload<NKPro_08::WriteToOTPSlot>();
strcpyT(payload.temporary_admin_password, temporary_password);
strcpyT(payload.slot_token_id, token_ID);
payload.use_8_digits = use_8_digits;
@@ -435,7 +435,7 @@ using nitrokey::misc::strcpyT;
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,
@@ -558,7 +558,7 @@ using nitrokey::misc::strcpyT;
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;
@@ -566,7 +566,7 @@ using nitrokey::misc::strcpyT;
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;
@@ -640,10 +640,10 @@ using nitrokey::misc::strcpyT;
break;
}
case DeviceModel::STORAGE : {
- auto p = get_payload<stick20::CreateNewKeys>();
+ auto p = get_payload<NKStorage::CreateNewKeys>();
strcpyT(p.password, admin_password);
p.set_defaults();
- stick20::CreateNewKeys::CommandTransaction::run(device, p);
+ NKStorage::CreateNewKeys::CommandTransaction::run(device, p);
break;
}
}
@@ -658,10 +658,10 @@ using nitrokey::misc::strcpyT;
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<stick10::UnlockUserPassword>();
+ auto p = get_payload<NKPro::UnlockUserPassword>();
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 : {
@@ -669,10 +669,10 @@ using nitrokey::misc::strcpyT;
p2.set_defaults();
strcpyT(p2.password, admin_password);
ChangeAdminUserPin20Current::CommandTransaction::run(device, p2);
- auto p3 = get_payload<stick20::UnlockUserPin>();
+ auto p3 = get_payload<NKStorage::UnlockUserPin>();
p3.set_defaults();
strcpyT(p3.password, new_user_password);
- stick20::UnlockUserPin::CommandTransaction::run(device, p3);
+ NKStorage::UnlockUserPin::CommandTransaction::run(device, p3);
break;
}
}
@@ -681,18 +681,18 @@ using nitrokey::misc::strcpyT;
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<stick10_08::WriteGeneralConfig>();
+ auto p = get_payload<NKPro_08::WriteGeneralConfig>();
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<stick10_08::WriteGeneralConfig, Authorize>(p, admin_temporary_password, device);
+ authorize_packet<NKPro_08::WriteGeneralConfig, Authorize>(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<uint8_t> NitrokeyManager::read_config() {
@@ -735,7 +735,7 @@ using nitrokey::misc::strcpyT;
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;
}
}
@@ -752,89 +752,89 @@ using nitrokey::misc::strcpyT;
//storage commands
void NitrokeyManager::send_startup(uint64_t seconds_from_epoch){
- auto p = get_payload<stick20::SendStartup>();
+ auto p = get_payload<NKStorage::SendStartup>();
// 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<stick20::EnableEncryptedPartition>(device, user_pin);
+ misc::execute_password_command<NKStorage::EnableEncryptedPartition>(device, user_pin);
}
void NitrokeyManager::unlock_hidden_volume(const char* hidden_volume_password) {
- misc::execute_password_command<stick20::EnableHiddenEncryptedPartition>(device, hidden_volume_password);
+ misc::execute_password_command<NKStorage::EnableHiddenEncryptedPartition>(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<stick20::SetupHiddenVolume>();
+ auto p = get_payload<NKStorage::SetupHiddenVolume>();
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<stick20::SendSetReadonlyToUncryptedVolume>(device, user_pin);
+ misc::execute_password_command<NKStorage::SendSetReadonlyToUncryptedVolume>(device, user_pin);
}
void NitrokeyManager::set_unencrypted_read_write(const char* user_pin) {
- misc::execute_password_command<stick20::SendSetReadwriteToUncryptedVolume>(device, user_pin);
+ misc::execute_password_command<NKStorage::SendSetReadwriteToUncryptedVolume>(device, user_pin);
}
void NitrokeyManager::export_firmware(const char* admin_pin) {
- misc::execute_password_command<stick20::ExportFirmware>(device, admin_pin);
+ misc::execute_password_command<NKStorage::ExportFirmware>(device, admin_pin);
}
void NitrokeyManager::enable_firmware_update(const char* firmware_pin) {
- misc::execute_password_command<stick20::EnableFirmwareUpdate>(device, firmware_pin);
+ misc::execute_password_command<NKStorage::EnableFirmwareUpdate>(device, firmware_pin);
}
void NitrokeyManager::clear_new_sd_card_warning(const char* admin_pin) {
- misc::execute_password_command<stick20::SendClearNewSdCardFound>(device, admin_pin);
+ misc::execute_password_command<NKStorage::SendClearNewSdCardFound>(device, admin_pin);
}
void NitrokeyManager::fill_SD_card_with_random_data(const char* admin_pin) {
- auto p = get_payload<stick20::FillSDCardWithRandomChars>();
+ auto p = get_payload<NKStorage::FillSDCardWithRandomChars>();
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<stick20::ChangeUpdatePassword>();
+ auto p = get_payload<NKStorage::ChangeUpdatePassword>();
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<uint8_t,uint8_t> 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){
@@ -846,18 +846,18 @@ using nitrokey::misc::strcpyT;
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<stick10::ReadSlot>();
+ NKPro::ReadSlot::ResponsePayload NitrokeyManager::get_OTP_slot_data(const uint8_t slot_number) {
+ auto p = get_payload<NKPro::ReadSlot>();
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
@@ -868,15 +868,15 @@ using nitrokey::misc::strcpyT;
}
void NitrokeyManager::lock_encrypted_volume() {
- misc::execute_password_command<stick20::DisableEncryptedPartition>(device, "");
+ misc::execute_password_command<NKStorage::DisableEncryptedPartition>(device, "");
}
void NitrokeyManager::lock_hidden_volume() {
- misc::execute_password_command<stick20::DisableHiddenEncryptedPartition>(device, "");
+ misc::execute_password_command<NKStorage::DisableHiddenEncryptedPartition>(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 d0e1ce6..ce65da0 100644
--- a/README.md
+++ b/README.md
@@ -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/include/CommandFailedException.h b/include/CommandFailedException.h
index 417e850..8434301 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/NKPro_commands.h b/include/NKPro_commands.h
index e863328..1ed3d4f 100644
--- a/include/NKPro_commands.h
+++ b/include/NKPro_commands.h
@@ -19,7 +19,7 @@ namespace proto {
/*
* Stick10 protocol definition
*/
-namespace stick10 {
+namespace NKPro {
class GetSlotName : public Command<CommandID::READ_SLOT_NAME> {
public:
// reachable as a typedef in Transaction
diff --git a/include/NKPro_commands_0.8.h b/include/NKPro_commands_0.8.h
index 76bb030..2482dec 100644
--- a/include/NKPro_commands_0.8.h
+++ b/include/NKPro_commands_0.8.h
@@ -23,32 +23,32 @@ namespace nitrokey {
/*
* Stick10 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<CommandID::ERASE_SLOT> {
public:
diff --git a/include/NKStorage_commands.h b/include/NKStorage_commands.h
index 5f99d28..b375617 100644
--- a/include/NKStorage_commands.h
+++ b/include/NKStorage_commands.h
@@ -18,8 +18,7 @@ namespace nitrokey {
* STICK20 protocol command ids
* a superset (almost) of STICK10
*/
-
- namespace stick20 {
+ namespace NKStorage {
class ChangeAdminUserPin20Current :
public PasswordCommand<CommandID::SEND_PASSWORD, PasswordKind::Admin> {};
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index f6977d9..216ff88 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -13,8 +13,8 @@
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;
@@ -39,8 +39,8 @@ char * strndup(const char* str, size_t maxlen);
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);
@@ -55,7 +55,7 @@ char * strndup(const char* str, size_t maxlen);
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();
@@ -126,7 +126,7 @@ char * strndup(const char* str, size_t maxlen);
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<uint8_t,uint8_t> get_SD_usage_data();
@@ -150,7 +150,7 @@ char * strndup(const char* str, size_t maxlen);
static shared_ptr <NitrokeyManager> _instance;
std::shared_ptr<Device> 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 3f711c0..4710cbd 100644
--- a/include/command.h
+++ b/include/command.h
@@ -27,7 +27,7 @@ namespace nitrokey {
}
};
-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 d1246dd..cde75f1 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_proto.h b/include/device_proto.h
index b557384..4abb7b8 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -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;
@@ -269,24 +269,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<uint8_t>(stick10::command_status::ok);
- switch (static_cast<stick20::device_status>(resp.storage_status.device_status)) {
- case stick20::device_status::idle :
- case stick20::device_status::ok:
- resp.device_status = static_cast<uint8_t>(stick10::device_status::ok);
+ resp.last_command_status = static_cast<uint8_t>(NKPro::command_status::ok);
+ switch (static_cast<NKStorage::device_status>(resp.storage_status.device_status)) {
+ case NKStorage::device_status::idle :
+ case NKStorage::device_status::ok:
+ resp.device_status = static_cast<uint8_t>(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<uint8_t>(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<uint8_t>(NKPro::device_status::busy);
break;
- case stick20::device_status::wrong_password:
- resp.last_command_status = static_cast<uint8_t>(stick10::command_status::wrong_password);
- resp.device_status = static_cast<uint8_t>(stick10::device_status::ok);
+ case NKStorage::device_status::wrong_password:
+ resp.last_command_status = static_cast<uint8_t>(NKPro::command_status::wrong_password);
+ resp.device_status = static_cast<uint8_t>(NKPro::device_status::ok);
break;
default:
LOG(std::string("Unknown storage device status, cannot translate: ") +
@@ -299,12 +299,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<uint8_t>(stick10::device_status::ok) &&
+ if (resp.device_status == static_cast<uint8_t>(NKPro::device_status::ok) &&
CRC_equal_awaited && resp.isValid()){
successful_communication = true;
break;
}
- if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy)) {
+ if (resp.device_status == static_cast<uint8_t>(NKPro::device_status::busy)) {
dev->m_counters.busy++;
if (busy_counter++<10) {
receiving_retry_counter++;
@@ -318,9 +318,9 @@ namespace nitrokey {
+ std::to_string(retry_timeout.count()), Loglevel::DEBUG);
}
}
- if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy) &&
- static_cast<stick20::device_status>(resp.storage_status.device_status)
- == stick20::device_status::busy_progressbar){
+ if (resp.device_status == static_cast<uint8_t>(NKPro::device_status::busy) &&
+ static_cast<NKStorage::device_status>(resp.storage_status.device_status)
+ == NKStorage::device_status::busy_progressbar){
successful_communication = true;
break;
}
@@ -371,9 +371,9 @@ namespace nitrokey {
LOG(std::string("receiving_retry_counter count: ") + std::to_string(receiving_retry_counter),
Loglevel::DEBUG_L2);
- if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy) &&
- static_cast<stick20::device_status>(resp.storage_status.device_status)
- == stick20::device_status::busy_progressbar){
+ if (resp.device_status == static_cast<uint8_t>(NKPro::device_status::busy) &&
+ static_cast<NKStorage::device_status>(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);
@@ -385,7 +385,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<uint8_t>(stick10::command_status::ok)){
+ if (resp.last_command_status != static_cast<uint8_t>(NKPro::command_status::ok)){
dev->m_counters.command_result_not_equal_0_recv++;
throw CommandFailedException(resp.command_id, resp.last_command_status);
}
@@ -393,8 +393,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 69a5129..8ff392a 100644
--- a/include/dissect.h
+++ b/include/dissect.h
@@ -45,12 +45,12 @@ template <CommandID id, class HIDPacket>
class ResponseDissector : semantics::non_constructible {
public:
static std::string status_translate_device(int status){
- auto enum_status = static_cast<proto::stick10::device_status>(status);
+ auto enum_status = static_cast<proto::NKPro::device_status>(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);
}
@@ -60,20 +60,20 @@ class ResponseDissector : semantics::non_constructible {
return str;
}
static std::string status_translate_command(int status){
- auto enum_status = static_cast<proto::stick10::command_status >(status);
+ auto enum_status = static_cast<proto::NKPro::command_status >(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 46b6ae1..41cf545 100644
--- a/unittest/test.cc
+++ b/unittest/test.cc
@@ -8,7 +8,7 @@
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;
diff --git a/unittest/test2.cc b/unittest/test2.cc
index 13e33a3..37d5983 100644
--- a/unittest/test2.cc
+++ b/unittest/test2.cc
@@ -15,7 +15,7 @@ static const char *const default_user_pin = "123456";
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;
@@ -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);
@@ -128,18 +128,18 @@ TEST_CASE("test device internal status with various commands", "[fast]") {
REQUIRE(connected == true);
Log::instance().set_loglevel(Loglevel::DEBUG);
- auto p = get_payload<stick20::SendStartup>();
+ auto p = get_payload<NKStorage::SendStartup>();
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);
@@ -151,19 +151,19 @@ TEST_CASE("setup hidden volume test", "[hidden]") {
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<EnableEncryptedPartition>(stick, user_pin);
- auto p = get_payload<stick20::SetupHiddenVolume>();
+ auto p = get_payload<NKStorage::SetupHiddenVolume>();
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<EnableHiddenEncryptedPartition>(stick, hidden_volume_password);
@@ -176,19 +176,19 @@ TEST_CASE("setup multiple hidden volumes", "[hidden]") {
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<EnableEncryptedPartition>(stick, user_pin);
constexpr int volume_count = 4;
for (int i = 0; i < volume_count; ++i) {
- auto p = get_payload<stick20::SetupHiddenVolume>();
+ auto p = get_payload<NKStorage::SetupHiddenVolume>();
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);
}
@@ -220,10 +220,10 @@ TEST_CASE("update password change", "[dangerous]") {
make_pair(pass2, pass1),
};
for (auto && password: data) {
- auto p = get_payload<stick20::ChangeUpdatePassword>();
+ auto p = get_payload<NKStorage::ChangeUpdatePassword>();
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);
}
}
@@ -234,7 +234,7 @@ TEST_CASE("general test", "[test]") {
Log::instance().set_loglevel(Loglevel::DEBUG);
- stick10::LockDevice::CommandTransaction::run(stick);
+ NKPro::LockDevice::CommandTransaction::run(stick);
// execute_password_command<EnableEncryptedPartition>(stick, "123456");
// execute_password_command<DisableEncryptedPartition>(stick, "123456");
// execute_password_command<DisableHiddenEncryptedPartition>(stick, "123123123");
@@ -242,7 +242,7 @@ TEST_CASE("general test", "[test]") {
execute_password_command<SendSetReadonlyToUncryptedVolume>(stick, default_user_pin);
execute_password_command<SendSetReadwriteToUncryptedVolume>(stick, default_user_pin);
execute_password_command<SendClearNewSdCardFound>(stick, default_admin_pin, 'A');
- stick20::GetDeviceStatus::CommandTransaction::run(stick);
+ NKStorage::GetDeviceStatus::CommandTransaction::run(stick);
this_thread::sleep_for(1000ms);
// execute_password_command<LockFirmware>(stick, "123123123"); //CAUTION
// execute_password_command<EnableFirmwareUpdate>(stick, "123123123"); //CAUTION FIRMWARE PIN
@@ -250,5 +250,5 @@ TEST_CASE("general test", "[test]") {
execute_password_command<ExportFirmware>(stick, "12345678", 'A');
// execute_password_command<FillSDCardWithRandomChars>(stick, "12345678", 'A');
- stick10::LockDevice::CommandTransaction::run(stick);
+ NKPro::LockDevice::CommandTransaction::run(stick);
}
diff --git a/unittest/test3.cc b/unittest/test3.cc
index 9e0ef11..65680ad 100644
--- a/unittest/test3.cc
+++ b/unittest/test3.cc
@@ -11,13 +11,13 @@ const char * RFC_SECRET = "12345678901234567890";
#include <NitrokeyManager.h>
#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;
@@ -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<SendOTPData>();
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<WriteToOTPSlot>();
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<WriteGeneralConfig>();
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<SendOTPData>();
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<WriteToOTPSlot>();
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<GetHOTP>();
@@ -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<SendOTPData>();
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<WriteToOTPSlot>();
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<GetTOTP>();
p_get_totp.slot_number = 0 + 0x20;
diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc
index a1301ab..7c905dc 100644
--- a/unittest/test_HOTP.cc
+++ b/unittest/test_HOTP.cc
@@ -8,7 +8,7 @@
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;