diff options
-rw-r--r-- | NK_C_API.cc | 9 | ||||
-rw-r--r-- | NK_C_API.h | 2 | ||||
-rw-r--r-- | NitrokeyManager.cc | 7 | ||||
-rw-r--r-- | include/NitrokeyManager.h | 2 | ||||
-rw-r--r-- | unittest/test_bindings.py | 9 |
5 files changed, 19 insertions, 10 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 4f7195e..094a7e3 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -241,16 +241,17 @@ extern int NK_enable_password_safe(const char *user_pin){ } return 0; } -extern int NK_get_password_safe_slot_status(){ +extern uint8_t * NK_get_password_safe_slot_status(){ auto m = NitrokeyManager::instance(); + auto res = new uint8_t[16]; + memset(res, 0, 16); try { - m->get_password_safe_slot_status(); //TODO FIXME + return m->get_password_safe_slot_status(); //TODO FIXME } catch (CommandFailedException & commandFailedException){ NK_last_command_status = commandFailedException.last_command_status; - return commandFailedException.last_command_status; } - return 0; + return res; } extern uint8_t NK_get_user_retry_count(){ @@ -32,7 +32,7 @@ extern uint8_t NK_get_user_retry_count(); extern uint8_t NK_get_admin_retry_count(); //password safe extern int NK_enable_password_safe(const char *user_pin); -extern int NK_get_password_safe_slot_status(); +extern uint8_t * 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, const char *temporary_password); extern const char *NK_get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password); diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index e541b47..ef0eb5e 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -219,9 +219,12 @@ namespace nitrokey{ EnablePasswordSafe::CommandTransaction::run(*device, p); } - void NitrokeyManager::get_password_safe_slot_status() { + uint8_t * NitrokeyManager::get_password_safe_slot_status() { auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(*device); //TODO FIXME - responsePayload.password_safe_status; + auto res = new uint8_t[16]; + memcpy(res, responsePayload.password_safe_status, 16*sizeof (uint8_t)); + //FIXME return vector<uint8_t> and do copy on C_API side + return res; } uint8_t NitrokeyManager::get_user_retry_count() { diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 63332aa..00011e2 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -42,7 +42,7 @@ namespace nitrokey { void enable_password_safe(const char *user_pin); - void get_password_safe_slot_status(); + uint8_t * get_password_safe_slot_status(); uint8_t get_admin_retry_count(); uint8_t get_user_retry_count(); diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py index 4d749bd..9591751 100644 --- a/unittest/test_bindings.py +++ b/unittest/test_bindings.py @@ -90,12 +90,17 @@ def test_erase_password_safe_slot(C): assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK assert C.NK_erase_password_safe_slot(0) == DeviceErrorCode.STATUS_OK assert gs(C.NK_get_password_safe_slot_name(0, DefaultPasswords.ADMIN_TEMP)) == '' - assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK # TODO shouldn't be DeviceErrorCode.NOT_PROGRAMMED ? + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK # TODO CHECK shouldn't this be DeviceErrorCode.NOT_PROGRAMMED ? def test_password_safe_slot_status(C): C.NK_set_debug(True) - assert C.NK_get_password_safe_slot_status() == DeviceErrorCode.STATUS_OK + safe_slot_status = C.NK_get_password_safe_slot_status() + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + is_slot_programmed = list(ffi.cast("uint8_t [16]", safe_slot_status)[0:16]) + print ((is_slot_programmed, len(is_slot_programmed))) + assert is_slot_programmed[0] == 0 # FIXME not programmed, assuming erased in preceeding test, add writing and erasing + assert is_slot_programmed[1] == 1 # FIXME assuming slot 1 is programmed, not writing there in this tests, same as ^ C.NK_set_debug(False) |