From 83da928701b52005b1e29234164b2d21bfdeff39 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:40:29 +0200 Subject: Precise value for p.enable_user_password field to 1 on true, as in firmware Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index db0c0a9..4008bd0 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -840,11 +840,11 @@ using nitrokey::misc::strcpyT; void NitrokeyManager::write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, bool delete_user_password, const char *admin_temporary_password) { auto p = get_payload(); - p.numlock = (uint8_t) numlock; - p.capslock = (uint8_t) capslock; - p.scrolllock = (uint8_t) scrolllock; - p.enable_user_password = (uint8_t) enable_user_password; - p.delete_user_password = (uint8_t) delete_user_password; + p.numlock = numlock; + p.capslock = capslock; + p.scrolllock = scrolllock; + p.enable_user_password = static_cast(enable_user_password ? 1 : 0); + p.delete_user_password = static_cast(delete_user_password ? 1 : 0); if (is_authorization_command_supported()){ authorize_packet(p, admin_temporary_password, device); } else { -- cgit v1.2.1 From 0474b8b06d2be6616d4c909e59466af5151e960b Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:42:56 +0200 Subject: Correct C API documentation Signed-off-by: Szczepan Zalega --- NK_C_API.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NK_C_API.h b/NK_C_API.h index 27730c9..0dae549 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -133,8 +133,8 @@ extern "C" { * or outside the range to disable this function * @param capslock similar to numlock but with capslock * @param scrolllock similar to numlock but with scrolllock - * @param enable_user_password set True to enable OTP PIN protection (request PIN each OTP code request) - * @param delete_user_password set True to disable OTP PIN protection (request PIN each OTP code request) + * @param enable_user_password set True to enable OTP PIN protection (require PIN each OTP code request) + * @param delete_user_password (unused) * @param admin_temporary_password current admin temporary password * @return command processing error code */ -- cgit v1.2.1 From 090af48ee1c49c8655610c7b529b2ca256d9e8ae Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:51:15 +0200 Subject: Correct validation functions for GetStatus and WriteGeneralConfig structs Signed-off-by: Szczepan Zalega --- libnitrokey/stick10_commands.h | 9 ++++++--- libnitrokey/stick10_commands_0.8.h | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libnitrokey/stick10_commands.h b/libnitrokey/stick10_commands.h index 893b98f..755b651 100644 --- a/libnitrokey/stick10_commands.h +++ b/libnitrokey/stick10_commands.h @@ -385,10 +385,11 @@ class GetStatus : Command { uint8_t capslock; /** same as numlock */ uint8_t scrolllock; /** same as numlock */ uint8_t enable_user_password; - uint8_t delete_user_password; + uint8_t delete_user_password; /* unused */ } __packed; } __packed; - bool isValid() const { return enable_user_password!=delete_user_password; } + + bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } std::string get_card_serial_hex() const { return nitrokey::misc::toHex(card_serial_u32); @@ -684,7 +685,9 @@ class WriteGeneralConfig : Command { uint8_t delete_user_password; }; }; - std::string dissect() const { + bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + + std::string dissect() const { std::stringstream ss; ss << "numlock:\t" << (int)numlock << std::endl; ss << "capslock:\t" << (int)capslock << std::endl; diff --git a/libnitrokey/stick10_commands_0.8.h b/libnitrokey/stick10_commands_0.8.h index a04946f..4614f16 100644 --- a/libnitrokey/stick10_commands_0.8.h +++ b/libnitrokey/stick10_commands_0.8.h @@ -322,7 +322,9 @@ namespace nitrokey { }; uint8_t temporary_admin_password[25]; - std::string dissect() const { + bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + + std::string dissect() const { std::stringstream ss; ss << "numlock:\t" << (int)numlock << std::endl; ss << "capslock:\t" << (int)capslock << std::endl; -- cgit v1.2.1 From 7f3d4ce81a0a38d9591dc4c746bcb75edfe80caa Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:55:38 +0200 Subject: Name magic numbers in validation functions Signed-off-by: Szczepan Zalega --- libnitrokey/stick10_commands.h | 4 +++- libnitrokey/stick10_commands_0.8.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libnitrokey/stick10_commands.h b/libnitrokey/stick10_commands.h index 755b651..f2ffba2 100644 --- a/libnitrokey/stick10_commands.h +++ b/libnitrokey/stick10_commands.h @@ -389,7 +389,9 @@ class GetStatus : Command { } __packed; } __packed; - bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + static constexpr uint8_t special_HOTP_slots = 2; + bool isValid() const { return numlock < special_HOTP_slots && capslock < special_HOTP_slots + && scrolllock < special_HOTP_slots && enable_user_password < 2; } std::string get_card_serial_hex() const { return nitrokey::misc::toHex(card_serial_u32); diff --git a/libnitrokey/stick10_commands_0.8.h b/libnitrokey/stick10_commands_0.8.h index 4614f16..9477890 100644 --- a/libnitrokey/stick10_commands_0.8.h +++ b/libnitrokey/stick10_commands_0.8.h @@ -322,7 +322,9 @@ namespace nitrokey { }; uint8_t temporary_admin_password[25]; - bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + static constexpr uint8_t special_HOTP_slots = 3; + bool isValid() const { return numlock < special_HOTP_slots && capslock < special_HOTP_slots + && scrolllock < special_HOTP_slots && enable_user_password < 2; } std::string dissect() const { std::stringstream ss; -- cgit v1.2.1