From 89076a0c44dd12a73060dbfda419c20c4ce5285a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:12:37 +0200 Subject: Migrate commands to new format Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 134 +++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 71 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index f4e7500..8e758d4 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -82,68 +82,67 @@ namespace stick20 { CommandTransaction; }; -class EnableEncryptedPartition : semantics::non_constructible { +class EnableEncryptedPartition : Command{ public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class DisableEncryptedPartition : semantics::non_constructible { +class DisableEncryptedPartition : Command{ public: - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class EnableHiddenEncryptedPartition : semantics::non_constructible { +class EnableHiddenEncryptedPartition :Command{ public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class DisableHiddenEncryptedPartition : semantics::non_constructible { +class DisableHiddenEncryptedPartition :Command{ public: - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class EnableFirmwareUpdate : semantics::non_constructible { +class EnableFirmwareUpdate :Command{ public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class UpdatePassword : semantics::non_constructible { +class UpdatePassword :Command{ public: struct CommandPayload { uint8_t old_password[15]; uint8_t new_password[15]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class ExportFirmware : semantics::non_constructible { +class ExportFirmware :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; class CreateNewKeys : Command { @@ -166,50 +165,47 @@ class ExportFirmware : semantics::non_constructible { }; -class FillSDCardWithRandomChars : semantics::non_constructible { +class FillSDCardWithRandomChars :Command{ public: struct CommandPayload { uint8_t volume_flag; uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SetupHiddenVolume : semantics::non_constructible { +class SetupHiddenVolume :Command{ public: - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendPasswordMatrix : semantics::non_constructible { +class SendPasswordMatrix :Command{ public: - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendPasswordMatrixPinData : semantics::non_constructible { +class SendPasswordMatrixPinData :Command{ public: struct CommandPayload { uint8_t pin_data[30]; // TODO how long actually can it be? }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendPasswordMatrixSetup : semantics::non_constructible { +class SendPasswordMatrixSetup :Command{ public: struct CommandPayload { uint8_t setup_data[30]; // TODO how long actually can it be? }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; #define d(x) ss << " "#x":\t" << (int)x << std::endl; @@ -246,95 +242,91 @@ class SendPasswordMatrixSetup : semantics::non_constructible { }; -class SendPassword : semantics::non_constructible { +class SendPassword :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendNewPassword : semantics::non_constructible { +class SendNewPassword :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; // TODO fix original nomenclature -class SendSetReadonlyToUncryptedVolume : semantics::non_constructible { +class SendSetReadonlyToUncryptedVolume :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendSetReadwriteToUncryptedVolume : semantics::non_constructible { +class SendSetReadwriteToUncryptedVolume :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendClearNewSdCardFound : semantics::non_constructible { +class SendClearNewSdCardFound :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendStartup : semantics::non_constructible { +class SendStartup :Command{ public: struct CommandPayload { uint64_t localtime; // POSIX }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class SendHiddenVolumeSetup : semantics::non_constructible { +class SendHiddenVolumeSetup :Command{ public: struct CommandPayload { // TODO HiddenVolumeSetup_tst type }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class LockFirmware : semantics::non_constructible { +class LockFirmware :Command{ public: struct CommandPayload { uint8_t password[30]; }; - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; -class ProductionTest : semantics::non_constructible { +class ProductionTest :Command{ public: - typedef Transaction CommandTransaction; + typedef Transaction + CommandTransaction; }; } } -- cgit v1.2.1 From 3f7aaa09e8f83b68aac29693b536b2d1e6619d83 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:13:03 +0200 Subject: Code reformat Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 634 +++++++++++++++++++++++---------------------- 1 file changed, 322 insertions(+), 312 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 8e758d4..86ac053 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -1,5 +1,6 @@ #ifndef STICK20_COMMANDS_H #define STICK20_COMMANDS_H + #include "inttypes.h" #include "command.h" #include @@ -8,328 +9,337 @@ namespace nitrokey { -namespace proto { + namespace proto { /* * STICK20 protocol command ids * a superset (almost) of STICK10 */ -namespace stick20 { - - enum class PasswordKind : uint8_t { - User = 'P', - Admin = 'A' - }; - - class ChangeAdminUserPin20Current : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t old_pin[20]; - std::string dissect() const { - std::stringstream ss; - ss << " old_pin:\t" << old_pin<< std::endl; - return ss.str(); - } - void set_kind(PasswordKind k){ - kind = (uint8_t)k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class ChangeAdminUserPin20New : Command { - public: - - struct CommandPayload { - uint8_t kind; - uint8_t new_pin[20]; - std::string dissect() const { - std::stringstream ss; - ss << " new_pin:\t" << new_pin<< std::endl; - return ss.str(); - } - void set_kind(PasswordKind k){ - kind = (uint8_t)k; - } - - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class UnlockUserPassword : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t user_new_password[20]; - std::string dissect() const { - std::stringstream ss; - ss << " user_new_password:\t" << user_new_password<< std::endl; - return ss.str(); - } - void set_kind(PasswordKind k){ - kind = (uint8_t)k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - -class EnableEncryptedPartition : Command{ - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - }; - - typedef Transaction - CommandTransaction; -}; - -class DisableEncryptedPartition : Command{ - public: - typedef Transaction - CommandTransaction; -}; - -class EnableHiddenEncryptedPartition :Command{ - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - }; - - typedef Transaction - CommandTransaction; -}; - -class DisableHiddenEncryptedPartition :Command{ - public: - typedef Transaction - CommandTransaction; -}; - -class EnableFirmwareUpdate :Command{ - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - }; - - typedef Transaction - CommandTransaction; -}; - -class UpdatePassword :Command{ - public: - struct CommandPayload { - uint8_t old_password[15]; - uint8_t new_password[15]; - }; - - typedef Transaction - CommandTransaction; -}; - -class ExportFirmware :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - - class CreateNewKeys : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t admin_password[30]; //CS20_MAX_PASSWORD_LEN - std::string dissect() const { - std::stringstream ss; - ss << " admin_password:\t" << admin_password<< std::endl; - return ss.str(); - } - void setKindPrefixed(){ - kind = 'P'; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - -class FillSDCardWithRandomChars :Command{ - public: - struct CommandPayload { - uint8_t volume_flag; - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class SetupHiddenVolume :Command{ - public: - typedef Transaction - CommandTransaction; -}; - -class SendPasswordMatrix :Command{ - public: - typedef Transaction - CommandTransaction; -}; - -class SendPasswordMatrixPinData :Command{ - public: - struct CommandPayload { - uint8_t pin_data[30]; // TODO how long actually can it be? - }; - - typedef Transaction - CommandTransaction; -}; - -class SendPasswordMatrixSetup :Command{ - public: - struct CommandPayload { - uint8_t setup_data[30]; // TODO how long actually can it be? - }; - - typedef Transaction - CommandTransaction; -}; + namespace stick20 { + + enum class PasswordKind : uint8_t { + User = 'P', + Admin = 'A' + }; + + class ChangeAdminUserPin20Current : Command { + public: + struct CommandPayload { + uint8_t kind; + uint8_t old_pin[20]; + + std::string dissect() const { + std::stringstream ss; + ss << " old_pin:\t" << old_pin << std::endl; + return ss.str(); + } + + void set_kind(PasswordKind k) { + kind = (uint8_t) k; + } + } __packed; + + typedef Transaction + CommandTransaction; + }; + + + class ChangeAdminUserPin20New : Command { + public: + + struct CommandPayload { + uint8_t kind; + uint8_t new_pin[20]; + + std::string dissect() const { + std::stringstream ss; + ss << " new_pin:\t" << new_pin << std::endl; + return ss.str(); + } + + void set_kind(PasswordKind k) { + kind = (uint8_t) k; + } + + } __packed; + + typedef Transaction + CommandTransaction; + }; + + + class UnlockUserPassword : Command { + public: + struct CommandPayload { + uint8_t kind; + uint8_t user_new_password[20]; + + std::string dissect() const { + std::stringstream ss; + ss << " user_new_password:\t" << user_new_password << std::endl; + return ss.str(); + } + + void set_kind(PasswordKind k) { + kind = (uint8_t) k; + } + } __packed; + + typedef Transaction + CommandTransaction; + }; + + class EnableEncryptedPartition : Command { + public: + struct CommandPayload { + uint8_t password[30]; // TODO check w/ firmware + }; + + typedef Transaction + CommandTransaction; + }; + + class DisableEncryptedPartition : Command { + public: + typedef Transaction + CommandTransaction; + }; + + class EnableHiddenEncryptedPartition : Command { + public: + struct CommandPayload { + uint8_t password[30]; // TODO check w/ firmware + }; + + typedef Transaction + CommandTransaction; + }; + + class DisableHiddenEncryptedPartition : Command { + public: + typedef Transaction + CommandTransaction; + }; + + class EnableFirmwareUpdate : Command { + public: + struct CommandPayload { + uint8_t password[30]; // TODO check w/ firmware + }; + + typedef Transaction + CommandTransaction; + }; + + class UpdatePassword : Command { + public: + struct CommandPayload { + uint8_t old_password[15]; + uint8_t new_password[15]; + }; + + typedef Transaction + CommandTransaction; + }; + + class ExportFirmware : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class CreateNewKeys : Command { + public: + struct CommandPayload { + uint8_t kind; + uint8_t admin_password[30]; //CS20_MAX_PASSWORD_LEN + std::string dissect() const { + std::stringstream ss; + ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } + + void setKindPrefixed() { + kind = 'P'; + } + } __packed; + + typedef Transaction + CommandTransaction; + }; + + + class FillSDCardWithRandomChars : Command { + public: + struct CommandPayload { + uint8_t volume_flag; + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class SetupHiddenVolume : Command { + public: + typedef Transaction + CommandTransaction; + }; + + class SendPasswordMatrix : Command { + public: + typedef Transaction + CommandTransaction; + }; + + class SendPasswordMatrixPinData : Command { + public: + struct CommandPayload { + uint8_t pin_data[30]; // TODO how long actually can it be? + }; + + typedef Transaction + CommandTransaction; + }; + + class SendPasswordMatrixSetup : Command { + public: + struct CommandPayload { + uint8_t setup_data[30]; // TODO how long actually can it be? + }; + + typedef Transaction + CommandTransaction; + }; #define d(x) ss << " "#x":\t" << (int)x << std::endl; - class GetDeviceStatus : Command { - public: - static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 20 +1; - static const int payload_absolute_begin = 8; - static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; - struct ResponsePayload { - uint8_t _padding[padding_size]; //TODO confirm padding in Storage firmware - //data starts from 21st byte of packet -> 13th byte of payload - uint8_t command_counter; - uint8_t last_command; - uint8_t status; - uint8_t progress_bar_value; - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - d(command_counter); - d(last_command); - d(status); - d(progress_bar_value); - ss << "_padding:\t" - << ::nitrokey::misc::hexdump((const char *)(_padding), - sizeof _padding); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - -class SendPassword :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class SendNewPassword :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; + class GetDeviceStatus : Command { + public: + static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 20 + 1; + static const int payload_absolute_begin = 8; + static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; + + struct ResponsePayload { + uint8_t _padding[padding_size]; //TODO confirm padding in Storage firmware + //data starts from 21st byte of packet -> 13th byte of payload + uint8_t command_counter; + uint8_t last_command; + uint8_t status; + uint8_t progress_bar_value; + + bool isValid() const { return true; } + + std::string dissect() const { + std::stringstream ss; + d(command_counter); + d(last_command); + d(status); + d(progress_bar_value); + ss << "_padding:\t" + << ::nitrokey::misc::hexdump((const char *) (_padding), + sizeof _padding); + return ss.str(); + } + } __packed; + + typedef Transaction + CommandTransaction; + }; + + + class SendPassword : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class SendNewPassword : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; // TODO fix original nomenclature -class SendSetReadonlyToUncryptedVolume :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class SendSetReadwriteToUncryptedVolume :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class SendClearNewSdCardFound :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class SendStartup :Command{ - public: - struct CommandPayload { - uint64_t localtime; // POSIX - }; - - typedef Transaction - CommandTransaction; -}; - -class SendHiddenVolumeSetup :Command{ - public: - struct CommandPayload { - // TODO HiddenVolumeSetup_tst type - }; - - typedef Transaction - CommandTransaction; -}; - -class LockFirmware :Command{ - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; -}; - -class ProductionTest :Command{ - public: - typedef Transaction - CommandTransaction; -}; -} -} + class SendSetReadonlyToUncryptedVolume : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class SendSetReadwriteToUncryptedVolume : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class SendClearNewSdCardFound : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class SendStartup : Command { + public: + struct CommandPayload { + uint64_t localtime; // POSIX + }; + + typedef Transaction + CommandTransaction; + }; + + class SendHiddenVolumeSetup : Command { + public: + struct CommandPayload { + // TODO HiddenVolumeSetup_tst type + }; + + typedef Transaction + CommandTransaction; + }; + + class LockFirmware : Command { + public: + struct CommandPayload { + uint8_t password[30]; + }; + + typedef Transaction + CommandTransaction; + }; + + class ProductionTest : Command { + public: + typedef Transaction + CommandTransaction; + }; + } + } } #endif -- cgit v1.2.1 From 323cb033d330129f12ddc19ed96a264e1becf8bb Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:14:24 +0200 Subject: Remove password matrix commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 86ac053..40352a3 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -190,32 +190,6 @@ namespace nitrokey { CommandTransaction; }; - class SendPasswordMatrix : Command { - public: - typedef Transaction - CommandTransaction; - }; - - class SendPasswordMatrixPinData : Command { - public: - struct CommandPayload { - uint8_t pin_data[30]; // TODO how long actually can it be? - }; - - typedef Transaction - CommandTransaction; - }; - - class SendPasswordMatrixSetup : Command { - public: - struct CommandPayload { - uint8_t setup_data[30]; // TODO how long actually can it be? - }; - - typedef Transaction - CommandTransaction; - }; - #define d(x) ss << " "#x":\t" << (int)x << std::endl; class GetDeviceStatus : Command { -- cgit v1.2.1 From c07390ce32506e009ebf44c2ecc8190d21abd530 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:15:46 +0200 Subject: Remove already implemented commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 40352a3..e57932d 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -226,26 +226,6 @@ namespace nitrokey { }; - class SendPassword : Command { - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; - }; - - class SendNewPassword : Command { - public: - struct CommandPayload { - uint8_t password[30]; - }; - - typedef Transaction - CommandTransaction; - }; - // TODO fix original nomenclature class SendSetReadonlyToUncryptedVolume : Command { public: -- cgit v1.2.1 From 3601f5f97fb64357d9d9221acbd356eec4dbc67a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:20:43 +0200 Subject: Add dissection template to commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index e57932d..b685055 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -93,6 +93,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -109,6 +114,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -125,6 +135,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; // TODO check w/ firmware + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -136,6 +151,11 @@ namespace nitrokey { struct CommandPayload { uint8_t old_password[15]; uint8_t new_password[15]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -146,6 +166,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -178,6 +203,11 @@ namespace nitrokey { struct CommandPayload { uint8_t volume_flag; uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -231,6 +261,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -241,6 +276,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -251,6 +291,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -261,6 +306,11 @@ namespace nitrokey { public: struct CommandPayload { uint64_t localtime; // POSIX + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -271,6 +321,11 @@ namespace nitrokey { public: struct CommandPayload { // TODO HiddenVolumeSetup_tst type + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction @@ -281,6 +336,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t password[30]; + std::string dissect() const { + std::stringstream ss; +// ss << " admin_password:\t" << admin_password << std::endl; + return ss.str(); + } }; typedef Transaction -- cgit v1.2.1 From 24f140f34c9c90be54165802edb80fce3408ffa3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 19:01:13 +0200 Subject: First template based password commands. Initial dissect support for commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 49 ++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index b685055..5ee16de 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -15,6 +15,7 @@ namespace nitrokey { * STICK20 protocol command ids * a superset (almost) of STICK10 */ +#define print_to_ss(x) ( ss << " #x:\t" << (x) << std::endl ); namespace stick20 { enum class PasswordKind : uint8_t { @@ -30,6 +31,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; + print_to_ss( kind ); ss << " old_pin:\t" << old_pin << std::endl; return ss.str(); } @@ -53,6 +55,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; + print_to_ss( kind ); ss << " new_pin:\t" << new_pin << std::endl; return ss.str(); } @@ -76,6 +79,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; + print_to_ss( kind ); ss << " user_new_password:\t" << user_new_password << std::endl; return ss.str(); } @@ -89,26 +93,8 @@ namespace nitrokey { CommandTransaction; }; - class EnableEncryptedPartition : Command { - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - std::string dissect() const { - std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; - - class DisableEncryptedPartition : Command { - public: - typedef Transaction - CommandTransaction; - }; + class EnableEncryptedPartition : public PasswordCommand {}; + class DisableEncryptedPartition : public PasswordCommand {}; class EnableHiddenEncryptedPartition : Command { public: @@ -116,7 +102,7 @@ namespace nitrokey { uint8_t password[30]; // TODO check w/ firmware std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -137,7 +123,7 @@ namespace nitrokey { uint8_t password[30]; // TODO check w/ firmware std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -153,7 +139,8 @@ namespace nitrokey { uint8_t new_password[15]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( old_password ); + print_to_ss( new_password ); return ss.str(); } }; @@ -168,7 +155,7 @@ namespace nitrokey { uint8_t password[30]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -184,6 +171,7 @@ namespace nitrokey { uint8_t admin_password[30]; //CS20_MAX_PASSWORD_LEN std::string dissect() const { std::stringstream ss; + print_to_ss( kind ); ss << " admin_password:\t" << admin_password << std::endl; return ss.str(); } @@ -205,7 +193,8 @@ namespace nitrokey { uint8_t password[30]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( (int)volume_flag ); + print_to_ss( password ); return ss.str(); } }; @@ -255,6 +244,8 @@ namespace nitrokey { CommandTransaction; }; +#undef d + // TODO fix original nomenclature class SendSetReadonlyToUncryptedVolume : Command { @@ -263,7 +254,7 @@ namespace nitrokey { uint8_t password[30]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -278,7 +269,7 @@ namespace nitrokey { uint8_t password[30]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -293,7 +284,7 @@ namespace nitrokey { uint8_t password[30]; std::string dissect() const { std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; + print_to_ss( password ); return ss.str(); } }; @@ -356,4 +347,6 @@ namespace nitrokey { } } +#undef print_to_ss + #endif -- cgit v1.2.1 From acf8adf7d6920e702cbd2f256ab312f80b781001 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 19:30:42 +0200 Subject: Enable hidden encrypted partition Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5ee16de..34dda60 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -95,21 +95,7 @@ namespace nitrokey { class EnableEncryptedPartition : public PasswordCommand {}; class DisableEncryptedPartition : public PasswordCommand {}; - - class EnableHiddenEncryptedPartition : Command { - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class EnableHiddenEncryptedPartition : public PasswordCommand {}; class DisableHiddenEncryptedPartition : Command { public: -- cgit v1.2.1 From 9f0e18f1a91a768717481dbf6b88eedd066a46c9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 14:42:03 +0200 Subject: Another set of Storage password-only commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 118 +++------------------------------------------ 1 file changed, 8 insertions(+), 110 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 34dda60..75bce1c 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -96,27 +96,8 @@ namespace nitrokey { class EnableEncryptedPartition : public PasswordCommand {}; class DisableEncryptedPartition : public PasswordCommand {}; class EnableHiddenEncryptedPartition : public PasswordCommand {}; - - class DisableHiddenEncryptedPartition : Command { - public: - typedef Transaction - CommandTransaction; - }; - - class EnableFirmwareUpdate : Command { - public: - struct CommandPayload { - uint8_t password[30]; // TODO check w/ firmware - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class DisableHiddenEncryptedPartition : public PasswordCommand {}; + class EnableFirmwareUpdate : public PasswordCommand {}; class UpdatePassword : Command { public: @@ -135,20 +116,7 @@ namespace nitrokey { CommandTransaction; }; - class ExportFirmware : Command { - public: - struct CommandPayload { - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class ExportFirmware : public PasswordCommand {}; class CreateNewKeys : Command { public: @@ -171,23 +139,7 @@ namespace nitrokey { CommandTransaction; }; - - class FillSDCardWithRandomChars : Command { - public: - struct CommandPayload { - uint8_t volume_flag; - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; - print_to_ss( (int)volume_flag ); - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class FillSDCardWithRandomChars : public PasswordCommand {}; class SetupHiddenVolume : Command { public: @@ -234,50 +186,9 @@ namespace nitrokey { // TODO fix original nomenclature - class SendSetReadonlyToUncryptedVolume : Command { - public: - struct CommandPayload { - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; - - class SendSetReadwriteToUncryptedVolume : Command { - public: - struct CommandPayload { - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; - - class SendClearNewSdCardFound : Command { - public: - struct CommandPayload { - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; - print_to_ss( password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class SendSetReadonlyToUncryptedVolume : public PasswordCommand {}; + class SendSetReadwriteToUncryptedVolume : public PasswordCommand {}; + class SendClearNewSdCardFound : public PasswordCommand {}; class SendStartup : Command { public: @@ -309,20 +220,7 @@ namespace nitrokey { CommandTransaction; }; - class LockFirmware : Command { - public: - struct CommandPayload { - uint8_t password[30]; - std::string dissect() const { - std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; + class LockFirmware : public PasswordCommand {}; class ProductionTest : Command { public: -- cgit v1.2.1 From ec8b19e231390e25860218000d77d622d94782c7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 14:44:38 +0200 Subject: Remove obsolete macro Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 75bce1c..b3dbacf 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -147,7 +147,6 @@ namespace nitrokey { CommandTransaction; }; -#define d(x) ss << " "#x":\t" << (int)x << std::endl; class GetDeviceStatus : Command { public: @@ -167,10 +166,10 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; - d(command_counter); - d(last_command); - d(status); - d(progress_bar_value); + print_to_ss((int)command_counter); + print_to_ss((int)last_command); + print_to_ss((int)status); + print_to_ss((int)progress_bar_value); ss << "_padding:\t" << ::nitrokey::misc::hexdump((const char *) (_padding), sizeof _padding); @@ -182,8 +181,6 @@ namespace nitrokey { CommandTransaction; }; -#undef d - // TODO fix original nomenclature class SendSetReadonlyToUncryptedVolume : public PasswordCommand {}; -- cgit v1.2.1 From 33a2d790e0a68d243bc1d9e9f75590b141d85c7f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 16:19:00 +0200 Subject: Fix printing macro Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index b3dbacf..5679681 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -15,7 +15,7 @@ namespace nitrokey { * STICK20 protocol command ids * a superset (almost) of STICK10 */ -#define print_to_ss(x) ( ss << " #x:\t" << (x) << std::endl ); +#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); namespace stick20 { enum class PasswordKind : uint8_t { -- cgit v1.2.1 From b0412c73b8ff129183f570a4eed72bdafd9f55d3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 25 Oct 2016 18:41:59 +0200 Subject: Handle FillSDCardWithRandomChars command and test it Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5679681..a335809 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -139,7 +139,43 @@ namespace nitrokey { CommandTransaction; }; - class FillSDCardWithRandomChars : public PasswordCommand {}; +// class FillSDCardWithRandomChars : public PasswordCommand {}; + + + class FillSDCardWithRandomChars : Command { + public: + enum class ChosenVolumes : uint8_t { + all_volumes = 0, + encrypted_volume = 1 + }; + + struct CommandPayload { + uint8_t volume_flag; + uint8_t kind; + uint8_t password[20]; + + std::string dissect() const { + std::stringstream ss; + print_to_ss( (int) volume_flag ); + print_to_ss( kind ); + print_to_ss(password); + return ss.str(); + } + void set_kind_user() { + kind = (uint8_t) 'P'; + } + void set_defaults(){ + set_kind_user(); + volume_flag = static_cast(ChosenVolumes::encrypted_volume); + } + + } __packed; + + typedef Transaction::command_id(), + struct CommandPayload, struct EmptyPayload> + CommandTransaction; + }; + class SetupHiddenVolume : Command { public: -- cgit v1.2.1 From a4d93360a600d5361a825c5270cb313202e1f318 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 27 Oct 2016 19:42:17 +0200 Subject: Fix naming for change password commands ids Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index a335809..7b69ec6 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -23,7 +23,7 @@ namespace nitrokey { Admin = 'A' }; - class ChangeAdminUserPin20Current : Command { + class ChangeAdminUserPin20Current : Command { public: struct CommandPayload { uint8_t kind; @@ -46,7 +46,7 @@ namespace nitrokey { }; - class ChangeAdminUserPin20New : Command { + class ChangeAdminUserPin20New : Command { public: struct CommandPayload { -- cgit v1.2.1 From b727d90d4e599762ff3eebff2349ae0fed1e0743 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 27 Oct 2016 20:10:22 +0200 Subject: Support Storage status commands: SendStartup ProductionTest Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 170 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 133 insertions(+), 37 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 7b69ec6..4bbb8c0 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -177,35 +177,78 @@ namespace nitrokey { }; - class SetupHiddenVolume : Command { - public: - typedef Transaction - CommandTransaction; - }; - class GetDeviceStatus : Command { + class SendStartup : Command { public: - static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 20 + 1; + struct CommandPayload { + uint64_t localtime; // POSIX seconds from epoch start, supports until year 2106 + std::string dissect() const { + std::stringstream ss; + print_to_ss( localtime ); + return ss.str(); + } + void set_defaults(){ + localtime = + std::chrono::duration_cast ( + std::chrono::system_clock::now().time_since_epoch()).count(); + } + }__packed; + + static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; static const int payload_absolute_begin = 8; static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; struct ResponsePayload { - uint8_t _padding[padding_size]; //TODO confirm padding in Storage firmware - //data starts from 21st byte of packet -> 13th byte of payload - uint8_t command_counter; - uint8_t last_command; - uint8_t status; - uint8_t progress_bar_value; + uint8_t _padding[padding_size]; + + uint8_t SendCounter_u8; + uint8_t SendDataType_u8; + uint8_t FollowBytesFlag_u8; + uint8_t SendSize_u8; + + uint16_t MagicNumber_StickConfig_u16; + uint8_t ReadWriteFlagUncryptedVolume_u8; + uint8_t ReadWriteFlagCryptedVolume_u8; + uint8_t VersionInfo_au8[4]; + uint8_t ReadWriteFlagHiddenVolume_u8; + uint8_t FirmwareLocked_u8; + uint8_t NewSDCardFound_u8; + uint8_t SDFillWithRandomChars_u8; + uint32_t ActiveSD_CardID_u32; + uint8_t VolumeActiceFlag_u8; + uint8_t NewSmartCardFound_u8; + uint8_t UserPwRetryCount; + uint8_t AdminPwRetryCount; + uint32_t ActiveSmartCardID_u32; + uint8_t StickKeysNotInitiated; bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - print_to_ss((int)command_counter); - print_to_ss((int)last_command); - print_to_ss((int)status); - print_to_ss((int)progress_bar_value); + + print_to_ss((int) SendCounter_u8 ); + print_to_ss((int) SendDataType_u8 ); + print_to_ss((int) FollowBytesFlag_u8 ); + print_to_ss((int) SendSize_u8 ); + + print_to_ss( MagicNumber_StickConfig_u16 ); + print_to_ss((int) ReadWriteFlagUncryptedVolume_u8 ); + print_to_ss((int) ReadWriteFlagCryptedVolume_u8 ); + print_to_ss((int) VersionInfo_au8[1] ); + print_to_ss((int) VersionInfo_au8[3] ); + print_to_ss((int) ReadWriteFlagHiddenVolume_u8 ); + print_to_ss((int) FirmwareLocked_u8 ); + print_to_ss((int) NewSDCardFound_u8 ); + print_to_ss((int) SDFillWithRandomChars_u8 ); + print_to_ss( ActiveSD_CardID_u32 ); + print_to_ss((int) VolumeActiceFlag_u8 ); + print_to_ss((int) NewSmartCardFound_u8 ); + print_to_ss((int) UserPwRetryCount ); + print_to_ss((int) AdminPwRetryCount ); + print_to_ss( ActiveSmartCardID_u32 ); + print_to_ss((int) StickKeysNotInitiated ); ss << "_padding:\t" << ::nitrokey::misc::hexdump((const char *) (_padding), sizeof _padding); @@ -213,7 +256,7 @@ namespace nitrokey { } } __packed; - typedef Transaction + typedef Transaction CommandTransaction; }; @@ -223,41 +266,94 @@ namespace nitrokey { class SendSetReadwriteToUncryptedVolume : public PasswordCommand {}; class SendClearNewSdCardFound : public PasswordCommand {}; - class SendStartup : Command { + class GetDeviceStatus : Command { public: - struct CommandPayload { - uint64_t localtime; // POSIX - std::string dissect() const { - std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; - return ss.str(); - } - }; - typedef Transaction + typedef Transaction CommandTransaction; }; - class SendHiddenVolumeSetup : Command { + class SendHiddenVolumePassword : public PasswordCommand {}; + + class SetupHiddenVolume : Command { public: + constexpr static int MAX_HIDDEN_VOLUME_PASSOWORD_SIZE = 20; struct CommandPayload { - // TODO HiddenVolumeSetup_tst type - std::string dissect() const { - std::stringstream ss; -// ss << " admin_password:\t" << admin_password << std::endl; - return ss.str(); - } - }; + uint8_t SlotNr_u8; + uint8_t StartBlockPercent_u8; + uint8_t EndBlockPercent_u8; + uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSOWORD_SIZE + 1]; + }__packed; typedef Transaction CommandTransaction; }; + class LockFirmware : public PasswordCommand {}; class ProductionTest : Command { public: - typedef Transaction + static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; + static const int payload_absolute_begin = 8; + static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; + + struct ResponsePayload { + uint8_t _padding[padding_size]; + + uint8_t SendCounter_u8; + uint8_t SendDataType_u8; + uint8_t FollowBytesFlag_u8; + uint8_t SendSize_u8; + + uint8_t FirmwareVersion_au8[2]; // 2 byte // 2 + uint8_t FirmwareVersionInternal_u8; // 1 byte // 3 + uint8_t SD_Card_Size_u8; // 1 byte // 4 + uint32_t CPU_CardID_u32; // 4 byte // 8 + uint32_t SmartCardID_u32; // 4 byte // 12 + uint32_t SD_CardID_u32; // 4 byte // 16 + uint8_t SC_UserPwRetryCount; // User PIN retry count 1 byte // 17 + uint8_t SC_AdminPwRetryCount; // Admin PIN retry count 1 byte // 18 + uint8_t SD_Card_ManufacturingYear_u8; // 1 byte // 19 + uint8_t SD_Card_ManufacturingMonth_u8; // 1 byte // 20 + uint16_t SD_Card_OEM_u16; // 2 byte // 22 + uint16_t SD_WriteSpeed_u16; // in kbyte / sec 2 byte // 24 + uint8_t SD_Card_Manufacturer_u8; // 1 byte // 25 + + bool isValid() const { return true; } + + std::string dissect() const { + std::stringstream ss; + + print_to_ss((int) SendCounter_u8); + print_to_ss((int) SendDataType_u8); + print_to_ss((int) FollowBytesFlag_u8); + print_to_ss((int) SendSize_u8); + + print_to_ss((int) FirmwareVersion_au8[0]); + print_to_ss((int) FirmwareVersion_au8[1]); + print_to_ss((int) FirmwareVersionInternal_u8); + print_to_ss((int) SD_Card_Size_u8); + print_to_ss( CPU_CardID_u32); + print_to_ss( SmartCardID_u32); + print_to_ss( SD_CardID_u32); + print_to_ss((int) SC_UserPwRetryCount); + print_to_ss((int) SC_AdminPwRetryCount); + print_to_ss((int) SD_Card_ManufacturingYear_u8); + print_to_ss((int) SD_Card_ManufacturingMonth_u8); + print_to_ss( SD_Card_OEM_u16); + print_to_ss( SD_WriteSpeed_u16); + print_to_ss((int) SD_Card_Manufacturer_u8); + + ss << "_padding:\t" + << ::nitrokey::misc::hexdump((const char *) (_padding), + sizeof _padding); + return ss.str(); + } + + } __packed; + + typedef Transaction CommandTransaction; }; } -- cgit v1.2.1 From d58f3fd3bb6df5d3f46e3c4c3b719174e31b7201 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 27 Oct 2016 21:14:17 +0200 Subject: Support for setting hidden volume and test for it Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 4bbb8c0..a1e65c2 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -282,8 +282,23 @@ namespace nitrokey { uint8_t SlotNr_u8; uint8_t StartBlockPercent_u8; uint8_t EndBlockPercent_u8; - uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSOWORD_SIZE + 1]; - }__packed; + uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSOWORD_SIZE + 1]; //last char is a null terminator TODO check if it's needed + std::string dissect() const { + std::stringstream ss; + print_to_ss((int) SlotNr_u8); + print_to_ss((int) StartBlockPercent_u8); + print_to_ss((int) EndBlockPercent_u8); + ss << " HiddenVolumePassword_au8:\t" + << HiddenVolumePassword_au8 << std::endl; + return ss.str(); + } + + void set_defaults(){ + SlotNr_u8 = 0; + StartBlockPercent_u8 = 70; + EndBlockPercent_u8 = 90; + } + } __packed; typedef Transaction CommandTransaction; -- cgit v1.2.1 From 3b1926164b2e0eb91cf3a7e9c854cca85f7d4c8e Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 14:33:25 +0200 Subject: Support for changing firmware update password and test Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index a1e65c2..676b3df 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -99,15 +99,17 @@ namespace nitrokey { class DisableHiddenEncryptedPartition : public PasswordCommand {}; class EnableFirmwareUpdate : public PasswordCommand {}; - class UpdatePassword : Command { + class ChangeUpdatePassword : Command { public: struct CommandPayload { - uint8_t old_password[15]; - uint8_t new_password[15]; + uint8_t __gap; + uint8_t current_update_password[20]; + uint8_t __gap2; + uint8_t new_update_password[20]; std::string dissect() const { std::stringstream ss; - print_to_ss( old_password ); - print_to_ss( new_password ); + print_to_ss( current_update_password ); + print_to_ss( new_update_password ); return ss.str(); } }; -- cgit v1.2.1 From e45e2f03cf40b5826632ab95cbc79c487249897a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 14:34:25 +0200 Subject: Mark unused commands and remove obsolete code Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 676b3df..237118d 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -141,8 +141,6 @@ namespace nitrokey { CommandTransaction; }; -// class FillSDCardWithRandomChars : public PasswordCommand {}; - class FillSDCardWithRandomChars : Command { public: @@ -275,7 +273,6 @@ namespace nitrokey { CommandTransaction; }; - class SendHiddenVolumePassword : public PasswordCommand {}; class SetupHiddenVolume : Command { public: -- cgit v1.2.1 From 6343eea03980627cb763de777af6b316130bdf43 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 14:55:56 +0200 Subject: Support getting SD card occupancy and test Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 237118d..42f46ad 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -273,6 +273,27 @@ namespace nitrokey { CommandTransaction; }; + class GetSDCardOccupancy : Command { + public: + struct ResponsePayload { + uint8_t WriteLevelMin; + uint8_t WriteLevelMax; + uint8_t ReadLevelMin; + uint8_t ReadLevelMax; + std::string dissect() const { + std::stringstream ss; + print_to_ss((int) WriteLevelMin); + print_to_ss((int) WriteLevelMax); + print_to_ss((int) ReadLevelMin); + print_to_ss((int) ReadLevelMax); + return ss.str(); + } + } __packed; + + typedef Transaction + CommandTransaction; + }; + class SetupHiddenVolume : Command { public: -- cgit v1.2.1 From ce30b49b4d50f2eff39a40ddd0c02ad96b78654c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 28 Oct 2016 16:29:55 +0200 Subject: Make packet variables' names more clear General fixes Remove default values from hidden volume setup command rename password -> pin Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 42f46ad..31d7b13 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -71,7 +71,7 @@ namespace nitrokey { }; - class UnlockUserPassword : Command { + class UnlockUserPin : Command { public: struct CommandPayload { uint8_t kind; @@ -124,11 +124,11 @@ namespace nitrokey { public: struct CommandPayload { uint8_t kind; - uint8_t admin_password[30]; //CS20_MAX_PASSWORD_LEN + uint8_t admin_pin[30]; //CS20_MAX_PASSWORD_LEN std::string dissect() const { std::stringstream ss; print_to_ss( kind ); - ss << " admin_password:\t" << admin_password << std::endl; + ss << " admin_pin:\t" << admin_pin << std::endl; return ss.str(); } @@ -152,13 +152,13 @@ namespace nitrokey { struct CommandPayload { uint8_t volume_flag; uint8_t kind; - uint8_t password[20]; + uint8_t admin_pin[20]; std::string dissect() const { std::stringstream ss; print_to_ss( (int) volume_flag ); print_to_ss( kind ); - print_to_ss(password); + print_to_ss(admin_pin); return ss.str(); } void set_kind_user() { @@ -297,27 +297,20 @@ namespace nitrokey { class SetupHiddenVolume : Command { public: - constexpr static int MAX_HIDDEN_VOLUME_PASSOWORD_SIZE = 20; + constexpr static int MAX_HIDDEN_VOLUME_PASSWORD_SIZE = 20; struct CommandPayload { uint8_t SlotNr_u8; uint8_t StartBlockPercent_u8; uint8_t EndBlockPercent_u8; - uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSOWORD_SIZE + 1]; //last char is a null terminator TODO check if it's needed + uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSWORD_SIZE]; std::string dissect() const { std::stringstream ss; print_to_ss((int) SlotNr_u8); print_to_ss((int) StartBlockPercent_u8); print_to_ss((int) EndBlockPercent_u8); - ss << " HiddenVolumePassword_au8:\t" - << HiddenVolumePassword_au8 << std::endl; + print_to_ss(HiddenVolumePassword_au8); return ss.str(); } - - void set_defaults(){ - SlotNr_u8 = 0; - StartBlockPercent_u8 = 70; - EndBlockPercent_u8 = 90; - } } __packed; typedef Transaction @@ -329,9 +322,9 @@ namespace nitrokey { class ProductionTest : Command { public: - static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; - static const int payload_absolute_begin = 8; - static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; + static constexpr int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; + static constexpr int payload_absolute_begin = 8; + static constexpr int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; struct ResponsePayload { uint8_t _padding[padding_size]; @@ -380,7 +373,7 @@ namespace nitrokey { print_to_ss( SD_WriteSpeed_u16); print_to_ss((int) SD_Card_Manufacturer_u8); - ss << "_padding:\t" + ss << "_padding:" << std::endl << ::nitrokey::misc::hexdump((const char *) (_padding), sizeof _padding); return ss.str(); -- cgit v1.2.1 From 8b49ee9e25efbca9d0d51fcc8be17fd115fc78fd Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 16:56:40 +0100 Subject: Define configuration response packet separately Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 31d7b13..5c2d97e 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -178,23 +178,7 @@ namespace nitrokey { - - class SendStartup : Command { - public: - struct CommandPayload { - uint64_t localtime; // POSIX seconds from epoch start, supports until year 2106 - std::string dissect() const { - std::stringstream ss; - print_to_ss( localtime ); - return ss.str(); - } - void set_defaults(){ - localtime = - std::chrono::duration_cast ( - std::chrono::system_clock::now().time_since_epoch()).count(); - } - }__packed; - + namespace DeviceConfigurationResponsePacket{ static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; static const int payload_absolute_begin = 8; static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; @@ -249,14 +233,33 @@ namespace nitrokey { print_to_ss((int) AdminPwRetryCount ); print_to_ss( ActiveSmartCardID_u32 ); print_to_ss((int) StickKeysNotInitiated ); - ss << "_padding:\t" + ss << "_padding:" << std::endl << ::nitrokey::misc::hexdump((const char *) (_padding), sizeof _padding); return ss.str(); } } __packed; + } + + class SendStartup : Command { + public: + struct CommandPayload { + uint64_t localtime; // POSIX seconds from epoch start, supports until year 2106 + std::string dissect() const { + std::stringstream ss; + print_to_ss( localtime ); + return ss.str(); + } + void set_defaults(){ + localtime = + std::chrono::duration_cast ( + std::chrono::system_clock::now().time_since_epoch()).count(); + } + }__packed; + + using ResponsePayload = DeviceConfigurationResponsePacket::ResponsePayload; - typedef Transaction + typedef Transaction CommandTransaction; }; @@ -268,8 +271,9 @@ namespace nitrokey { class GetDeviceStatus : Command { public: + using ResponsePayload = DeviceConfigurationResponsePacket::ResponsePayload; - typedef Transaction + typedef Transaction CommandTransaction; }; -- cgit v1.2.1 From 9ad4796130a4ce192420563bb601468ffc292df9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 17:48:18 +0100 Subject: Code refactoring - unify password only commands Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 78 ++++------------------------------------------ 1 file changed, 6 insertions(+), 72 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5c2d97e..a51d1ca 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -18,80 +18,14 @@ namespace nitrokey { #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); namespace stick20 { - enum class PasswordKind : uint8_t { - User = 'P', - Admin = 'A' - }; - - class ChangeAdminUserPin20Current : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t old_pin[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " old_pin:\t" << old_pin << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class ChangeAdminUserPin20New : Command { - public: - - struct CommandPayload { - uint8_t kind; - uint8_t new_pin[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " new_pin:\t" << new_pin << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - - } __packed; - - typedef Transaction - CommandTransaction; - }; - class UnlockUserPin : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t user_new_password[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " user_new_password:\t" << user_new_password << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; + class ChangeAdminUserPin20Current : + public PasswordCommand {}; + class ChangeAdminUserPin20New : + public PasswordCommand {}; + class UnlockUserPin : + public PasswordCommand {}; class EnableEncryptedPartition : public PasswordCommand {}; class DisableEncryptedPartition : public PasswordCommand {}; -- cgit v1.2.1 From 98b27cb58b12f699b5c11f88d55c3e3f70ed2063 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 18:02:55 +0100 Subject: Code refactoring - unify password only commands (2) Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index a51d1ca..d7d89cf 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -18,8 +18,6 @@ namespace nitrokey { #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); namespace stick20 { - - class ChangeAdminUserPin20Current : public PasswordCommand {}; class ChangeAdminUserPin20New : @@ -54,26 +52,8 @@ namespace nitrokey { class ExportFirmware : public PasswordCommand {}; - class CreateNewKeys : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t admin_pin[30]; //CS20_MAX_PASSWORD_LEN - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " admin_pin:\t" << admin_pin << std::endl; - return ss.str(); - } - - void setKindPrefixed() { - kind = 'P'; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; + class CreateNewKeys : + public PasswordCommand {}; class FillSDCardWithRandomChars : Command { -- cgit v1.2.1 From b540266c4ce17b640724bc09275e45e15a53d707 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 18:19:54 +0100 Subject: Transmission data for 2.0 commands move to separate struct Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 67 +++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index d7d89cf..f816868 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -90,20 +90,37 @@ namespace nitrokey { CommandTransaction; }; - + namespace StorageCommandResponsePayload{ + static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; + static const int payload_absolute_begin = 8; + static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; + struct TransmissionData{ + uint8_t _padding[padding_size]; + + uint8_t SendCounter_u8; + uint8_t SendDataType_u8; + uint8_t FollowBytesFlag_u8; + uint8_t SendSize_u8; + + std::string dissect() const { + std::stringstream ss; + ss << "_padding:" << std::endl + << ::nitrokey::misc::hexdump((const char *) (_padding), + sizeof _padding); + print_to_ss((int) SendCounter_u8); + print_to_ss((int) SendDataType_u8); + print_to_ss((int) FollowBytesFlag_u8); + print_to_ss((int) SendSize_u8); + return ss.str(); + } + + } __packed; + } namespace DeviceConfigurationResponsePacket{ - static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; - static const int payload_absolute_begin = 8; - static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; struct ResponsePayload { - uint8_t _padding[padding_size]; - - uint8_t SendCounter_u8; - uint8_t SendDataType_u8; - uint8_t FollowBytesFlag_u8; - uint8_t SendSize_u8; + StorageCommandResponsePayload::TransmissionData transmission_data; uint16_t MagicNumber_StickConfig_u16; uint8_t ReadWriteFlagUncryptedVolume_u8; @@ -126,11 +143,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; - print_to_ss((int) SendCounter_u8 ); - print_to_ss((int) SendDataType_u8 ); - print_to_ss((int) FollowBytesFlag_u8 ); - print_to_ss((int) SendSize_u8 ); - + print_to_ss(transmission_data.dissect()); print_to_ss( MagicNumber_StickConfig_u16 ); print_to_ss((int) ReadWriteFlagUncryptedVolume_u8 ); print_to_ss((int) ReadWriteFlagCryptedVolume_u8 ); @@ -147,9 +160,7 @@ namespace nitrokey { print_to_ss((int) AdminPwRetryCount ); print_to_ss( ActiveSmartCardID_u32 ); print_to_ss((int) StickKeysNotInitiated ); - ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (_padding), - sizeof _padding); + return ss.str(); } } __packed; @@ -240,17 +251,9 @@ namespace nitrokey { class ProductionTest : Command { public: - static constexpr int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; - static constexpr int payload_absolute_begin = 8; - static constexpr int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; - struct ResponsePayload { - uint8_t _padding[padding_size]; - uint8_t SendCounter_u8; - uint8_t SendDataType_u8; - uint8_t FollowBytesFlag_u8; - uint8_t SendSize_u8; + StorageCommandResponsePayload::TransmissionData transmission_data; uint8_t FirmwareVersion_au8[2]; // 2 byte // 2 uint8_t FirmwareVersionInternal_u8; // 1 byte // 3 @@ -271,11 +274,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; - print_to_ss((int) SendCounter_u8); - print_to_ss((int) SendDataType_u8); - print_to_ss((int) FollowBytesFlag_u8); - print_to_ss((int) SendSize_u8); - + print_to_ss(transmission_data.dissect()); print_to_ss((int) FirmwareVersion_au8[0]); print_to_ss((int) FirmwareVersion_au8[1]); print_to_ss((int) FirmwareVersionInternal_u8); @@ -290,10 +289,6 @@ namespace nitrokey { print_to_ss( SD_Card_OEM_u16); print_to_ss( SD_WriteSpeed_u16); print_to_ss((int) SD_Card_Manufacturer_u8); - - ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (_padding), - sizeof _padding); return ss.str(); } -- cgit v1.2.1 From c346ff180244de682e78f49783eab9b296c79de6 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 19:03:30 +0100 Subject: Code refactoring - named magic numbers (2) Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index f816868..139dc63 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -91,9 +91,9 @@ namespace nitrokey { }; namespace StorageCommandResponsePayload{ - static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1; - static const int payload_absolute_begin = 8; - static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin; + using namespace DeviceResponseConstants; + static constexpr auto padding_size = + storage_data_absolute_address - header_size; struct TransmissionData{ uint8_t _padding[padding_size]; -- cgit v1.2.1 From 266b57dfe7b36799243816b7af22f3dd69b0d197 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 19:07:34 +0100 Subject: Disable locking firmware command for now Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 139dc63..1af9da3 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -247,7 +247,8 @@ namespace nitrokey { }; - class LockFirmware : public PasswordCommand {}; +//disable this command for now +// class LockFirmware : public PasswordCommand {}; class ProductionTest : Command { public: -- cgit v1.2.1