summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-04-10 08:19:42 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-04-10 08:19:42 +0200
commit306186faab1bf1b8321fecdb2c50176b35a3f953 (patch)
tree3769e709ceb001ad931ebbab99d336372df127f2
parent92d4621442795b83dff55009c99e47d4a3d93bef (diff)
parent7f3d4ce81a0a38d9591dc4c746bcb75edfe80caa (diff)
downloadlibnitrokey-306186faab1bf1b8321fecdb2c50176b35a3f953.tar.gz
libnitrokey-306186faab1bf1b8321fecdb2c50176b35a3f953.tar.bz2
Merge branch '102-get_status_invalid'
Fixes #102
-rw-r--r--NK_C_API.h4
-rw-r--r--NitrokeyManager.cc10
-rw-r--r--libnitrokey/stick10_commands.h11
-rw-r--r--libnitrokey/stick10_commands_0.8.h6
4 files changed, 20 insertions, 11 deletions
diff --git a/NK_C_API.h b/NK_C_API.h
index b78bde5..f5b87ad 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -155,8 +155,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
*/
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 48196a9..8bb1a2a 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -855,11 +855,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<stick10_08::WriteGeneralConfig>();
- 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<uint8_t>(enable_user_password ? 1 : 0);
+ p.delete_user_password = static_cast<uint8_t>(delete_user_password ? 1 : 0);
if (is_authorization_command_supported()){
authorize_packet<stick10_08::WriteGeneralConfig, Authorize>(p, admin_temporary_password, device);
} else {
diff --git a/libnitrokey/stick10_commands.h b/libnitrokey/stick10_commands.h
index 893b98f..f2ffba2 100644
--- a/libnitrokey/stick10_commands.h
+++ b/libnitrokey/stick10_commands.h
@@ -385,10 +385,13 @@ class GetStatus : Command<CommandID::GET_STATUS> {
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; }
+
+ 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);
@@ -684,7 +687,9 @@ class WriteGeneralConfig : Command<CommandID::WRITE_CONFIG> {
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..9477890 100644
--- a/libnitrokey/stick10_commands_0.8.h
+++ b/libnitrokey/stick10_commands_0.8.h
@@ -322,7 +322,11 @@ namespace nitrokey {
};
uint8_t temporary_admin_password[25];
- std::string dissect() const {
+ 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;
ss << "numlock:\t" << (int)numlock << std::endl;
ss << "capslock:\t" << (int)capslock << std::endl;