#ifndef STICK20_COMMANDS_H #define STICK20_COMMANDS_H #include "inttypes.h" #include "command.h" #include #include #include "device_proto.h" namespace nitrokey { namespace proto { /* * 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 { 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 UnlockUserPassword : 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 EnableEncryptedPartition : public PasswordCommand {}; class DisableEncryptedPartition : public PasswordCommand {}; class EnableHiddenEncryptedPartition : public PasswordCommand {}; class DisableHiddenEncryptedPartition : public PasswordCommand {}; class EnableFirmwareUpdate : public PasswordCommand {}; class UpdatePassword : Command { public: struct CommandPayload { uint8_t old_password[15]; uint8_t new_password[15]; std::string dissect() const { std::stringstream ss; print_to_ss( old_password ); print_to_ss( new_password ); return ss.str(); } }; typedef Transaction CommandTransaction; }; class ExportFirmware : public PasswordCommand {}; 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; print_to_ss( kind ); ss << " admin_password:\t" << admin_password << std::endl; return ss.str(); } void setKindPrefixed() { kind = 'P'; } } __packed; typedef Transaction CommandTransaction; }; class FillSDCardWithRandomChars : public PasswordCommand {}; class SetupHiddenVolume : Command { public: 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; 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); return ss.str(); } } __packed; typedef Transaction CommandTransaction; }; // TODO fix original nomenclature class SendSetReadonlyToUncryptedVolume : public PasswordCommand {}; class SendSetReadwriteToUncryptedVolume : public PasswordCommand {}; class SendClearNewSdCardFound : public PasswordCommand {}; class SendStartup : 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 CommandTransaction; }; class SendHiddenVolumeSetup : Command { 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 CommandTransaction; }; class LockFirmware : public PasswordCommand {}; class ProductionTest : Command { public: typedef Transaction CommandTransaction; }; } } } #undef print_to_ss #endif