aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-21 08:40:15 +0100
committerSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-21 08:40:15 +0100
commit20028b40e61e79856c15181ed0b5061ab6d4fa29 (patch)
treed0969db5fa115f1370cda32aff6783e771ec0bf7
parent9f4fff341b1ca691c4b1de135dcae392e1ff5602 (diff)
downloadlibnitrokey-20028b40e61e79856c15181ed0b5061ab6d4fa29.tar.gz
libnitrokey-20028b40e61e79856c15181ed0b5061ab6d4fa29.tar.bz2
implementing hotp test
-rw-r--r--include/stick10_commands.h21
-rw-r--r--unittest/test_HOTP.cc11
2 files changed, 30 insertions, 2 deletions
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index 8f45f20..13aa24f 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -68,6 +68,16 @@ class WriteToHOTPSlot : Command<CommandID::WRITE_TO_SLOT> {
uint8_t slot_counter[8];
bool isValid() const { return !(slot_number & 0xF0); }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << "slot_number:\t" << (int)(slot_number) << std::endl;
+ ss << "slot_name" << slot_name << std::endl;
+ ss << "slot_secret" << slot_secret << std::endl;
+ ss << "slot_config" << slot_config << std::endl;
+ ss << "slot_token_id" << slot_token_id << std::endl;
+ ss << "slot_counter" << slot_counter << std::endl;
+ return ss.str();
+ }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
@@ -118,6 +128,17 @@ class GetHOTP : Command<CommandID::GET_CODE> {
uint8_t slot_number;
bool isValid() const { return !(slot_number & 0xF0); }
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << "slot_number:\t" << (int)(slot_number) << std::endl;
+ return ss.str();
+ }
+ } __packed;
+
+ struct ResponsePayload {
+ uint8_t code[18];
+
+ bool isValid() const { return true; }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc
index c1147d3..a61bc28 100644
--- a/unittest/test_HOTP.cc
+++ b/unittest/test_HOTP.cc
@@ -23,6 +23,7 @@ std::string getSlotName(Stick10 &stick, int slotNo) {
void setSecret (uint8_t slot_secret[], const char* secretHex){
assert(strlen(secretHex)%2==0);
+ //assert(strlen(secretHex)==(sizeof slot_secret)*2);
char buf[2];
for(int i=0; i<strlen(secretHex); i++){
buf[i%2] = secretHex[i];
@@ -37,7 +38,7 @@ TEST_CASE("test secret", "[functions]") {
slot_secret[20] = 0;
const char* secretHex = "3132333435363738393031323334353637383930";
setSecret(slot_secret, secretHex);
- WARN(slot_secret);
+ CAPTURE(slot_secret);
REQUIRE(strcmp("12345678901234567890",reinterpret_cast<char *>(slot_secret) ) == 0 );
}
@@ -58,7 +59,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
{
WriteToHOTPSlot::CommandTransaction::CommandPayload hwrite;
- hwrite.slot_number = 0;
+ hwrite.slot_number = 0xF;
strcpy(reinterpret_cast<char *>(hwrite.slot_name), "rfc_test");
//strcpy(reinterpret_cast<char *>(hwrite.slot_secret), "");
const char* secretHex = "3132333435363738393031323334353637383930";
@@ -66,6 +67,12 @@ TEST_CASE("Slot names are correct", "[slotNames]") {
//hwrite.slot_config;
strcpy(reinterpret_cast<char *>(hwrite.slot_token_id), "");
strcpy(reinterpret_cast<char *>(hwrite.slot_counter), "");
+ WriteToHOTPSlot::CommandTransaction::run(stick, hwrite);
+
+ GetHOTP::CommandTransaction::CommandPayload gh;
+ gh.slot_number = 0xF;
+ GetHOTP::CommandTransaction::run(stick, gh);
+
}