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(-) 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.3 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(-) 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.3 From bda5bab9646d3abc6e7209618d8e6f26208274a9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 25 May 2017 13:12:15 +0200 Subject: Catch invalid CRC exception in C API To handle invalid response packets in C API Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NK_C_API.cc b/NK_C_API.cc index 0e3fa1f..209b378 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -76,6 +76,12 @@ uint8_t get_without_result(T func){ catch (LibraryException & libraryException){ NK_last_command_status = libraryException.exception_id(); } + catch (const InvalidCRCReceived &invalidCRCException){ + ;;; + } + catch (const DeviceCommunicationException &deviceException){ + NK_last_command_status = -1; + } return NK_last_command_status; } -- cgit v1.2.3 From f53e5e799fe111bcf0b8ed71710e00000e097aca Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 27 Jun 2017 09:42:18 +0200 Subject: Tests: do additional authentication for Pro 0.7 Signed-off-by: Szczepan Zalega --- unittest/test_pro.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest/test_pro.py b/unittest/test_pro.py index 3f1f0a3..c292940 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -727,6 +727,8 @@ def test_HOTP_secrets(C, secret): DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK dev_res = [] lib_res = [] + # repeat authentication for Pro 0.7 + assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK assert C.NK_write_hotp_slot(slot_number, 'secret' + str(len(secret)), secret, counter, use_8_digits, False, False, "", DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK code_device = gs(C.NK_get_hotp_code(slot_number)) -- cgit v1.2.3 From 74c547e08220a55878de74d7c304c3a5cee33b11 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 11 Sep 2017 10:55:49 +0200 Subject: Do not resend command to device Signed-off-by: Szczepan Zalega --- device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.cc b/device.cc index 5f1c9a0..e6edd73 100644 --- a/device.cc +++ b/device.cc @@ -27,7 +27,7 @@ Device::Device(const uint16_t vid, const uint16_t pid, const DeviceModel model, m_vid(vid), m_pid(pid), m_model(model), - m_retry_sending_count(3), + m_retry_sending_count(1), m_retry_receiving_count(retry_receiving_count), m_retry_timeout(retry_timeout), m_send_receive_delay(send_receive_delay), -- cgit v1.2.3 From e1d35ffdaa4147b18ab22a1acc70762c9434a2d7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 11 Sep 2017 10:56:26 +0200 Subject: Log formatting: Enumerate from 1 Signed-off-by: Szczepan Zalega --- device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.cc b/device.cc index e6edd73..a7b68e1 100644 --- a/device.cc +++ b/device.cc @@ -93,7 +93,7 @@ int Device::send(const void *packet) { mp_devhandle, (const unsigned char *)(packet), HID_REPORT_SIZE); if (send_feature_report < 0) _reconnect(); //add thread sleep? - LOG(std::string("Sending attempt: ")+std::to_string(i) + " / 3" , Loglevel::DEBUG_L2); + LOG(std::string("Sending attempt: ")+std::to_string(i+1) + " / 3" , Loglevel::DEBUG_L2); } return send_feature_report; } -- cgit v1.2.3 From 8ea7214692243eadf18c4cdabf66500e8357ba0c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 11 Sep 2017 10:57:08 +0200 Subject: Make only 10 retries on receiving Signed-off-by: Szczepan Zalega --- device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.cc b/device.cc index a7b68e1..2fc55c7 100644 --- a/device.cc +++ b/device.cc @@ -200,7 +200,7 @@ Stick10::Stick10(): Stick20::Stick20(): - Device(0x20a0, 0x4109, DeviceModel::STORAGE, 20ms, 20, 20ms) + Device(0x20a0, 0x4109, DeviceModel::STORAGE, 20ms, 10, 20ms) { setDefaultDelay(); } -- cgit v1.2.3 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(+) 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.3 From 2e446c208e3522ff3b7a38eec40368fe15528a80 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 1 Jun 2017 19:50:19 +0200 Subject: Update hidapi Update to latest version with proper adjustments Signed-off-by: Szczepan Zalega --- hidapi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hidapi b/hidapi index 324dc7c..4e6cb25 160000 --- a/hidapi +++ b/hidapi @@ -1 +1 @@ -Subproject commit 324dc7c0d125f57a06e1107e90e49eb4377bd03c +Subproject commit 4e6cb25a8b48c500326c7d635e01c9f1bbd47306 -- cgit v1.2.3 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 --- NitrokeyManager.cc | 2 ++ include/device_proto.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 9a9d106..7985eb3 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -10,6 +10,8 @@ #include "include/cxx_semantics.h" #include +std::mutex nitrokey::proto::send_receive_mtx; + namespace nitrokey{ std::mutex mex_dev_com_manager; 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.3 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(-) 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.3 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(-) 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.3