From f19e5bdc349f0a98234745f66ef72324f47c656b Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 29 Mar 2016 14:15:49 +0200 Subject: working hotp tests on nitrokey pro (stick10) Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 9 ++++++++- unittest/test_HOTP.cc | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 60c947f..f58ace4 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -136,12 +136,19 @@ class GetHOTP : Command { } __packed; struct ResponsePayload { - uint8_t code[18]; + union { + uint8_t whole_response[18]; //TODO remove if not needed + struct { + uint32_t code; + uint8_t config; + } __packed; + } __packed; bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; ss << "code:\t" << (code) << std::endl; + ss << "config:\t" << "TODO" /*(config) */<< std::endl; //TODO show byte field options return ss.str(); } } __packed; diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index bc3650a..c4af104 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -81,11 +81,25 @@ TEST_CASE("Slot names are correct", "[slotNames]") { //run hotp command WriteToHOTPSlot::CommandTransaction::run(stick, hwrite); - GetHOTP::CommandTransaction::CommandPayload gh; - gh.slot_number = 0x10; - auto resp = GetHOTP::CommandTransaction::run(stick, gh); - REQUIRE( string(reinterpret_cast(resp.code)) == "755224"); + uint32_t codes[] = { + 755224, + 287082, + 359152, + 969429, + 338314, + 254676, + 287922, + 162583, + 399871, + 520489 + }; + for( auto code: codes){ + GetHOTP::CommandTransaction::CommandPayload gh; + gh.slot_number = 0x10; + auto resp = GetHOTP::CommandTransaction::run(stick, gh); + REQUIRE( resp.code == code); + } } -- cgit v1.2.1