aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--NK_C_API.cc1
-rw-r--r--NitrokeyManager.cc68
-rw-r--r--NitrokeyManagerPWS.cc80
-rw-r--r--NitrokeyManagerPWS.h6
-rw-r--r--NitrokeyManagerStorage.cpp1
6 files changed, 92 insertions, 68 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6e0bcb1..c795e22 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,6 +77,8 @@ set(SOURCE_FILES
NitrokeyManagerStorage.h
NitrokeyManagerOTP.cc
NitrokeyManagerOTP.h
+ NitrokeyManagerPWS.h
+ NitrokeyManagerPWS.cc
NK_C_API.h
NK_C_API.cc
NK_C_API_helpers.h
@@ -86,6 +88,7 @@ set(SOURCE_FILES
set(SOURCE_FILES_storage
${COMMON_FILES}
+ NitrokeyManager.cc
NitrokeyManagerStorage.cpp
NitrokeyManagerStorage.h
NK_C_API_helpers.h
@@ -140,6 +143,7 @@ endif()
OPTION(NO_LOG "Compile without logging functionality and its strings (decreases size)" OFF)
IF (NO_LOG)
SET_TARGET_PROPERTIES(nitrokey PROPERTIES COMPILE_DEFINITIONS "NO_LOG")
+ SET_TARGET_PROPERTIES(nitrokey-storage PROPERTIES COMPILE_DEFINITIONS "NO_LOG")
ENDIF()
OPTION(LOG_VOLATILE_DATA "Log volatile data (debug)" OFF)
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 9dd0837..434fb37 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -40,6 +40,7 @@ uint8_t NK_last_command_status = 0;
#include "NK_C_API_helpers.h"
#include "NitrokeyManagerOTP.h"
+#include "NitrokeyManagerPWS.h"
#ifdef __cplusplus
extern "C" {
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index cde559b..fa12a5e 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -21,6 +21,7 @@
#include "libnitrokey/NitrokeyManager.h"
#include "NitrokeyManagerOTP.h"
+#include "NitrokeyManagerPWS.h"
#include "libnitrokey/LibraryException.h"
#include "libnitrokey/cxx_semantics.h"
#include "libnitrokey/misc.h"
@@ -465,25 +466,6 @@ using nitrokey::misc::strcpyT;
}
- void NitrokeyManager::enable_password_safe(const char *user_pin) {
- //The following command will cancel enabling PWS if it is not supported
- auto a = get_payload<IsAESSupported>();
- strcpyT(a.user_password, user_pin);
- IsAESSupported::CommandTransaction::run(device, a);
-
- auto p = get_payload<EnablePasswordSafe>();
- strcpyT(p.user_password, user_pin);
- EnablePasswordSafe::CommandTransaction::run(device, p);
- }
-
- vector <uint8_t> NitrokeyManager::get_password_safe_slot_status() {
- auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(device);
- vector<uint8_t> v = vector<uint8_t>(responsePayload.data().password_safe_status,
- responsePayload.data().password_safe_status
- + sizeof(responsePayload.data().password_safe_status));
- return v;
- }
-
uint8_t NitrokeyManager::get_user_retry_count() {
if(device->get_device_model() == DeviceModel::STORAGE){
stick20::GetDeviceStatus::CommandTransaction::run(device);
@@ -504,54 +486,6 @@ using nitrokey::misc::strcpyT;
LockDevice::CommandTransaction::run(device);
}
- char * NitrokeyManager::get_password_safe_slot_name(uint8_t slot_number) {
- if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
- auto p = get_payload<GetPasswordSafeSlotName>();
- p.slot_number = slot_number;
- auto response = GetPasswordSafeSlotName::CommandTransaction::run(device, p);
- return strndup((const char *) response.data().slot_name, max_string_field_length);
- }
-
- bool NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16; }
-
- char * NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number) {
- if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
- auto p = get_payload<GetPasswordSafeSlotLogin>();
- p.slot_number = slot_number;
- auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(device, p);
- return strndup((const char *) response.data().slot_login, max_string_field_length);
- }
-
- char * NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) {
- if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
- auto p = get_payload<GetPasswordSafeSlotPassword>();
- p.slot_number = slot_number;
- auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(device, p);
- return strndup((const char *) response.data().slot_password, max_string_field_length); //FIXME use secure way
- }
-
- void NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
- const char *slot_password) {
- if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
- auto p = get_payload<SetPasswordSafeSlotData>();
- p.slot_number = slot_number;
- strcpyT(p.slot_name, slot_name);
- strcpyT(p.slot_password, slot_password);
- SetPasswordSafeSlotData::CommandTransaction::run(device, p);
-
- auto p2 = get_payload<SetPasswordSafeSlotData2>();
- p2.slot_number = slot_number;
- strcpyT(p2.slot_login_name, slot_login);
- SetPasswordSafeSlotData2::CommandTransaction::run(device, p2);
- }
-
- void NitrokeyManager::erase_password_safe_slot(uint8_t slot_number) {
- if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
- auto p = get_payload<ErasePasswordSafeSlot>();
- p.slot_number = slot_number;
- ErasePasswordSafeSlot::CommandTransaction::run(device, p);
- }
-
void NitrokeyManager::user_authenticate(const char *user_password, const char *temporary_password) {
auto p = get_payload<UserAuthenticate>();
strcpyT(p.card_password, user_password);
diff --git a/NitrokeyManagerPWS.cc b/NitrokeyManagerPWS.cc
new file mode 100644
index 0000000..5ccfd25
--- /dev/null
+++ b/NitrokeyManagerPWS.cc
@@ -0,0 +1,80 @@
+//
+// Created by sz on 7/28/20.
+//
+
+#include "NitrokeyManagerPWS.h"
+#include "NitrokeyManagerOTP.h"
+#include "libnitrokey/LibraryException.h"
+#include "libnitrokey/NitrokeyManager.h"
+#include "libnitrokey/cxx_semantics.h"
+#include "libnitrokey/misc.h"
+#include <algorithm>
+#include <cstring>
+#include <functional>
+#include <iostream>
+#include <mutex>
+#include <stick10_commands.h>
+#include <stick20_commands.h>
+#include <unordered_map>
+void nitrokey::NitrokeyManager::enable_password_safe(const char *user_pin) {
+ //The following command will cancel enabling PWS if it is not supported
+ auto a = get_payload<IsAESSupported>();
+ misc::strcpyT(a.user_password, user_pin);
+ IsAESSupported::CommandTransaction::run(device, a);
+
+ auto p = get_payload<EnablePasswordSafe>();
+ misc::strcpyT(p.user_password, user_pin);
+ EnablePasswordSafe::CommandTransaction::run(device, p);
+}
+std::vector <uint8_t> nitrokey::NitrokeyManager::get_password_safe_slot_status() {
+ auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(device);
+ vector<uint8_t> v = vector<uint8_t>(responsePayload.data().password_safe_status,
+ responsePayload.data().password_safe_status
+ + sizeof(responsePayload.data().password_safe_status));
+ return v;
+}
+char * nitrokey::NitrokeyManager::get_password_safe_slot_name(uint8_t slot_number) {
+ if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
+ auto p = get_payload<GetPasswordSafeSlotName>();
+ p.slot_number = slot_number;
+ auto response = GetPasswordSafeSlotName::CommandTransaction::run(device, p);
+ return strndup((const char *) response.data().slot_name, max_string_field_length);
+}
+bool nitrokey::NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16;
+}
+char *
+nitrokey::NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number) {
+ if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
+ auto p = get_payload<GetPasswordSafeSlotLogin>();
+ p.slot_number = slot_number;
+ auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(device, p);
+ return strndup((const char *) response.data().slot_login, max_string_field_length);
+}
+char * nitrokey::NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) {
+ if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
+ auto p = get_payload<GetPasswordSafeSlotPassword>();
+ p.slot_number = slot_number;
+ auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(device, p);
+ return strndup((const char *) response.data().slot_password, max_string_field_length); //FIXME use secure way
+}
+void nitrokey::NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
+ const char *slot_password) {
+ if (!is_valid_password_safe_slot_number(slot_number))
+ throw InvalidSlotException(slot_number);
+ auto p = get_payload<SetPasswordSafeSlotData>();
+ p.slot_number = slot_number;
+ misc::strcpyT(p.slot_name, slot_name);
+ misc::strcpyT(p.slot_password, slot_password);
+ SetPasswordSafeSlotData::CommandTransaction::run(device, p);
+
+ auto p2 = get_payload<SetPasswordSafeSlotData2>();
+ p2.slot_number = slot_number;
+ misc::strcpyT(p2.slot_login_name, slot_login);
+ SetPasswordSafeSlotData2::CommandTransaction::run(device, p2);
+}
+void nitrokey::NitrokeyManager::erase_password_safe_slot(uint8_t slot_number) {
+ if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number);
+ auto p = get_payload<ErasePasswordSafeSlot>();
+ p.slot_number = slot_number;
+ ErasePasswordSafeSlot::CommandTransaction::run(device, p);
+} \ No newline at end of file
diff --git a/NitrokeyManagerPWS.h b/NitrokeyManagerPWS.h
new file mode 100644
index 0000000..b9f5071
--- /dev/null
+++ b/NitrokeyManagerPWS.h
@@ -0,0 +1,6 @@
+#ifndef LIBNITROKEY_NITROKEYMANAGERPWS_H
+#define LIBNITROKEY_NITROKEYMANAGERPWS_H
+
+#include "NitrokeyManager.h"
+
+#endif // LIBNITROKEY_NITROKEYMANAGERPWS_H
diff --git a/NitrokeyManagerStorage.cpp b/NitrokeyManagerStorage.cpp
index 6814e8b..c78730b 100644
--- a/NitrokeyManagerStorage.cpp
+++ b/NitrokeyManagerStorage.cpp
@@ -1,6 +1,5 @@
#include "NitrokeyManagerStorage.h"
-//using namespace nitrokey;
namespace nitrokey{
using nitrokey::misc::strcpyT;