diff options
Diffstat (limited to 'include/stick20_commands.h')
-rw-r--r-- | include/stick20_commands.h | 170 |
1 files changed, 133 insertions, 37 deletions
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<CommandID::SEND_HIDDEN_VOLUME_SETUP> { - public: - typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload> - CommandTransaction; - }; - class GetDeviceStatus : Command<CommandID::GET_DEVICE_STATUS> { + class SendStartup : Command<CommandID::SEND_STARTUP> { 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::seconds> ( + 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<command_id(), struct EmptyPayload, struct ResponsePayload> + typedef Transaction<command_id(), struct CommandPayload, struct ResponsePayload> CommandTransaction; }; @@ -223,41 +266,94 @@ namespace nitrokey { class SendSetReadwriteToUncryptedVolume : public PasswordCommand<CommandID::ENABLE_READWRITE_UNCRYPTED_LUN> {}; class SendClearNewSdCardFound : public PasswordCommand<CommandID::CLEAR_NEW_SD_CARD_FOUND> {}; - class SendStartup : Command<CommandID::SEND_STARTUP> { + class GetDeviceStatus : Command<CommandID::GET_DEVICE_STATUS> { 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<command_id(), struct CommandPayload, struct EmptyPayload> + typedef Transaction<command_id(), struct EmptyPayload, struct EmptyPayload> CommandTransaction; }; - class SendHiddenVolumeSetup : Command<CommandID::SEND_HIDDEN_VOLUME_SETUP> { + class SendHiddenVolumePassword : public PasswordCommand<CommandID::SEND_HIDDEN_VOLUME_PASSWORD> {}; + + class SetupHiddenVolume : Command<CommandID::SEND_HIDDEN_VOLUME_SETUP> { 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<command_id(), struct CommandPayload, struct EmptyPayload> CommandTransaction; }; + class LockFirmware : public PasswordCommand<CommandID::SEND_LOCK_STICK_HARDWARE> {}; class ProductionTest : Command<CommandID::PRODUCTION_TEST> { public: - typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload> + 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<command_id(), struct EmptyPayload, struct ResponsePayload> CommandTransaction; }; } |