aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc6
-rw-r--r--NitrokeyManager.cc2
-rw-r--r--device.cc6
m---------hidapi0
-rw-r--r--include/device_proto.h21
-rw-r--r--include/stick20_commands.h7
-rw-r--r--unittest/test_pro.py2
7 files changed, 32 insertions, 12 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 1f8c12b..bac11b3 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -89,6 +89,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;
}
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 4b3c7e1..0d702eb 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -10,6 +10,8 @@
#include "include/cxx_semantics.h"
#include <functional>
+std::mutex nitrokey::proto::send_receive_mtx;
+
namespace nitrokey{
std::mutex mex_dev_com_manager;
diff --git a/device.cc b/device.cc
index 5f1c9a0..2fc55c7 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),
@@ -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;
}
@@ -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();
}
diff --git a/hidapi b/hidapi
-Subproject 324dc7c0d125f57a06e1107e90e49eb4377bd03
+Subproject 4e6cb25a8b48c500326c7d635e01c9f1bbd4730
diff --git a/include/device_proto.h b/include/device_proto.h
index b557384..bb14b42 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<std::mutex> guard(send_receive_mtx);
LOG(__FUNCTION__, Loglevel::DEBUG_L2);
@@ -306,12 +308,13 @@ namespace nitrokey {
}
if (resp.device_status == static_cast<uint8_t>(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);
} else {
retry_timeout *= 2;
+ 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:"
@@ -352,12 +355,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<CommandID>(resp.command_id))
- );
-
if (status <= 0) {
dev->m_counters.receiving_error++;
@@ -398,6 +395,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<CommandID>(resp.command_id)) + " "
+ + "Reported and calculated: " + std::to_string(resp.crc) + "!=" + std::to_string(resp.calculate_CRC()),
+ Loglevel::WARNING
+ );
+
// See: DeviceResponse
return resp;
}
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index 64df372..eb58af7 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 );
diff --git a/unittest/test_pro.py b/unittest/test_pro.py
index 11873fe..99dcf4d 100644
--- a/unittest/test_pro.py
+++ b/unittest/test_pro.py
@@ -730,6 +730,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, b'secret' + bytes(len(secret)), bb(secret), counter, use_8_digits, False, False, b"",
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
code_device = gs(C.NK_get_hotp_code(slot_number))