From 24ad4504648cd3918bb181b1d54a7c3441c02ae0 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 29 Jul 2016 14:28:58 +0200 Subject: Handle changing admin/user password on NK Storage - NitrokeyManager Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 31 +++++++++++++++++++++++++++---- include/NitrokeyManager.h | 2 ++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 79cd868..7f7a870 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -239,10 +239,33 @@ namespace nitrokey{ ChangeUserPin::CommandTransaction::run(*device, p); } void NitrokeyManager::change_admin_PIN(char *current_PIN, char *new_PIN) { - auto p = get_payload(); - strcpyT(p.old_pin, current_PIN); - strcpyT(p.new_pin, new_PIN); - ChangeAdminPin::CommandTransaction::run(*device, p); + switch (device->get_device_model()){ + case DeviceModel::PRO: + { + auto p = get_payload(); + strcpyT(p.old_pin, current_PIN); + strcpyT(p.new_pin, new_PIN); + ChangeAdminPin::CommandTransaction::run(*device, p); + } + break; + //in Storage change admin pin is divided to two commands with 20 chars field len + case DeviceModel::STORAGE: + { + auto p = get_payload(); + strcpyT(p.old_pin, current_PIN); + p.kind = 'A'; + p.set_kind(PasswordKind::Admin); + ChangeAdminPin20Current::CommandTransaction::run(*device, p); + + auto p2 = get_payload(); + strcpyT(p2.new_pin, new_PIN); + p2.kind = 'A'; + p2.set_kind(PasswordKind::Admin); + ChangeAdminPin20New::CommandTransaction::run(*device, p2); + } + break; + } + } void NitrokeyManager::enable_password_safe(const char *user_pin) { diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 3acb229..fdb485f 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -5,12 +5,14 @@ #include "log.h" #include "device_proto.h" #include "stick10_commands.h" +#include "stick20_commands.h" #include namespace nitrokey { using namespace nitrokey::device; using namespace std; using namespace nitrokey::proto::stick10; + using namespace nitrokey::proto::stick20; using namespace nitrokey::proto; using namespace nitrokey::log; -- cgit v1.2.3