summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-28 12:24:45 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit08fa8c559b42fb07bdadd62369802c348b896607 (patch)
tree7a94fe1810d7468ccc5b4d82ecbc549dd0b6c933
parentbdb25a0c1feb5709d718f408d6c839dbc9b55738 (diff)
downloadlibnitrokey-08fa8c559b42fb07bdadd62369802c348b896607.tar.gz
libnitrokey-08fa8c559b42fb07bdadd62369802c348b896607.tar.bz2
Choose device model during connection
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NK_C_API.cc4
-rw-r--r--NK_C_API.h2
-rw-r--r--NitrokeyManager.cc13
-rw-r--r--include/NitrokeyManager.h2
-rw-r--r--unittest/test_bindings.py2
5 files changed, 16 insertions, 7 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index fac8a3c..e6151fc 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -68,10 +68,10 @@ extern uint8_t NK_get_last_command_status(){
return _copy;
}
-extern int NK_login(const char *admin_pin, const char *temporary_password) {
+extern int NK_login(const char *admin_pin, const char *temporary_password, const char *device_model) {
auto m = NitrokeyManager::instance();
try {
- m->connect();
+ m->connect(device_model);
m->first_authenticate(admin_pin, temporary_password);
NK_last_command_status = 0;
}
diff --git a/NK_C_API.h b/NK_C_API.h
index 458dd31..5520099 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -10,7 +10,7 @@ extern "C"
{
//Make sure each function's declaration is in one line (for automatic python declaration processing)
extern void NK_set_debug(bool state);
-extern int NK_login(const char *admin_pin, const char *temporary_password);
+extern int NK_login(const char *admin_pin, const char *temporary_password, const char *device_model);
extern int NK_logout();
extern const char * NK_status();
extern uint8_t NK_get_last_command_status();
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index caf9724..3697369 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -36,8 +36,17 @@ namespace nitrokey{
}
NitrokeyManager::~NitrokeyManager() {delete _instance; delete device;}
- bool NitrokeyManager::connect() {
- device = new Stick10();
+ bool NitrokeyManager::connect(const char *device_model) {
+ switch (device_model[0]){
+ case 'P':
+ device = new Stick10();
+ break;
+ case 'S':
+ device = new Stick20();
+ break;
+ default:
+ throw std::runtime_error("Unknown model");
+ }
return device->connect();
}
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index 3a86597..3acb229 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -30,7 +30,7 @@ namespace nitrokey {
bool get_time();
bool erase_totp_slot(uint8_t slot_number, const char *temporary_password);
bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password);
- bool connect();
+ bool connect(const char *device_model);
bool disconnect();
void set_debug(bool state);
string get_status();
diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py
index cba5ba4..8d6169c 100644
--- a/unittest/test_bindings.py
+++ b/unittest/test_bindings.py
@@ -39,7 +39,7 @@ def C(request):
C = ffi.dlopen("../build/libnitrokey.so")
C.NK_set_debug(False)
- C.NK_login(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP)
+ C.NK_login(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP, 'P')
assert C.NK_user_authenticate(DefaultPasswords.USER, DefaultPasswords.USER_TEMP) == DeviceErrorCode.STATUS_OK
# C.NK_status()