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') 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