From ab0f01c381c16ed61b8258582869912d4c38cbb7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 28 Jun 2017 11:57:21 +0200 Subject: Adjust code to make compilation under MSVC 2017 --- include/dissect.h | 4 ++-- include/misc.h | 2 +- include/stick10_commands.h | 10 +++++----- include/stick10_commands_0.8.h | 6 +++--- include/stick20_commands.h | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/dissect.h b/include/dissect.h index 69a5129..06b99fa 100644 --- a/include/dissect.h +++ b/include/dissect.h @@ -22,7 +22,7 @@ class QueryDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); #endif out << "Contents:" << std::endl; @@ -87,7 +87,7 @@ class ResponseDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); #endif out << "Device status:\t" << pod.device_status + 0 << " " diff --git a/include/misc.h b/include/misc.h index 176b77c..25f3107 100644 --- a/include/misc.h +++ b/include/misc.h @@ -62,7 +62,7 @@ typename T::CommandPayload get_payload(){ CMDTYPE::CommandTransaction::run(stick, p); } - std::string hexdump(const char *p, size_t size, bool print_header=true, bool print_ascii=true, + std::string hexdump(const uint8_t *p, size_t size, bool print_header=true, bool print_ascii=true, bool print_empty=true); uint32_t stm_crc32(const uint8_t *data, size_t size); std::vector hex_string_to_byte(const char* hexString); diff --git a/include/stick10_commands.h b/include/stick10_commands.h index e863328..8f3ceef 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -130,7 +130,7 @@ class WriteToHOTPSlot : Command { 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); + << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); return ss.str(); } @@ -334,7 +334,7 @@ class ReadSlot : Command { 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); + << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); return ss.str(); } } __packed; @@ -372,13 +372,13 @@ class GetStatus : Command { ss << "firmware_version:\t" << "[" << firmware_version << "]" << "\t" << ::nitrokey::misc::hexdump( - (const char *)(&firmware_version), sizeof firmware_version, false); + (const uint8_t *)(&firmware_version), sizeof firmware_version, false); ss << "card_serial_u32:\t" << std::hex << card_serial_u32 << std::endl; ss << "card_serial:\t" - << ::nitrokey::misc::hexdump((const char *)(card_serial), + << ::nitrokey::misc::hexdump((const uint8_t *)(card_serial), sizeof card_serial, false); ss << "general_config:\t" - << ::nitrokey::misc::hexdump((const char *)(general_config), + << ::nitrokey::misc::hexdump((const uint8_t *)(general_config), sizeof general_config, false); ss << "numlock:\t" << (int)numlock << std::endl; ss << "capslock:\t" << (int)capslock << std::endl; diff --git a/include/stick10_commands_0.8.h b/include/stick10_commands_0.8.h index 4209380..361682d 100644 --- a/include/stick10_commands_0.8.h +++ b/include/stick10_commands_0.8.h @@ -94,7 +94,7 @@ namespace nitrokey { ss << "id:\t" << (int)id << std::endl; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (&data), sizeof data); + << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -113,7 +113,7 @@ namespace nitrokey { std::stringstream ss; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (&data), sizeof data); + << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -165,7 +165,7 @@ namespace nitrokey { ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; ss << "slot_number:\t" << (int) (slot_number) << std::endl; ss << "slot_counter_or_interval:\t[" << (int) slot_counter_or_interval << "]\t" - << ::nitrokey::misc::hexdump((const char *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); + << ::nitrokey::misc::hexdump((const uint8_t *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); ss << "slot_token_id:\t"; for (auto i : slot_token_id) diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5f99d28..64df372 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -111,7 +111,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (_padding), + << ::nitrokey::misc::hexdump((const uint8_t *) (_padding), sizeof _padding); print_to_ss((int) SendCounter_u8); print_to_ss((int) SendDataType_u8); @@ -138,9 +138,9 @@ namespace nitrokey { union{ uint8_t VersionInfo_au8[4]; struct { - uint8_t __reserved; + uint8_t _reserved; uint8_t minor; - uint8_t __reserved2; + uint8_t _reserved2; uint8_t major; } __packed versionInfo; } __packed; -- cgit v1.2.1 From 2da9ee14459d169fd033e36efe8780250b4283b1 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 28 Jun 2017 11:57:21 +0200 Subject: Run compilation using Qt Creator --- include/command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/command.h b/include/command.h index 3f711c0..279754a 100644 --- a/include/command.h +++ b/include/command.h @@ -11,7 +11,7 @@ #define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << "***********" << std::endl ); #endif #define hexdump_to_ss(x) (ss << #x":\n"\ - << ::nitrokey::misc::hexdump((const char *) (&x), sizeof x, false)); + << ::nitrokey::misc::hexdump((const uint8_t *) (&x), sizeof x, false)); namespace nitrokey { namespace proto { -- cgit v1.2.1 From 36b563b8efa720f56739019778086762cc6aaa81 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 1 Jun 2017 19:47:53 +0200 Subject: Show more detailed status in debug log Signed-off-by: Szczepan Zalega --- include/stick20_commands.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5f99d28..f4da337 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -184,14 +184,19 @@ namespace nitrokey { print_to_ss( MagicNumber_StickConfig_u16 ); print_to_ss((int) ReadWriteFlagUncryptedVolume_u8 ); print_to_ss((int) ReadWriteFlagCryptedVolume_u8 ); + print_to_ss((int) ReadWriteFlagHiddenVolume_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) NewSDCardFound_st.NewCard ); + print_to_ss((int) NewSDCardFound_st.Counter ); print_to_ss((int) SDFillWithRandomChars_u8 ); print_to_ss( ActiveSD_CardID_u32 ); print_to_ss((int) VolumeActiceFlag_u8 ); + print_to_ss((int) VolumeActiceFlag_st.unencrypted ); + print_to_ss((int) VolumeActiceFlag_st.encrypted ); + print_to_ss((int) VolumeActiceFlag_st.hidden); print_to_ss((int) NewSmartCardFound_u8 ); print_to_ss((int) UserPwRetryCount ); print_to_ss((int) AdminPwRetryCount ); -- cgit v1.2.1 From 2a3e72179f1cadc01897d74a5fc87686863ec258 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 25 May 2017 13:10:36 +0200 Subject: Show warning message about invalid incoming packet's CRC Signed-off-by: Szczepan Zalega --- include/device_proto.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index b557384..c126acd 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -352,12 +352,6 @@ namespace nitrokey { clear_packet(outp); - if (!resp.isCRCcorrect()) - LOGD(std::string("Accepting response from device with invalid CRC. ") - + "Command ID: " + std::to_string(resp.command_id) + " " + - commandid_to_string(static_cast(resp.command_id)) - ); - if (status <= 0) { dev->m_counters.receiving_error++; @@ -398,6 +392,14 @@ namespace nitrokey { dev->m_counters.successful_storage_commands++; } + if (!resp.isCRCcorrect()) + LOG(std::string("Accepting response from device with invalid CRC. ") + + "Command ID: " + std::to_string(resp.command_id) + " " + + commandid_to_string(static_cast(resp.command_id)) + " " + + "Reported and calculated: " + std::to_string(resp.crc) + "!=" + std::to_string(resp.calculate_CRC()), + Loglevel::WARNING + ); + // See: DeviceResponse return resp; } -- cgit v1.2.1 From 7e9fb2806f301f98b48e462d18fd1d3531db024a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 11 Sep 2017 10:57:30 +0200 Subject: Do not make longer waiting than 500ms on iteration Signed-off-by: Szczepan Zalega --- include/device_proto.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index c126acd..691c17b 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -312,6 +312,7 @@ namespace nitrokey { std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); } else { retry_timeout *= 2; + retry_timeout = std::min(retry_timeout, 500ms); busy_counter = 0; LOG("Status busy, decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter) + ", current delay:" -- cgit v1.2.1 From ff1f2248b830ad78833e347be8d8c8dc9cb03c85 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 15 Sep 2017 16:34:11 +0200 Subject: Correct mutex placement Move mutex from template instantation to single compilation unit to make it work as desired Signed-off-by: Szczepan Zalega --- include/device_proto.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index 691c17b..4a548a0 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -37,6 +37,9 @@ namespace nitrokey { namespace proto { + extern std::mutex send_receive_mtx; + + /* * POD types for HID proto commands * Instances are meant to be __packed. @@ -215,7 +218,6 @@ namespace nitrokey { using namespace ::nitrokey::log; using namespace std::chrono_literals; - static std::mutex send_receive_mtx; std::lock_guard guard(send_receive_mtx); LOG(__FUNCTION__, Loglevel::DEBUG_L2); -- cgit v1.2.1 From 09d699a7c7edce60547a3e9900301e1ea62188f6 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 15 Sep 2017 16:35:46 +0200 Subject: Decrease busy-delay count Signed-off-by: Szczepan Zalega --- include/device_proto.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index 4a548a0..6631d2f 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -308,7 +308,7 @@ namespace nitrokey { } if (resp.device_status == static_cast(stick10::device_status::busy)) { dev->m_counters.busy++; - if (busy_counter++<10) { + if (busy_counter++<3) { receiving_retry_counter++; LOG("Status busy, not decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); -- cgit v1.2.1 From a83419fe4a13bc77005d455dd89685b8c1443d96 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 15 Sep 2017 16:36:18 +0200 Subject: Set lower maximum between-sending delay Signed-off-by: Szczepan Zalega --- include/device_proto.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/device_proto.h b/include/device_proto.h index 6631d2f..bb14b42 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -314,7 +314,7 @@ namespace nitrokey { std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); } else { retry_timeout *= 2; - retry_timeout = std::min(retry_timeout, 500ms); + retry_timeout = std::min(retry_timeout, 300ms); busy_counter = 0; LOG("Status busy, decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter) + ", current delay:" -- cgit v1.2.1