From 43bb63424fb7e78c245341c1baf326557ef896e8 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 31 Jan 2017 18:53:14 +0100 Subject: C++ tests fixed Signed-off-by: Szczepan Zalega --- unittest/test.cc | 9 +++++---- unittest/test2.cc | 27 ++++++++++++++------------- unittest/test3.cc | 21 ++++++++++++--------- unittest/test_HOTP.cc | 6 +++--- 4 files changed, 34 insertions(+), 29 deletions(-) (limited to 'unittest') diff --git a/unittest/test.cc b/unittest/test.cc index 6744b45..99f96ac 100644 --- a/unittest/test.cc +++ b/unittest/test.cc @@ -13,8 +13,9 @@ using namespace nitrokey::proto::stick10; using namespace nitrokey::log; using namespace nitrokey::misc; +using Dev10 = std::shared_ptr; -std::string getSlotName(Stick10 &stick, int slotNo) { +std::string getSlotName(Dev10 stick, int slotNo) { auto slot_req = get_payload(); slot_req.slot_number = slotNo; auto slot = ReadSlot::CommandTransaction::run(stick, slot_req); @@ -23,8 +24,8 @@ std::string getSlotName(Stick10 &stick, int slotNo) { } TEST_CASE("Slot names are correct", "[slotNames]") { - Stick10 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -79,5 +80,5 @@ TEST_CASE("Slot names are correct", "[slotNames]") { REQUIRE(sName == std::string("login1")); } - stick.disconnect(); + stick->disconnect(); } diff --git a/unittest/test2.cc b/unittest/test2.cc index 00e70e3..4b61a3c 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -20,9 +20,10 @@ using namespace nitrokey::proto::stick20; using namespace nitrokey::log; using namespace nitrokey::misc; +#include template -void execute_password_command(Device &stick, const char *password, const char kind = 'P') { +void execute_password_command(std::shared_ptr stick, const char *password, const char kind = 'P') { auto p = get_payload(); if (kind == 'P'){ p.set_kind_user(); @@ -47,8 +48,8 @@ void SKIP_TEST() { TEST_CASE("long operation test", "[test_long]") { SKIP_TEST(); - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); try{ @@ -123,8 +124,8 @@ TEST_CASE("test device commands ids", "[fast]") { } TEST_CASE("test device internal status with various commands", "[fast]") { - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -147,8 +148,8 @@ TEST_CASE("test device internal status with various commands", "[fast]") { } TEST_CASE("setup hidden volume test", "[hidden]") { - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); stick10::LockDevice::CommandTransaction::run(stick); @@ -170,8 +171,8 @@ TEST_CASE("setup hidden volume test", "[hidden]") { } TEST_CASE("setup multiple hidden volumes", "[hidden]") { - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -207,8 +208,8 @@ TEST_CASE("setup multiple hidden volumes", "[hidden]") { TEST_CASE("update password change", "[dangerous]") { SKIP_TEST(); - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); @@ -228,8 +229,8 @@ TEST_CASE("update password change", "[dangerous]") { } TEST_CASE("general test", "[test]") { - Stick20 stick; - bool connected = stick.connect(); + auto stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); diff --git a/unittest/test3.cc b/unittest/test3.cc index 9049365..215df78 100644 --- a/unittest/test3.cc +++ b/unittest/test3.cc @@ -26,13 +26,15 @@ using namespace nitrokey::proto::stick10_08; using namespace nitrokey::log; using namespace nitrokey::misc; -void connect_and_setup(Stick10 &stick) { - bool connected = stick.connect(); +using Dev10 = std::shared_ptr; + +void connect_and_setup(Dev10 stick) { + bool connected = stick->connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG); } -void authorize(Stick10 &stick) { +void authorize(Dev10 stick) { auto authreq = get_payload(); strcpy((char *) (authreq.card_password), default_admin_pin); strcpy((char *) (authreq.temporary_password), temporary_password); @@ -45,7 +47,8 @@ void authorize(Stick10 &stick) { } TEST_CASE("write slot", "[pronew]"){ - Stick10 stick; + auto stick = make_shared(); + connect_and_setup(stick); authorize(stick); @@ -81,7 +84,7 @@ TEST_CASE("write slot", "[pronew]"){ TEST_CASE("erase slot", "[pronew]"){ - Stick10 stick; + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -107,7 +110,7 @@ TEST_CASE("erase slot", "[pronew]"){ } TEST_CASE("write general config", "[pronew]") { - Stick10 stick; + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -121,7 +124,7 @@ TEST_CASE("write general config", "[pronew]") { } TEST_CASE("authorize user HOTP", "[pronew]") { - Stick10 stick; + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -164,7 +167,7 @@ TEST_CASE("authorize user HOTP", "[pronew]") { } TEST_CASE("check firmware version", "[pronew]") { - Stick10 stick; + auto stick = make_shared(); connect_and_setup(stick); auto p = GetStatus::CommandTransaction::run(stick); @@ -172,7 +175,7 @@ TEST_CASE("check firmware version", "[pronew]") { } TEST_CASE("authorize user TOTP", "[pronew]") { - Stick10 stick; + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index d31df55..c6b62a3 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -34,8 +34,8 @@ TEST_CASE("test secret", "[functions]") { } TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { - Stick10 stick; - bool connected = stick.connect(); + std::shared_ptr stick = make_shared(); + bool connected = stick->connect(); REQUIRE(connected == true); @@ -98,5 +98,5 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") { } - stick.disconnect(); + stick->disconnect(); } -- cgit v1.2.3 From fa02c23ee2f4bef6be8a502e11fc568dc74b4235 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Feb 2017 09:25:03 +0100 Subject: Use CMake instead of Make Signed-off-by: Szczepan Zalega --- CMakeLists.txt | 23 ++++++++++++++++++----- unittest/test.cc | 1 - unittest/test2.cc | 1 - unittest/test3.cc | 5 ----- unittest/test_HOTP.cc | 3 +-- 5 files changed, 19 insertions(+), 14 deletions(-) (limited to 'unittest') diff --git a/CMakeLists.txt b/CMakeLists.txt index c324067..aa6208e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,12 +29,25 @@ set(SOURCE_FILES misc.cc NitrokeyManager.cc NK_C_API.cc include/CommandFailedException.h include/LibraryException.h - unittest/test_C_API.cpp - unittest/catch_main.cpp - unittest/test2.cc - unittest/test3.cc include/LongOperationInProgressException.h include/stick10_commands_0.8.h ) -add_executable(libnitrokey ${SOURCE_FILES}) \ No newline at end of file +#add_library(libnitrokey STATIC ${SOURCE_FILES}) +add_library(nitrokey SHARED ${SOURCE_FILES}) +add_library(catch STATIC unittest/catch_main.cpp ) + +add_executable (test_C_API unittest/test_C_API.cpp) +target_link_libraries (test_C_API PUBLIC nitrokey catch) + +add_executable (test2 unittest/test2.cc) +target_link_libraries (test2 PUBLIC nitrokey catch) + +add_executable (test3 unittest/test3.cc) +target_link_libraries (test3 PUBLIC nitrokey catch) + +add_executable (test_HOTP unittest/test_HOTP.cc) +target_link_libraries (test_HOTP PUBLIC nitrokey catch) + +add_executable (test1 unittest/test.cc) +target_link_libraries (test1 PUBLIC nitrokey catch) diff --git a/unittest/test.cc b/unittest/test.cc index 99f96ac..15235bd 100644 --- a/unittest/test.cc +++ b/unittest/test.cc @@ -1,4 +1,3 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include "catch.hpp" #include diff --git a/unittest/test2.cc b/unittest/test2.cc index 4b61a3c..31dbce8 100644 --- a/unittest/test2.cc +++ b/unittest/test2.cc @@ -1,4 +1,3 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() static const char *const default_admin_pin = "12345678"; static const char *const default_user_pin = "123456"; diff --git a/unittest/test3.cc b/unittest/test3.cc index 215df78..5302044 100644 --- a/unittest/test3.cc +++ b/unittest/test3.cc @@ -1,8 +1,3 @@ -// -// Created by sz on 08.11.16. -// - -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() static const char *const default_admin_pin = "12345678"; static const char *const default_user_pin = "123456"; diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index c6b62a3..e6f7d7c 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -1,4 +1,3 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include "catch.hpp" #include #include "device_proto.h" @@ -14,7 +13,7 @@ using namespace nitrokey::log; using namespace nitrokey::misc; void hexStringToByte(uint8_t data[], const char* hexString){ - assert(strlen(hexString)%2==0); + REQUIRE(strlen(hexString)%2==0); char buf[2]; for(int i=0; i Date: Mon, 6 Feb 2017 10:53:08 +0100 Subject: Use alias for easy device change Signed-off-by: Szczepan Zalega --- unittest/test3.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'unittest') diff --git a/unittest/test3.cc b/unittest/test3.cc index 5302044..9e0ef11 100644 --- a/unittest/test3.cc +++ b/unittest/test3.cc @@ -21,7 +21,8 @@ using namespace nitrokey::proto::stick10_08; using namespace nitrokey::log; using namespace nitrokey::misc; -using Dev10 = std::shared_ptr; +using Dev = Stick10; +using Dev10 = std::shared_ptr; void connect_and_setup(Dev10 stick) { bool connected = stick->connect(); @@ -42,7 +43,7 @@ void authorize(Dev10 stick) { } TEST_CASE("write slot", "[pronew]"){ - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -79,7 +80,7 @@ TEST_CASE("write slot", "[pronew]"){ TEST_CASE("erase slot", "[pronew]"){ - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -105,7 +106,7 @@ TEST_CASE("erase slot", "[pronew]"){ } TEST_CASE("write general config", "[pronew]") { - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -119,7 +120,7 @@ TEST_CASE("write general config", "[pronew]") { } TEST_CASE("authorize user HOTP", "[pronew]") { - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); @@ -162,7 +163,7 @@ TEST_CASE("authorize user HOTP", "[pronew]") { } TEST_CASE("check firmware version", "[pronew]") { - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); auto p = GetStatus::CommandTransaction::run(stick); @@ -170,7 +171,7 @@ TEST_CASE("check firmware version", "[pronew]") { } TEST_CASE("authorize user TOTP", "[pronew]") { - auto stick = make_shared(); + auto stick = make_shared(); connect_and_setup(stick); authorize(stick); -- cgit v1.2.3 From 2d518b08787575914160ea0b1057c26d1d05b764 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Feb 2017 10:54:34 +0100 Subject: Remove Makefile Signed-off-by: Szczepan Zalega --- Makefile | 45 --------------------------------------------- unittest/Makefile | 33 --------------------------------- 2 files changed, 78 deletions(-) delete mode 100644 Makefile delete mode 100644 unittest/Makefile (limited to 'unittest') diff --git a/Makefile b/Makefile deleted file mode 100644 index 977eae6..0000000 --- a/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -CC = $(PREFIX)-gcc -#CXX = $(PREFIX)-g++ -CXX = clang++-3.8 -LD = $(CXX) - -INCLUDE = -Iinclude/ -LIB = -lhidapi-libusb -BUILD = build - -CXXFLAGS = -std=c++14 -fPIC -Wno-gnu-variable-sized-type-not-at-end -SOFLAGS = -shared - -CXXSOURCES = $(wildcard *.cc) -OBJ = $(CXXSOURCES:%.cc=$(BUILD)/%.o) -DEPENDS = $(CXXSOURCES:%.cc=$(BUILD)/%.d) - -all: $(OBJ) $(BUILD)/libnitrokey.so unittest - -lib: $(OBJ) $(BUILD)/libnitrokey.so - -$(BUILD)/libnitrokey.so: $(OBJ) $(DEPENDS) - $(CXX) $(SOFLAGS) $(OBJ) $(LIB) -o $@ - -$(BUILD)/%.d: %.cc - $(CXX) -M $< -o $@ $(INCLUDE) $(CXXFLAGS) - -$(BUILD)/%.o: %.cc $(DEPENDS) - $(CXX) -c $< -o $@ $(INCLUDE) $(CXXFLAGS) - -clean: - rm -f $(OBJ) - rm -f $(BUILD)/libnitrokey.so - ${MAKE} -C unittest clean - -mrproper: clean - rm -f $(BUILD)/*.d - ${MAKE} -C unittest mrproper - -unittest: $(BUILD)/libnitrokey.so - ${MAKE} -C unittest - cd unittest/build && ln -fs ../../build/libnitrokey.so . - -.PHONY: all clean mrproper unittest - -include $(wildcard build/*.d) diff --git a/unittest/Makefile b/unittest/Makefile deleted file mode 100644 index dbd003e..0000000 --- a/unittest/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -CC = $(PREFIX)-gcc -#CXX = $(PREFIX)-g++ -CXX = clang++-3.8 -LD = $(CXX) - -INCLUDE = -I../include -ICatch/single_include/ -LIB = -L../build -LDLIBS = -lnitrokey -BUILD = build - -CXXFLAGS = -std=c++14 -fPIC -Wno-gnu-variable-sized-type-not-at-end - -CXXSOURCES = $(wildcard *.cc) -TARGETS = $(CXXSOURCES:%.cc=$(BUILD)/%) -DEPENDS = $(CXXSOURCES:%.cc=$(BUILD)/%.d) - -$(BUILD)/%.d: %.cc - $(CXX) -M $< -o $@ $(INCLUDE) $(CXXFLAGS) - -$(BUILD)/%: %.cc $(DEPENDS) - $(CXX) $< -o $@ $(INCLUDE) $(LIB) $(CXXFLAGS) $(LDLIBS) - -all: $(TARGETS) - -clean: - rm -f $(TARGETS) - -mrproper: clean - rm -f $(BUILD)/*.d - -.PHONY: all clean mrproper - -include $(wildcard build/*.d) -- cgit v1.2.3 From 735d7eebcf132c1146da14989ed70fda2f01c06f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 18 Feb 2017 17:02:33 +0100 Subject: Add script for installing python dependencies for unit tests Signed-off-by: Szczepan Zalega --- unittest/setup_python_dependencies.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 unittest/setup_python_dependencies.sh (limited to 'unittest') diff --git a/unittest/setup_python_dependencies.sh b/unittest/setup_python_dependencies.sh new file mode 100644 index 0000000..0f1a0f7 --- /dev/null +++ b/unittest/setup_python_dependencies.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pip install -r requirements.txt --user -- cgit v1.2.3 From bd5fd5d6cf42732c4a34c10d390d3596615e9a47 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 18 Feb 2017 17:03:16 +0100 Subject: Remove unnecessary extern keyword from C API Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 121 +++++++++++++++++++++++++++++---------------------- NK_C_API.h | 120 ++++++++++++++++++++++++++++---------------------- unittest/conftest.py | 4 +- 3 files changed, 137 insertions(+), 108 deletions(-) (limited to 'unittest') diff --git a/NK_C_API.cc b/NK_C_API.cc index 0fde829..05102cc 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -76,15 +76,16 @@ uint8_t get_without_result(T func){ return NK_last_command_status; } + extern "C" { -extern uint8_t NK_get_last_command_status(){ +NK_C_API uint8_t NK_get_last_command_status(){ auto _copy = NK_last_command_status; NK_last_command_status = 0; return _copy; } -extern int NK_login(const char *device_model) { +NK_C_API int NK_login(const char *device_model) { auto m = NitrokeyManager::instance(); try { NK_last_command_status = 0; @@ -101,14 +102,14 @@ extern int NK_login(const char *device_model) { return 0; } -extern int NK_logout() { +NK_C_API int NK_logout() { auto m = NitrokeyManager::instance(); return get_without_result( [&](){ m->disconnect(); }); } -extern int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password){ +NK_C_API int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password){ auto m = NitrokeyManager::instance(); return get_without_result( [&](){ return m->first_authenticate(admin_password, admin_temporary_password); @@ -116,34 +117,34 @@ extern int NK_first_authenticate(const char* admin_password, const char* admin_t } -extern int NK_user_authenticate(const char* user_password, const char* user_temporary_password){ +NK_C_API int NK_user_authenticate(const char* user_password, const char* user_temporary_password){ auto m = NitrokeyManager::instance(); return get_without_result( [&](){ m->user_authenticate(user_password, user_temporary_password); }); } -extern int NK_factory_reset(const char* admin_password){ +NK_C_API int NK_factory_reset(const char* admin_password){ auto m = NitrokeyManager::instance(); return get_without_result( [&](){ m->factory_reset(admin_password); }); } -extern int NK_build_aes_key(const char* admin_password){ +NK_C_API int NK_build_aes_key(const char* admin_password){ auto m = NitrokeyManager::instance(); return get_without_result( [&](){ m->build_aes_key(admin_password); }); } -extern int NK_unlock_user_password(const char *admin_password, const char *new_user_password) { +NK_C_API int NK_unlock_user_password(const char *admin_password, const char *new_user_password) { auto m = NitrokeyManager::instance(); return get_without_result( [&](){ m->unlock_user_password(admin_password, new_user_password); }); } -extern int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, +NK_C_API int NK_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 m = NitrokeyManager::instance(); @@ -153,7 +154,7 @@ extern int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock } -extern uint8_t* NK_read_config(){ +NK_C_API uint8_t* NK_read_config(){ auto m = NitrokeyManager::instance(); return get_with_array_result( [&](){ auto v = m->read_config(); @@ -166,7 +167,7 @@ void clear_string(std::string &s){ std::fill(s.begin(), s.end(), ' '); } -extern const char * NK_status() { +NK_C_API const char * NK_status() { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ string && s = m->get_status_as_string(); @@ -176,7 +177,7 @@ extern const char * NK_status() { }); } -extern const char * NK_device_serial_number(){ +NK_C_API const char * NK_device_serial_number(){ auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ string && s = m->get_serial_number(); @@ -186,23 +187,23 @@ extern const char * NK_device_serial_number(){ }); } -extern uint32_t NK_get_hotp_code(uint8_t slot_number) { +NK_C_API uint32_t NK_get_hotp_code(uint8_t slot_number) { return NK_get_hotp_code_PIN(slot_number, ""); } -extern uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password){ +NK_C_API uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password){ auto m = NitrokeyManager::instance(); return get_with_result([&](){ return m->get_HOTP_code(slot_number, user_temporary_password); }); } -extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, +NK_C_API uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval){ return NK_get_totp_code_PIN(slot_number, challenge, last_totp_time, last_interval, ""); } -extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, +NK_C_API uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval, const char* user_temporary_password){ auto m = NitrokeyManager::instance(); return get_with_result([&](){ @@ -210,21 +211,21 @@ extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, ui }); } -extern int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password) { +NK_C_API int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password) { auto m = NitrokeyManager::instance(); return get_without_result([&]{ m->erase_hotp_slot(slot_number, temporary_password); }); } -extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password) { +NK_C_API int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password) { auto m = NitrokeyManager::instance(); return get_without_result([&]{ m->erase_totp_slot(slot_number, temporary_password); }); } -extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, +NK_C_API int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, const char *temporary_password) { auto m = NitrokeyManager::instance(); @@ -234,7 +235,7 @@ extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const }); } -extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, +NK_C_API int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, const char *temporary_password) { auto m = NitrokeyManager::instance(); @@ -244,14 +245,14 @@ extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const }); } -extern const char* NK_get_totp_slot_name(uint8_t slot_number){ +NK_C_API const char* NK_get_totp_slot_name(uint8_t slot_number){ auto m = NitrokeyManager::instance(); return get_with_string_result([&]() { const auto slot_name = m->get_totp_slot_name(slot_number); return slot_name; }); } -extern const char* NK_get_hotp_slot_name(uint8_t slot_number){ +NK_C_API const char* NK_get_hotp_slot_name(uint8_t slot_number){ auto m = NitrokeyManager::instance(); return get_with_string_result([&]() { const auto slot_name = m->get_hotp_slot_name(slot_number); @@ -259,46 +260,46 @@ extern const char* NK_get_hotp_slot_name(uint8_t slot_number){ }); } -extern void NK_set_debug(bool state){ +NK_C_API void NK_set_debug(bool state){ auto m = NitrokeyManager::instance(); m->set_debug(state); } -extern int NK_totp_set_time(uint64_t time){ +NK_C_API int NK_totp_set_time(uint64_t time){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->set_time(time); }); } -extern int NK_totp_get_time(){ +NK_C_API int NK_totp_get_time(){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->get_time(0); // FIXME check how that should work }); } -extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN){ +NK_C_API int NK_change_admin_PIN(char *current_PIN, char *new_PIN){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->change_admin_PIN(current_PIN, new_PIN); }); } -extern int NK_change_user_PIN(char *current_PIN, char *new_PIN){ +NK_C_API int NK_change_user_PIN(char *current_PIN, char *new_PIN){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->change_user_PIN(current_PIN, new_PIN); }); } -extern int NK_enable_password_safe(const char *user_pin){ +NK_C_API int NK_enable_password_safe(const char *user_pin){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->enable_password_safe(user_pin); }); } -extern uint8_t * NK_get_password_safe_slot_status(){ +NK_C_API uint8_t * NK_get_password_safe_slot_status(){ auto m = NitrokeyManager::instance(); return get_with_array_result( [&](){ auto slot_status = m->get_password_safe_slot_status(); @@ -307,47 +308,47 @@ extern uint8_t * NK_get_password_safe_slot_status(){ } -extern uint8_t NK_get_user_retry_count(){ +NK_C_API uint8_t NK_get_user_retry_count(){ auto m = NitrokeyManager::instance(); return get_with_result([&](){ return m->get_user_retry_count(); }); } -extern uint8_t NK_get_admin_retry_count(){ +NK_C_API uint8_t NK_get_admin_retry_count(){ auto m = NitrokeyManager::instance(); return get_with_result([&](){ return m->get_admin_retry_count(); }); } -extern int NK_lock_device(){ +NK_C_API int NK_lock_device(){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->lock_device(); }); } -extern const char *NK_get_password_safe_slot_name(uint8_t slot_number) { +NK_C_API const char *NK_get_password_safe_slot_name(uint8_t slot_number) { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ return m->get_password_safe_slot_name(slot_number); }); } -extern const char *NK_get_password_safe_slot_login(uint8_t slot_number) { +NK_C_API const char *NK_get_password_safe_slot_login(uint8_t slot_number) { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ return m->get_password_safe_slot_login(slot_number); }); } -extern const char *NK_get_password_safe_slot_password(uint8_t slot_number) { +NK_C_API const char *NK_get_password_safe_slot_password(uint8_t slot_number) { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ return m->get_password_safe_slot_password(slot_number); }); } -extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, +NK_C_API int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, const char *slot_password) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ @@ -355,21 +356,21 @@ extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_nam }); } -extern int NK_erase_password_safe_slot(uint8_t slot_number) { +NK_C_API int NK_erase_password_safe_slot(uint8_t slot_number) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->erase_password_safe_slot(slot_number); }); } -extern int NK_is_AES_supported(const char *user_password) { +NK_C_API int NK_is_AES_supported(const char *user_password) { auto m = NitrokeyManager::instance(); return get_with_result([&](){ return (uint8_t) m->is_AES_supported(user_password); }); } -extern int NK_login_auto() { +NK_C_API int NK_login_auto() { auto m = NitrokeyManager::instance(); return get_with_result([&](){ return (uint8_t) m->connect(); @@ -378,28 +379,42 @@ extern int NK_login_auto() { // storage commands -extern int NK_send_startup(uint64_t seconds_from_epoch){ +NK_C_API int NK_send_startup(uint64_t seconds_from_epoch){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->send_startup(seconds_from_epoch); }); } -extern int NK_unlock_encrypted_volume(const char* user_pin){ +NK_C_API int NK_unlock_encrypted_volume(const char* user_pin){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->unlock_encrypted_volume(user_pin); }); } -extern int NK_unlock_hidden_volume(const char* hidden_volume_password){ +NK_C_API int NK_lock_encrypted_volume(){ + auto m = NitrokeyManager::instance(); + return get_without_result([&](){ + m->lock_encrypted_volume(); + }); +} + +NK_C_API int NK_unlock_hidden_volume(const char* hidden_volume_password){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->unlock_hidden_volume(hidden_volume_password); }); } -extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, +NK_C_API int NK_lock_hidden_volume(){ + auto m = NitrokeyManager::instance(); + return get_without_result([&](){ + m->lock_hidden_volume(); + }); +} + +NK_C_API int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, const char *hidden_volume_password){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ @@ -408,42 +423,42 @@ extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8 }); } -extern int NK_set_unencrypted_read_only(const char* user_pin){ +NK_C_API int NK_set_unencrypted_read_only(const char* user_pin){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->set_unencrypted_read_only(user_pin); }); } -extern int NK_set_unencrypted_read_write(const char* user_pin){ +NK_C_API int NK_set_unencrypted_read_write(const char* user_pin){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->set_unencrypted_read_write(user_pin); }); } -extern int NK_export_firmware(const char* admin_pin) { +NK_C_API int NK_export_firmware(const char* admin_pin) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->export_firmware(admin_pin) ; }); } -extern int NK_clear_new_sd_card_warning(const char* admin_pin) { +NK_C_API int NK_clear_new_sd_card_warning(const char* admin_pin) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->clear_new_sd_card_warning(admin_pin); }); } -extern int NK_fill_SD_card_with_random_data(const char* admin_pin) { +NK_C_API int NK_fill_SD_card_with_random_data(const char* admin_pin) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->fill_SD_card_with_random_data(admin_pin); }); } -extern int NK_change_update_password(const char* current_update_password, +NK_C_API int NK_change_update_password(const char* current_update_password, const char* new_update_password) { auto m = NitrokeyManager::instance(); return get_without_result([&](){ @@ -451,28 +466,28 @@ extern int NK_change_update_password(const char* current_update_password, }); } -extern const char* NK_get_status_storage_as_string() { +NK_C_API const char* NK_get_status_storage_as_string() { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ return m->get_status_storage_as_string(); }); } -extern const char* NK_get_SD_usage_data_as_string() { +NK_C_API const char* NK_get_SD_usage_data_as_string() { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ return m->get_SD_usage_data_as_string(); }); } -extern int NK_get_progress_bar_value() { +NK_C_API int NK_get_progress_bar_value() { auto m = NitrokeyManager::instance(); return get_with_result([&](){ return m->get_progress_bar_value(); }); } -extern int NK_get_major_firmware_version(){ +NK_C_API int NK_get_major_firmware_version(){ auto m = NitrokeyManager::instance(); return get_with_result([&](){ return m->get_minor_firmware_version(); diff --git a/NK_C_API.h b/NK_C_API.h index 7f01900..dd31287 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -6,57 +6,59 @@ #include "include/NitrokeyManager.h" #include "include/inttypes.h" +#define NK_C_API + extern "C" { /** * Set debug level of messages written on stderr * @param state state=True - all messages, state=False - only errors level */ -extern void NK_set_debug(bool state); +NK_C_API void NK_set_debug(bool state); /** * Connect to device of given model. Currently library can be connected only to one device at once. * @param device_model char 'S': Nitrokey Storage, 'P': Nitrokey Pro * @return 1 if connected, 0 if wrong model or cannot connect */ -extern int NK_login(const char *device_model); +NK_C_API int NK_login(const char *device_model); /** * Connect to first available device, starting checking from Pro 1st to Storage 2nd. * @return 1 if connected, 0 if wrong model or cannot connect */ -extern int NK_login_auto(); +NK_C_API int NK_login_auto(); /** * Disconnect from the device. * @return command processing error code */ -extern int NK_logout(); +NK_C_API int NK_logout(); /** * Return the debug status string. Debug purposes. * @return command processing error code */ -extern const char * NK_status(); +NK_C_API const char * NK_status(); /** * Return the device's serial number string in hex. * @return string device's serial number in hex */ -extern const char * NK_device_serial_number(); +NK_C_API const char * NK_device_serial_number(); /** * Get last command processing status. Useful for commands which returns the results of their own and could not return * an error code. * @return previous command processing error code */ -extern uint8_t NK_get_last_command_status(); +NK_C_API uint8_t NK_get_last_command_status(); /** * Lock device - cancel any user device unlocking. * @return command processing error code */ -extern int NK_lock_device(); +NK_C_API int NK_lock_device(); /** * Authenticates the user on USER privilages with user_password and sets user's temporary password on device to user_temporary_password. @@ -64,7 +66,7 @@ extern int NK_lock_device(); * @param user_temporary_password char[25](Pro) user temporary password to be set on device for further communication (authentication command) * @return command processing error code */ -extern int NK_user_authenticate(const char* user_password, const char* user_temporary_password); +NK_C_API int NK_user_authenticate(const char* user_password, const char* user_temporary_password); /** * Authenticates the user on ADMIN privilages with admin_password and sets user's temporary password on device to admin_temporary_password. @@ -72,28 +74,28 @@ extern int NK_user_authenticate(const char* user_password, const char* user_temp * @param admin_temporary_password char[25](Pro) admin temporary password to be set on device for further communication (authentication command) * @return command processing error code */ -extern int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password); +NK_C_API int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password); /** * Execute a factory reset. * @param admin_password char[20](Pro) current administrator PIN * @return command processing error code */ -extern int NK_factory_reset(const char* admin_password); +NK_C_API int NK_factory_reset(const char* admin_password); /** * Generates AES key on the device * @param admin_password char[20](Pro) current administrator PIN * @return command processing error code */ -extern int NK_build_aes_key(const char* admin_password); +NK_C_API int NK_build_aes_key(const char* admin_password); /** * Unlock user PIN locked after 3 incorrect codes tries. * @param admin_password char[20](Pro) current administrator PIN * @return command processing error code */ -extern int NK_unlock_user_password(const char *admin_password, const char *new_user_password); +NK_C_API int NK_unlock_user_password(const char *admin_password, const char *new_user_password); /** * Write general config to the device @@ -106,7 +108,7 @@ extern int NK_unlock_user_password(const char *admin_password, const char *new_u * @param admin_temporary_password current admin temporary password * @return command processing error code */ -extern int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, +NK_C_API int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, bool delete_user_password, const char *admin_temporary_password); /** @@ -120,7 +122,7 @@ extern int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock uint8_t delete_user_password; */ -extern uint8_t* NK_read_config(); +NK_C_API uint8_t* NK_read_config(); //OTP @@ -129,14 +131,14 @@ extern uint8_t* NK_read_config(); * @param slot_number TOTP slot number, slot_number<15 * @return char[20](Pro) the name of the slot */ -extern const char * NK_get_totp_slot_name(uint8_t slot_number); +NK_C_API const char * NK_get_totp_slot_name(uint8_t slot_number); /** * * @param slot_number HOTP slot number, slot_number<3 * @return char[20](Pro) the name of the slot */ -extern const char * NK_get_hotp_slot_name(uint8_t slot_number); +NK_C_API const char * NK_get_hotp_slot_name(uint8_t slot_number); /** * Erase HOTP slot data from the device @@ -144,7 +146,7 @@ extern const char * NK_get_hotp_slot_name(uint8_t slot_number); * @param temporary_password admin temporary password * @return command processing error code */ -extern int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password); +NK_C_API int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password); /** * Erase TOTP slot data from the device @@ -152,7 +154,7 @@ extern int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_passwor * @param temporary_password admin temporary password * @return command processing error code */ -extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password); +NK_C_API int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password); /** * Write HOTP slot data to the device @@ -167,7 +169,7 @@ extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_passwor * @param temporary_password char[25](Pro) admin temporary password * @return command processing error code */ -extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, +NK_C_API int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, const char *temporary_password); @@ -184,7 +186,7 @@ extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const * @param temporary_password char[20](Pro) admin temporary password * @return command processing error code */ -extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, +NK_C_API int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, const char *temporary_password); @@ -193,7 +195,7 @@ extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const * @param slot_number HOTP slot number, slot_number<3 * @return HOTP code */ -extern uint32_t NK_get_hotp_code(uint8_t slot_number); +NK_C_API uint32_t NK_get_hotp_code(uint8_t slot_number); /** * Get HOTP code from the device (PIN protected) @@ -202,7 +204,7 @@ extern uint32_t NK_get_hotp_code(uint8_t slot_number); * otherwise should be set to empty string - '' * @return HOTP code */ -extern uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password); +NK_C_API uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password); /** * Get TOTP code from the device @@ -212,7 +214,7 @@ extern uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_tempo * @param last_interval last interval * @return TOTP code */ -extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval); +NK_C_API uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval); /** * Get TOTP code from the device (PIN protected) @@ -224,7 +226,7 @@ extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64 * otherwise should be set to empty string - '' * @return TOTP code */ -extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, +NK_C_API uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval, const char* user_temporary_password); /** @@ -232,9 +234,9 @@ extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, * @param time seconds in unix epoch (from 01.01.1970) * @return command processing error code */ -extern int NK_totp_set_time(uint64_t time); +NK_C_API int NK_totp_set_time(uint64_t time); -extern int NK_totp_get_time(); +NK_C_API int NK_totp_get_time(); //passwords /** * Change administrator PIN @@ -242,7 +244,7 @@ extern int NK_totp_get_time(); * @param new_PIN char[25](Pro) new PIN * @return command processing error code */ -extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN); +NK_C_API int NK_change_admin_PIN(char *current_PIN, char *new_PIN); /** * Change user PIN @@ -250,20 +252,20 @@ extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN); * @param new_PIN char[25](Pro) new PIN * @return command processing error code */ -extern int NK_change_user_PIN(char *current_PIN, char *new_PIN); +NK_C_API int NK_change_user_PIN(char *current_PIN, char *new_PIN); /** * Get retry count of user PIN * @return user PIN retry count */ -extern uint8_t NK_get_user_retry_count(); +NK_C_API uint8_t NK_get_user_retry_count(); /** * Get retry count of admin PIN * @return admin PIN retry count */ -extern uint8_t NK_get_admin_retry_count(); +NK_C_API uint8_t NK_get_admin_retry_count(); //password safe /** @@ -271,34 +273,34 @@ extern uint8_t NK_get_admin_retry_count(); * @param user_pin char[30](Pro) current user PIN * @return command processing error code */ -extern int NK_enable_password_safe(const char *user_pin); +NK_C_API int NK_enable_password_safe(const char *user_pin); /** * Get password safe slots' status * @return uint8_t[16] slot statuses - each byte represents one slot with 0 (not programmed) and 1 (programmed) */ -extern uint8_t * NK_get_password_safe_slot_status(); +NK_C_API uint8_t * NK_get_password_safe_slot_status(); /** * Get password safe slot name * @param slot_number password safe slot number, slot_number<16 * @return slot name */ -extern const char *NK_get_password_safe_slot_name(uint8_t slot_number); +NK_C_API const char *NK_get_password_safe_slot_name(uint8_t slot_number); /** * Get password safe slot login * @param slot_number password safe slot number, slot_number<16 * @return login from the PWS slot */ -extern const char *NK_get_password_safe_slot_login(uint8_t slot_number); +NK_C_API const char *NK_get_password_safe_slot_login(uint8_t slot_number); /** * Get the password safe slot password * @param slot_number password safe slot number, slot_number<16 * @return password from the PWS slot */ -extern const char *NK_get_password_safe_slot_password(uint8_t slot_number); +NK_C_API const char *NK_get_password_safe_slot_password(uint8_t slot_number); /** * Write password safe data to the slot @@ -308,7 +310,7 @@ extern const char *NK_get_password_safe_slot_password(uint8_t slot_number); * @param slot_password char[20](Pro) password string * @return command processing error code */ -extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, +NK_C_API int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, const char *slot_password); /** @@ -316,19 +318,19 @@ extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_nam * @param slot_number password safe slot number, slot_number<16 * @return command processing error code */ -extern int NK_erase_password_safe_slot(uint8_t slot_number); +NK_C_API int NK_erase_password_safe_slot(uint8_t slot_number); /** * Check whether AES is supported by the device * @return 0 for no and 1 for yes */ -extern int NK_is_AES_supported(const char *user_password); +NK_C_API int NK_is_AES_supported(const char *user_password); /** * Get device's major firmware version * @return 7,8 for Pro and major for Storage */ -extern int NK_get_major_firmware_version(); +NK_C_API int NK_get_major_firmware_version(); @@ -340,7 +342,7 @@ extern int NK_get_major_firmware_version(); * Storage only * @param seconds_from_epoch date and time expressed in seconds */ -extern int NK_send_startup(uint64_t seconds_from_epoch); +NK_C_API int NK_send_startup(uint64_t seconds_from_epoch); /** * Unlock encrypted volume. @@ -348,7 +350,13 @@ extern int NK_send_startup(uint64_t seconds_from_epoch); * @param user_pin user pin 20 characters * @return command processing error code */ -extern int NK_unlock_encrypted_volume(const char* user_pin); +NK_C_API int NK_unlock_encrypted_volume(const char* user_pin); + +/** + * Locks encrypted volume + * @return command processing error code + */ +NK_C_API int NK_lock_encrypted_volume(); /** * Unlock hidden volume and lock encrypted volume. @@ -357,7 +365,13 @@ extern int NK_unlock_encrypted_volume(const char* user_pin); * @param hidden_volume_password 20 characters * @return command processing error code */ -extern int NK_unlock_hidden_volume(const char* hidden_volume_password); +NK_C_API int NK_unlock_hidden_volume(const char* hidden_volume_password); + +/** + * Locks hidden volume + * @return command processing error code + */ +NK_C_API int NK_lock_hidden_volume(); /** * Create hidden volume. @@ -369,7 +383,7 @@ extern int NK_unlock_hidden_volume(const char* hidden_volume_password); * @param hidden_volume_password 20 characters * @return command processing error code */ -extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, +NK_C_API int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, const char *hidden_volume_password); /** @@ -380,7 +394,7 @@ extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8 * @param user_pin 20 characters * @return command processing error code */ -extern int NK_set_unencrypted_read_only(const char* user_pin); +NK_C_API int NK_set_unencrypted_read_only(const char* user_pin); /** * Make unencrypted volume read-write. @@ -390,7 +404,7 @@ extern int NK_set_unencrypted_read_only(const char* user_pin); * @param user_pin 20 characters * @return command processing error code */ -extern int NK_set_unencrypted_read_write(const char* user_pin); +NK_C_API int NK_set_unencrypted_read_write(const char* user_pin); /** * Exports device's firmware to unencrypted volume. @@ -398,7 +412,7 @@ extern int NK_set_unencrypted_read_write(const char* user_pin); * @param admin_pin 20 characters * @return command processing error code */ -extern int NK_export_firmware(const char* admin_pin) ; +NK_C_API int NK_export_firmware(const char* admin_pin) ; /** * Clear new SD card notification. It is set after factory reset. @@ -406,7 +420,7 @@ extern int NK_export_firmware(const char* admin_pin) ; * @param admin_pin 20 characters * @return command processing error code */ -extern int NK_clear_new_sd_card_warning(const char* admin_pin) ; +NK_C_API int NK_clear_new_sd_card_warning(const char* admin_pin) ; /** * Fill SD card with random data. @@ -415,7 +429,7 @@ extern int NK_clear_new_sd_card_warning(const char* admin_pin) ; * @param admin_pin 20 characters * @return command processing error code */ -extern int NK_fill_SD_card_with_random_data(const char* admin_pin) ; +NK_C_API int NK_fill_SD_card_with_random_data(const char* admin_pin) ; /** * Change update password. @@ -426,7 +440,7 @@ extern int NK_fill_SD_card_with_random_data(const char* admin_pin) ; * @param new_update_password 20 characters * @return command processing error code */ -extern int NK_change_update_password(const char* current_update_password, +NK_C_API int NK_change_update_password(const char* current_update_password, const char* new_update_password); /** @@ -434,7 +448,7 @@ extern int NK_change_update_password(const char* current_update_password, * Storage only * @return string with devices attributes */ -extern const char* NK_get_status_storage_as_string(); +NK_C_API const char* NK_get_status_storage_as_string(); /** * Get SD card usage attributes as string. @@ -442,14 +456,14 @@ extern const char* NK_get_status_storage_as_string(); * Storage only * @return string with SD card usage attributes */ -extern const char* NK_get_SD_usage_data_as_string(); +NK_C_API const char* NK_get_SD_usage_data_as_string(); /** * Get progress value of current long operation. * Storage only * @return int in range 0-100 or -1 if device is not busy */ -extern int NK_get_progress_bar_value(); +NK_C_API int NK_get_progress_bar_value(); } diff --git a/unittest/conftest.py b/unittest/conftest.py index 88bf7d0..f43f153 100644 --- a/unittest/conftest.py +++ b/unittest/conftest.py @@ -22,8 +22,8 @@ def C(request): a = iter(declarations) for declaration in a: - if declaration.startswith('extern') and not '"C"' in declaration: - declaration = declaration.replace('extern', '').strip() + if declaration.startswith('NK_C_API'): + declaration = declaration.replace('NK_C_API', '').strip() while not ';' in declaration: declaration += (next(a)).strip() print(declaration) -- cgit v1.2.3 From bbbb596a0e6e5b22a19d5543d20e7b2dfc1a0f83 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 18 Feb 2017 17:06:32 +0100 Subject: Add oath to Pythons unittest requirements Signed-off-by: Szczepan Zalega --- unittest/requirements.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'unittest') diff --git a/unittest/requirements.txt b/unittest/requirements.txt index 7224741..2cb9c05 100644 --- a/unittest/requirements.txt +++ b/unittest/requirements.txt @@ -2,3 +2,4 @@ cffi pytest-repeat pytest-randomly enum +oath \ No newline at end of file -- cgit v1.2.3 From 544d68631303fa35b5e6a538f8afb4e054ad9302 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 18 Feb 2017 17:08:07 +0100 Subject: Add some complex unit tests to find out corruption cause Signed-off-by: Szczepan Zalega --- unittest/test_pro.py | 70 +++++++++++++++++++++- unittest/test_storage.py | 147 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 214 insertions(+), 3 deletions(-) (limited to 'unittest') diff --git a/unittest/test_pro.py b/unittest/test_pro.py index 4a2a504..0ad42e1 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -22,6 +22,71 @@ def test_write_password_safe_slot(C): assert C.NK_write_password_safe_slot(0, 'slotname1', 'login1', 'pass1') == DeviceErrorCode.STATUS_OK +@pytest.mark.slowtest +def test_write_all_password_safe_slots_and_read_10_times(C): + def fill(s, wid): + assert wid >= len(s) + numbers = '1234567890'*4 + s += numbers[:wid-len(s)] + assert len(s) == wid + return s + + def get_pass(suffix): + return fill('pass' + suffix, 20) + + def get_loginname(suffix): + return fill('login' + suffix, 32) + + def get_slotname(suffix): + return fill('slotname' + suffix, 11) + + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + PWS_slot_count = 16 + for i in range(0, PWS_slot_count): + iss = str(i) + assert C.NK_write_password_safe_slot(i, + get_slotname(iss), get_loginname(iss), + get_pass(iss)) == DeviceErrorCode.STATUS_OK + + for j in range(0, 10): + for i in range(0, PWS_slot_count): + iss = str(i) + assert gs(C.NK_get_password_safe_slot_name(i)) == get_slotname(iss) + assert gs(C.NK_get_password_safe_slot_login(i)) == get_loginname(iss) + assert gs(C.NK_get_password_safe_slot_password(i)) == get_pass(iss) + + +@pytest.mark.slowtest +def test_read_all_password_safe_slots_10_times(C): + def fill(s, wid): + assert wid >= len(s) + numbers = '1234567890'*4 + s += numbers[:wid-len(s)] + assert len(s) == wid + return s + + def get_pass(suffix): + return fill('pass' + suffix, 20) + + def get_loginname(suffix): + return fill('login' + suffix, 32) + + def get_slotname(suffix): + return fill('slotname' + suffix, 11) + + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + PWS_slot_count = 16 + + for j in range(0, 10): + for i in range(0, PWS_slot_count): + iss = str(i) + assert gs(C.NK_get_password_safe_slot_name(i)) == get_slotname(iss) + assert gs(C.NK_get_password_safe_slot_login(i)) == get_loginname(iss) + assert gs(C.NK_get_password_safe_slot_password(i)) == get_pass(iss) + + def test_get_password_safe_slot_name(C): assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK assert C.NK_write_password_safe_slot(0, 'slotname1', 'login1', 'pass1') == DeviceErrorCode.STATUS_OK @@ -645,10 +710,11 @@ def test_TOTP_secrets(C, secret): @pytest.mark.parametrize("secret", [RFC_SECRET, 2*RFC_SECRET, '12'*10, '12'*30] ) def test_HOTP_secrets(C, secret): """ - NK Pro 0.8+, NK Storage 0.44+ + NK Pro 0.8+ feature needed: support for 320bit secrets """ - skip_if_device_version_lower_than({'S': 44, 'P': 8}) + if len(secret)>40: + skip_if_device_version_lower_than({'P': 8}) slot_number = 0 counter = 0 diff --git a/unittest/test_storage.py b/unittest/test_storage.py index a1c59aa..9c01382 100644 --- a/unittest/test_storage.py +++ b/unittest/test_storage.py @@ -57,6 +57,7 @@ def test_encrypted_volume_unlock_hidden(C): assert C.NK_create_hidden_volume(0, 20, 21, hidden_volume_password) == DeviceErrorCode.STATUS_OK assert C.NK_unlock_hidden_volume(hidden_volume_password) == DeviceErrorCode.STATUS_OK + @pytest.mark.skip(reason='hangs device, to report') def test_encrypted_volume_setup_multiple_hidden(C): skip_if_device_version_lower_than({'S': 43}) @@ -72,6 +73,149 @@ def test_encrypted_volume_setup_multiple_hidden(C): assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK +@pytest.mark.parametrize("volumes_to_setup", range(1, 5)) +def test_encrypted_volume_setup_multiple_hidden_no_lock_device_volumes(C, volumes_to_setup): + skip_if_device_version_lower_than({'S': 43}) + hidden_volume_password = 'hiddenpassword' + p = lambda i: hidden_volume_password + str(i) + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + for i in range(volumes_to_setup): + assert C.NK_create_hidden_volume(i, 20+i*10, 20+i*10+i+1, p(i)) == DeviceErrorCode.STATUS_OK + + assert C.NK_lock_encrypted_volume() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + + for i in range(volumes_to_setup): + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + # TODO mount and test for files + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + +@pytest.mark.parametrize("volumes_to_setup", range(1, 5)) +def test_encrypted_volume_setup_multiple_hidden_no_lock_device_volumes_unlock_at_once(C, volumes_to_setup): + skip_if_device_version_lower_than({'S': 43}) + hidden_volume_password = 'hiddenpassword' + p = lambda i: hidden_volume_password + str(i) + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + for i in range(volumes_to_setup): + assert C.NK_create_hidden_volume(i, 20+i*10, 20+i*10+i+1, p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + assert C.NK_lock_encrypted_volume() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + + for i in range(volumes_to_setup): + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + # TODO mount and test for files + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + +@pytest.mark.parametrize("use_slot", range(4)) +def test_encrypted_volume_setup_one_hidden_no_lock_device_slot(C, use_slot): + skip_if_device_version_lower_than({'S': 43}) + hidden_volume_password = 'hiddenpassword' + p = lambda i: hidden_volume_password + str(i) + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + i = use_slot + assert C.NK_create_hidden_volume(i, 20+i*10, 20+i*10+i+1, p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + assert C.NK_lock_encrypted_volume() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + + for j in range(3): + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + # TODO mount and test for files + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + +def test_password_safe_slot_name_corruption(C): + skip_if_device_version_lower_than({'S': 43}) + volumes_to_setup = 4 + # connected with encrypted volumes, possible also with hidden + def fill(s, wid): + assert wid >= len(s) + numbers = '1234567890' * 4 + s += numbers[:wid - len(s)] + assert len(s) == wid + return s + + def get_pass(suffix): + return fill('pass' + suffix, 20) + + def get_loginname(suffix): + return fill('login' + suffix, 32) + + def get_slotname(suffix): + return fill('slotname' + suffix, 11) + + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + PWS_slot_count = 16 + for i in range(0, PWS_slot_count): + iss = str(i) + assert C.NK_write_password_safe_slot(i, + get_slotname(iss), get_loginname(iss), + get_pass(iss)) == DeviceErrorCode.STATUS_OK + + def check_PWS_correctness(C): + for i in range(0, PWS_slot_count): + iss = str(i) + assert gs(C.NK_get_password_safe_slot_name(i)) == get_slotname(iss) + assert gs(C.NK_get_password_safe_slot_login(i)) == get_loginname(iss) + assert gs(C.NK_get_password_safe_slot_password(i)) == get_pass(iss) + + hidden_volume_password = 'hiddenpassword' + p = lambda i: hidden_volume_password + str(i) + def check_volumes_correctness(C): + for i in range(volumes_to_setup): + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + # TODO mount and test for files + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + check_PWS_correctness(C) + + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + for i in range(volumes_to_setup): + assert C.NK_create_hidden_volume(i, 20+i*10, 20+i*10+i+1, p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + + assert C.NK_lock_encrypted_volume() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + + check_volumes_correctness(C) + check_PWS_correctness(C) + check_volumes_correctness(C) + check_PWS_correctness(C) + + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + check_volumes_correctness(C) + check_PWS_correctness(C) + assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + check_volumes_correctness(C) + check_PWS_correctness(C) + +def test_hidden_volume_corruption(C): + # bug: this should return error without unlocking encrypted volume each hidden volume lock, but it does not + assert C.NK_lock_encrypted_volume() == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + hidden_volume_password = 'hiddenpassword' + p = lambda i: hidden_volume_password + str(i) + for i in range(4): + assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + assert C.NK_unlock_hidden_volume(p(i)) == DeviceErrorCode.STATUS_OK + wait(2) + assert C.NK_lock_hidden_volume() == DeviceErrorCode.STATUS_OK + def test_unencrypted_volume_set_read_only(C): skip_if_device_version_lower_than({'S': 43}) assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK @@ -94,7 +238,8 @@ def test_clear_new_sd_card_notification(C): assert C.NK_clear_new_sd_card_warning(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK -@pytest.mark.skip +@pytest.mark.slowtest +@pytest.mark.skip(reason='long test (about 1h)') def test_fill_SD_card(C): skip_if_device_version_lower_than({'S': 43}) status = C.NK_fill_SD_card_with_random_data(DefaultPasswords.ADMIN) -- cgit v1.2.3 From 097c9ecf42d2724a074ea9e0d317ed5f38b5ca37 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Mar 2017 13:47:52 +0100 Subject: Prefer to use log-enabled library in tests Signed-off-by: Szczepan Zalega --- unittest/conftest.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'unittest') diff --git a/unittest/conftest.py b/unittest/conftest.py index f43f153..67b45aa 100644 --- a/unittest/conftest.py +++ b/unittest/conftest.py @@ -29,7 +29,23 @@ def C(request): print(declaration) ffi.cdef(declaration, override=True) - C = ffi.dlopen("../build/libnitrokey.so") + C = None + import os, sys + path_build = os.path.join("..", "build") + paths = [ os.path.join(path_build,"libnitrokey-log.so"), + os.path.join(path_build,"libnitrokey.so")] + for p in paths: + print p + if os.path.exists(p): + C = ffi.dlopen(p) + break + else: + print("File does not exist: " + p) + print("Trying another") + if not C: + print("No library file found") + sys.exit(1) + C.NK_set_debug(False) nk_login = C.NK_login_auto() if nk_login != 1: -- cgit v1.2.3 From f7101225f26176f62ef3df48bd20d43521210987 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Mar 2017 13:49:13 +0100 Subject: Update encrypted volume test. Use random password. Randomizing password to ensure correctness of setting up hidden volume in current iteration Signed-off-by: Szczepan Zalega --- unittest/test_storage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'unittest') diff --git a/unittest/test_storage.py b/unittest/test_storage.py index 9c01382..da7c9a3 100644 --- a/unittest/test_storage.py +++ b/unittest/test_storage.py @@ -58,10 +58,10 @@ def test_encrypted_volume_unlock_hidden(C): assert C.NK_unlock_hidden_volume(hidden_volume_password) == DeviceErrorCode.STATUS_OK -@pytest.mark.skip(reason='hangs device, to report') -def test_encrypted_volume_setup_multiple_hidden(C): - skip_if_device_version_lower_than({'S': 43}) - hidden_volume_password = 'hiddenpassword' +def test_encrypted_volume_setup_multiple_hidden_lock(C): + import random + skip_if_device_version_lower_than({'S': 45}) #hangs device on lower version + hidden_volume_password = 'hiddenpassword' + str(random.randint(0,100)) p = lambda i: hidden_volume_password + str(i) assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK assert C.NK_unlock_encrypted_volume(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK -- cgit v1.2.3 From 9e659919a4b2da8855a1c7ec83edb685e6fec663 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Mar 2017 15:43:28 +0100 Subject: Authenticate before factory reset so the command will not timeout To investigate later Signed-off-by: Szczepan Zalega --- unittest/test_pro.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'unittest') diff --git a/unittest/test_pro.py b/unittest/test_pro.py index 0ad42e1..67fc585 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -147,6 +147,9 @@ def test_regenerate_aes_key(C): def test_enable_password_safe_after_factory_reset(C): assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK + if is_storage(C): + # for some reason storage likes to be authenticated before reset (to investigate) + assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK assert C.NK_factory_reset(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK wait(10) if is_storage(C): -- cgit v1.2.3 From 1b1a3211faa806d656b0ebb50864348c595857ed Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 6 Mar 2017 15:43:52 +0100 Subject: Correct comments and fix firmware version requirements Signed-off-by: Szczepan Zalega --- unittest/test_pro.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'unittest') diff --git a/unittest/test_pro.py b/unittest/test_pro.py index 67fc585..0140994 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -58,6 +58,7 @@ def test_write_all_password_safe_slots_and_read_10_times(C): @pytest.mark.slowtest +@pytest.mark.xfail(reason="This test should be run directly after test_write_all_password_safe_slots_and_read_10_times") def test_read_all_password_safe_slots_10_times(C): def fill(s, wid): assert wid >= len(s) @@ -591,7 +592,7 @@ def test_OTP_secret_started_from_null(C, secret): skip_if_device_version_lower_than({'S': 43, 'P': 8}) if len(secret) > 40: # feature: 320 bit long secret handling - skip_if_device_version_lower_than({'S': 44, 'P': 8}) + skip_if_device_version_lower_than({'P': 8}) oath = pytest.importorskip("oath") lib_at = lambda t: oath.hotp(secret, t, format='dec6') @@ -685,8 +686,9 @@ def test_TOTP_secrets(C, secret): ''' skip_if_device_version_lower_than({'S': 44, 'P': 8}) - if is_pro_rtm_07(C) and len(secret)>20*2: #*2 since secret is in hex - pytest.skip("Secret lengths over 20 bytes are not supported by NK Pro 0.7 ") + if len(secret)>20*2: #*2 since secret is in hex + # pytest.skip("Secret lengths over 20 bytes are not supported by NK Pro 0.7 and NK Storage") + skip_if_device_version_lower_than({'P': 8}) slot_number = 0 time = 0 period = 30 @@ -764,7 +766,7 @@ def test_edit_OTP_slot(C): """ should change slots counter and name without changing its secret (using null secret for second update) """ - # counter does not reset under Storage v0.43 + # counter is not getting updated under Storage v0.43 - #TOREPORT skip_if_device_version_lower_than({'S': 44, 'P': 7}) secret = RFC_SECRET -- cgit v1.2.3 From 9cfce3cf6b531b01296dbebc1cc7844c1e049478 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 11 Mar 2017 13:48:02 +0100 Subject: Fix compilation warnings Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 4 ++-- NK_C_API.h | 4 ++-- unittest/test_C_API.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'unittest') diff --git a/NK_C_API.cc b/NK_C_API.cc index 05102cc..262a0a4 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -279,14 +279,14 @@ NK_C_API int NK_totp_get_time(){ }); } -NK_C_API int NK_change_admin_PIN(char *current_PIN, char *new_PIN){ +NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->change_admin_PIN(current_PIN, new_PIN); }); } -NK_C_API int NK_change_user_PIN(char *current_PIN, char *new_PIN){ +NK_C_API int NK_change_user_PIN(const char *current_PIN, const char *new_PIN){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->change_user_PIN(current_PIN, new_PIN); diff --git a/NK_C_API.h b/NK_C_API.h index dd31287..f52034a 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -244,7 +244,7 @@ NK_C_API int NK_totp_get_time(); * @param new_PIN char[25](Pro) new PIN * @return command processing error code */ -NK_C_API int NK_change_admin_PIN(char *current_PIN, char *new_PIN); +NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN); /** * Change user PIN @@ -252,7 +252,7 @@ NK_C_API int NK_change_admin_PIN(char *current_PIN, char *new_PIN); * @param new_PIN char[25](Pro) new PIN * @return command processing error code */ -NK_C_API int NK_change_user_PIN(char *current_PIN, char *new_PIN); +NK_C_API int NK_change_user_PIN(const char *current_PIN, const char *new_PIN); /** diff --git a/unittest/test_C_API.cpp b/unittest/test_C_API.cpp index 37d3c7f..160145b 100644 --- a/unittest/test_C_API.cpp +++ b/unittest/test_C_API.cpp @@ -24,8 +24,8 @@ TEST_CASE("Check retry count", "[BASIC]") { } TEST_CASE("Check long strings", "[STANDARD]") { - char* longPin = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - char *pin = "123123123"; + const char* longPin = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const char* pin = "123123123"; auto result = NK_change_user_PIN(longPin, pin); REQUIRE(result == TOO_LONG_STRING); result = NK_change_user_PIN(pin, longPin); -- cgit v1.2.3