From 0c6f3234acea5888dd6c3c3aeee8cebcce59ba06 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 11 Jan 2017 15:57:45 +0100 Subject: Use stdint instead of inttypes Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index f02fd70..9b72e92 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -4,7 +4,7 @@ #include #include #include -#include "inttypes.h" +#include #include "command.h" #include "device_proto.h" -- cgit v1.2.1 From 3d54b4ea0c96a2420973dc840c1b32545bf2b05d Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 18 Jan 2017 00:11:25 +0100 Subject: Fix getting card serial todo: remove whitespace at the string end Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 9b72e92..fb362fb 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -332,7 +332,7 @@ class GetStatus : Command { std::string get_card_serial_hex() const { return ::nitrokey::misc::hexdump((const char *)(card_serial), - sizeof card_serial, false); + sizeof card_serial, false, false, false); } std::string dissect() const { -- cgit v1.2.1 From 2543e09fa25fa8ed54920c519de32d4b4da074d4 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 24 Jan 2017 17:33:49 +0100 Subject: Read slot command support Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index fb362fb..b66a9b4 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -293,18 +293,44 @@ class ReadSlot : Command { struct ResponsePayload { uint8_t slot_name[15]; - uint8_t config; - uint8_t token_id[13]; - uint64_t counter; + union{ + uint8_t _slot_config; + struct{ + bool use_8_digits : 1; + bool use_enter : 1; + bool use_tokenID : 1; + }; + }; + union{ + uint8_t slot_token_id[13]; /** OATH Token Identifier */ + struct{ /** @see https://openauthentication.org/token-specs/ */ + uint8_t omp[2]; + uint8_t tt[2]; + uint8_t mui[8]; + uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805 + } slot_token_fields; + }; + union{ + uint64_t slot_counter; + uint8_t slot_counter_s[8]; + } __packed; bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; ss << "slot_name:\t" << slot_name << std::endl; - ss << "config:\t" << config << std::endl; - ss << "token_id:\t" << token_id << std::endl; - ss << "counter:\t" << counter << std::endl; + ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; + ss << "\tuse_enter(1):\t" << use_enter << std::endl; + ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; + + ss << "slot_token_id:\t"; + for (auto i : slot_token_id) + ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; + ss << std::endl; + ss << "slot_counter:\t[" << (int)slot_counter << "]\t" + << ::nitrokey::misc::hexdump((const char *)(&slot_counter), sizeof slot_counter, false); return ss.str(); } } __packed; -- cgit v1.2.1 From 48ec48d2c680b9f40d2b038fda9555bfd024bb97 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 30 Jan 2017 20:31:18 +0100 Subject: Use local hexdumping function for getting serial number Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index b66a9b4..8d37dbd 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -357,8 +357,14 @@ class GetStatus : Command { bool isValid() const { return enable_user_password!=delete_user_password; } std::string get_card_serial_hex() const { - return ::nitrokey::misc::hexdump((const char *)(card_serial), - sizeof card_serial, false, false, false); +// return ::nitrokey::misc::hexdump((const char *)(card_serial), +// sizeof card_serial, false, false, false); + std::stringstream ss; + ss << std::hex << std::setfill('0'); + for (int i = 0; i < sizeof(card_serial); ++i) { + ss << std::setw(2) << static_cast(card_serial[i]); + } + return ss.str(); } std::string dissect() const { -- cgit v1.2.1 From adbc664125142c434294bfa795666c90c7608429 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 9 Mar 2017 18:49:24 +0100 Subject: Adjust for compilation on Visual Studio 2017 Building works however tests are not. Possibly linking with original hidapi solution would work. --- include/stick10_commands.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 8d37dbd..3d9e234 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -1,5 +1,6 @@ #ifndef STICK10_COMMANDS_H #define STICK10_COMMANDS_H + #include #include #include @@ -8,9 +9,13 @@ #include "command.h" #include "device_proto.h" +#pragma pack (push,1) + namespace nitrokey { namespace proto { + + /* * Stick10 protocol definition */ @@ -844,8 +849,11 @@ class BuildAESKey : Command { typedef Transaction CommandTransaction; + }; + } } } +#pragma pack (pop) #endif -- cgit v1.2.1 From 5650e48b114529075d89dbdde0330901351b8460 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 17 Feb 2017 16:29:21 +0100 Subject: Get proper card serial for Storage. Get serial as one number. Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 3d9e234..843d8bd 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -348,7 +348,10 @@ class GetStatus : Command { public: struct ResponsePayload { uint16_t firmware_version; - uint8_t card_serial[4]; + union{ + uint8_t card_serial[4]; + uint32_t card_serial_i; + } __packed; union { uint8_t general_config[5]; struct{ @@ -357,19 +360,12 @@ class GetStatus : Command { uint8_t scrolllock; /** same as numlock */ uint8_t enable_user_password; uint8_t delete_user_password; - }; - }; + } __packed; + } __packed; bool isValid() const { return enable_user_password!=delete_user_password; } std::string get_card_serial_hex() const { -// return ::nitrokey::misc::hexdump((const char *)(card_serial), -// sizeof card_serial, false, false, false); - std::stringstream ss; - ss << std::hex << std::setfill('0'); - for (int i = 0; i < sizeof(card_serial); ++i) { - ss << std::setw(2) << static_cast(card_serial[i]); - } - return ss.str(); + return nitrokey::misc::toHex(card_serial_i); } std::string dissect() const { @@ -378,6 +374,7 @@ class GetStatus : Command { << "[" << firmware_version << "]" << "\t" << ::nitrokey::misc::hexdump( (const char *)(&firmware_version), sizeof firmware_version, false); + ss << "card_serial_i:\t" << std::hex << card_serial_i << std::endl; ss << "card_serial:\t" << ::nitrokey::misc::hexdump((const char *)(card_serial), sizeof card_serial, false); -- cgit v1.2.1 From 0fb8c08704a338bb9f1b7d3ead4b488bf65cf51e Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 17 Feb 2017 17:52:54 +0100 Subject: Make names more consistent Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 843d8bd..676aabc 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -350,7 +350,7 @@ class GetStatus : Command { uint16_t firmware_version; union{ uint8_t card_serial[4]; - uint32_t card_serial_i; + uint32_t card_serial_u32; } __packed; union { uint8_t general_config[5]; @@ -365,7 +365,7 @@ class GetStatus : Command { bool isValid() const { return enable_user_password!=delete_user_password; } std::string get_card_serial_hex() const { - return nitrokey::misc::toHex(card_serial_i); + return nitrokey::misc::toHex(card_serial_u32); } std::string dissect() const { @@ -374,7 +374,7 @@ class GetStatus : Command { << "[" << firmware_version << "]" << "\t" << ::nitrokey::misc::hexdump( (const char *)(&firmware_version), sizeof firmware_version, false); - ss << "card_serial_i:\t" << std::hex << card_serial_i << std::endl; + ss << "card_serial_u32:\t" << std::hex << card_serial_u32 << std::endl; ss << "card_serial:\t" << ::nitrokey::misc::hexdump((const char *)(card_serial), sizeof card_serial, false); -- cgit v1.2.1 From f12b6a9c29f8d236ca969f45d3be1cd9ee5a749f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 28 Feb 2017 19:13:01 +0100 Subject: Reorder includes Signed-off-by: Szczepan Zalega --- include/stick10_commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/stick10_commands.h') diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 676aabc..a50d0ae 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -6,8 +6,8 @@ #include #include #include -#include "command.h" #include "device_proto.h" +#include "command.h" #pragma pack (push,1) -- cgit v1.2.1