From 955fb912ab9563a5246f9d3bfda9ccfab187949f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 29 Mar 2016 13:04:52 +0200 Subject: adding next steps for hotp tests: writing, reading and authorization for writing hotp code --- include/device_proto.h | 9 +++++++++ include/stick10_commands.h | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index f2ed84d..e05a303 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -151,6 +151,15 @@ class Transaction : semantics::non_constructible { static_assert(sizeof(ResponsePacket) == HID_REPORT_SIZE, "ResponsePacket type is not the right size"); + static uint32_t getCRC( + const command_payload &payload) { + OutgoingPacket outp; + outp.initialize(); + outp.payload = payload; + outp.update_CRC(); + return outp.crc; + } + static response_payload run(device::Device &dev, const command_payload &payload) { using namespace ::nitrokey::device; diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 1c21eee..60c947f 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -127,7 +127,7 @@ class GetHOTP : Command { struct CommandPayload { uint8_t slot_number; - bool isValid() const { return !(slot_number & 0xF0); } + bool isValid() const { return (slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; ss << "slot_number:\t" << (int)(slot_number) << std::endl; @@ -146,7 +146,7 @@ class GetHOTP : Command { } } __packed; - typedef Transaction + typedef Transaction CommandTransaction; }; @@ -473,8 +473,15 @@ class UserAuthenticate : Command { class Authorize : Command { public: struct CommandPayload { - uint8_t crc[4]; - uint8_t password[25]; + uint32_t crc_to_authorize; + uint8_t temporary_password[25]; + + std::string dissect() const { + std::stringstream ss; + ss << " crc_to_authorize:\t" << crc_to_authorize<< std::endl; + ss << " temporary_password:\t" << temporary_password<< std::endl; + return ss.str(); + } } __packed; typedef Transaction @@ -484,8 +491,14 @@ class Authorize : Command { class UserAuthorize : Command { public: struct CommandPayload { - uint8_t crc[4]; - uint8_t password[25]; + uint8_t crc_to_authorize[4]; + uint8_t temporary_password[25]; + std::string dissect() const { + std::stringstream ss; + ss << " crc_to_authorize:\t" << crc_to_authorize<< std::endl; + ss << " temporary_password:\t" << temporary_password<< std::endl; + return ss.str(); + } } __packed; typedef Transaction -- cgit v1.2.3