diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-07-26 17:14:33 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-01 13:54:57 +0200 |
commit | 664d33c8966f478d6f077a666a39a5b76a235ffa (patch) | |
tree | 974a2eb7ac68d07831f0bcc118888fd9e7291cba | |
parent | 32ed4100e098ae2930e6fd94800c6ce7041101c2 (diff) | |
download | libnitrokey-664d33c8966f478d6f077a666a39a5b76a235ffa.tar.gz libnitrokey-664d33c8966f478d6f077a666a39a5b76a235ffa.tar.bz2 |
Handling PW safe login and password
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | NK_C_API.cc | 8 | ||||
-rw-r--r-- | NK_C_API.h | 4 | ||||
-rw-r--r-- | NitrokeyManager.cc | 4 | ||||
-rw-r--r-- | include/NitrokeyManager.h | 5 | ||||
-rw-r--r-- | include/stick10_commands.h | 12 | ||||
-rw-r--r-- | unittest/test_bindings.py | 13 |
6 files changed, 29 insertions, 17 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index f01f0f5..c0910a2 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -281,16 +281,16 @@ extern const char *NK_get_password_safe_slot_name(uint8_t slot_number, const cha }); } -extern const char *NK_get_password_safe_slot_login(uint8_t slot_number) { +extern const char *NK_get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password) { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ - return m->get_password_safe_slot_login(slot_number); + return m->get_password_safe_slot_login(slot_number, temporary_password); }); } -extern const char *NK_get_password_safe_slot_password(uint8_t slot_number) { +extern const char *NK_get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password) { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ - return m->get_password_safe_slot_password(slot_number); + return m->get_password_safe_slot_password(slot_number, temporary_password); }); } extern int NK_write_password_safe_slot(){ @@ -34,8 +34,8 @@ extern uint8_t NK_get_admin_retry_count(); extern int NK_enable_password_safe(const char *user_pin); extern int NK_get_password_safe_slot_status(); extern const char *NK_get_password_safe_slot_name(uint8_t slot_number, const char *temporary_password); -extern const char *NK_get_password_safe_slot_login(uint8_t slot_number); -extern const char *NK_get_password_safe_slot_password(uint8_t slot_number); +extern const char *NK_get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password); +extern const char *NK_get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password); extern int NK_write_password_safe_slot(); } diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 8f5db6f..e0f5fa3 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -249,14 +249,14 @@ namespace nitrokey{ return strdup((const char *) response.slot_name); } - const char *NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number) { + const char *NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password) { auto p = get_payload<GetPasswordSafeSlotLogin>(); p.slot_number = slot_number; auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(*device, p); return strdup((const char *) response.slot_login); } - const char *NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) { + const char *NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password) { auto p = get_payload<GetPasswordSafeSlotPassword>(); p.slot_number = slot_number; auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(*device, p); diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index d9844c9..6f65324 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -50,8 +50,8 @@ namespace nitrokey { void lock_device(); const char *get_password_safe_slot_name(uint8_t slot_number, const char *temporary_password); - const char *get_password_safe_slot_password(uint8_t slot_number); - const char *get_password_safe_slot_login(uint8_t slot_number); + const char *get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password); + const char *get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password); private: NitrokeyManager(); @@ -67,6 +67,7 @@ namespace nitrokey { uint8_t get_internal_slot_number_for_totp(uint8_t slot_number) const; bool erase_slot(uint8_t slot_number); uint8_t *get_slot_name(uint8_t slot_number) const; + }; } diff --git a/include/stick10_commands.h b/include/stick10_commands.h index d350044..92bddd5 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -376,7 +376,7 @@ class GetPasswordSafeSlotName : Command<CommandID::GET_PW_SAFE_SLOT_NAME> { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number\t" << slot_number << std::endl; + ss << "slot_number\t" << (int)slot_number << std::endl; return ss.str(); } } __packed; @@ -387,7 +387,7 @@ class GetPasswordSafeSlotName : Command<CommandID::GET_PW_SAFE_SLOT_NAME> { bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - ss << " slot_name\t" << slot_name << std::endl; + ss << " slot_name\t" << (char*)slot_name << std::endl; return ss.str(); } } __packed; @@ -405,7 +405,7 @@ class GetPasswordSafeSlotPassword bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << slot_number << std::endl; + ss << " slot_number\t" << (int)slot_number << std::endl; return ss.str(); } } __packed; @@ -416,7 +416,7 @@ class GetPasswordSafeSlotPassword bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - ss << " slot_password\t" << slot_password << std::endl; + ss << " slot_password\t" << (char*)slot_password << std::endl; return ss.str(); } } __packed; @@ -434,7 +434,7 @@ class GetPasswordSafeSlotLogin bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << slot_number << std::endl; + ss << " slot_number\t" << (int)slot_number << std::endl; return ss.str(); } } __packed; @@ -445,7 +445,7 @@ class GetPasswordSafeSlotLogin bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - ss << " slot_login\t" << slot_login << std::endl; + ss << " slot_login\t" << (char*)slot_login << std::endl; return ss.str(); } } __packed; diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py index f5d5cf7..6d9e490 100644 --- a/unittest/test_bindings.py +++ b/unittest/test_bindings.py @@ -55,7 +55,7 @@ def test_enable_password_safe(C): def test_get_password_safe_slot_name(C): - C.NK_set_debug(True) + # C.NK_set_debug(True) assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK assert gs(C.NK_get_password_safe_slot_name(0, '123123123')) == '' assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_NOT_AUTHORIZED @@ -63,6 +63,17 @@ def test_get_password_safe_slot_name(C): assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK assert gs(C.NK_get_password_safe_slot_name(0, '123123123')) == '1' assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + # C.NK_set_debug(False) + +def test_get_password_safe_slot_login_password(C): + C.NK_set_debug(True) + assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + slot_login = C.NK_get_password_safe_slot_login(0, '123123123') + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + assert gs(slot_login) == '1' + slot_password = gs(C.NK_get_password_safe_slot_password(0, '123123123')) + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + assert slot_password == '1' C.NK_set_debug(False) |