aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc21
-rw-r--r--NK_C_API.h3
-rw-r--r--NitrokeyManager.cc18
-rw-r--r--include/NitrokeyManager.h6
-rw-r--r--include/stick10_commands.h21
5 files changed, 66 insertions, 3 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index db96c52..6565b7c 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -86,6 +86,27 @@ extern int NK_user_authenticate(const char* user_password, const char* user_temp
});
}
+extern int NK_factory_reset(const char* admin_password){
+ auto m = NitrokeyManager::instance();
+ return get_without_result( [&](){
+ return m->factory_reset(admin_password);
+ });
+}
+extern int NK_build_aes_key(const char* admin_password){
+ auto m = NitrokeyManager::instance();
+ return get_without_result( [&](){
+ return m->build_aes_key(admin_password);
+ });
+}
+
+extern int NK_unlock_user_password(const char* admin_password){
+ auto m = NitrokeyManager::instance();
+ return get_without_result( [&](){
+ return m->unlock_user_password(admin_password);
+ });
+}
+
+
extern const char * NK_status() {
auto m = NitrokeyManager::instance();
try {
diff --git a/NK_C_API.h b/NK_C_API.h
index 26f99f9..9dc1bce 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -17,6 +17,9 @@ extern uint8_t NK_get_last_command_status();
extern int NK_lock_device();
extern int NK_user_authenticate(const char* user_password, const char* user_temporary_password);
extern int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password);
+extern int NK_factory_reset(const char* admin_password);
+extern int NK_build_aes_key(const char* admin_password);
+extern int NK_unlock_user_password(const char* admin_password);
//otp
extern const char * NK_get_totp_slot_name(uint8_t slot_number);
extern const char * NK_get_hotp_slot_name(uint8_t slot_number);
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 69b2059..2d63c21 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -307,4 +307,22 @@ namespace nitrokey{
UserAuthenticate::CommandTransaction::run(*device, p);
}
+ void NitrokeyManager::build_aes_key(const char *admin_password) {
+ auto p = get_payload<BuildAESKey>();
+ strcpyT(p.admin_password, admin_password);
+ BuildAESKey::CommandTransaction::run(*device, p);
+ }
+
+ void NitrokeyManager::factory_reset(const char *admin_password) {
+ auto p = get_payload<FactoryReset>();
+ strcpyT(p.admin_password, admin_password);
+ FactoryReset::CommandTransaction::run(*device, p);
+ }
+
+ void NitrokeyManager::unlock_user_password(const char *admin_password) {
+ auto p = get_payload<UnlockUserPassword>();
+ strcpyT(p.admin_password, admin_password);
+ UnlockUserPassword::CommandTransaction::run(*device, p);
+ }
+
} \ No newline at end of file
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index e6e79c7..5bd253d 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -61,6 +61,12 @@ namespace nitrokey {
void user_authenticate(const char *user_password, const char *temporary_password);
+ void factory_reset(const char *admin_password);
+
+ void build_aes_key(const char *admin_password);
+
+ void unlock_user_password(const char *admin_password);
+
private:
NitrokeyManager();
~NitrokeyManager();
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index fbd0698..8dc1b22 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -637,7 +637,12 @@ class UserAuthorize : Command<CommandID::USER_AUTHORIZE> {
class UnlockUserPassword : Command<CommandID::UNLOCK_USER_PASSWORD> {
public:
struct CommandPayload {
- uint8_t admin_password[20]; // TODO
+ uint8_t admin_password[20];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " admin_password:\t" << admin_password<< std::endl;
+ return ss.str();
+ }
} __packed;
// TODO could we get the stick to return the retry count?
@@ -700,7 +705,12 @@ class LockDevice : Command<CommandID::LOCK_DEVICE> {
class FactoryReset : Command<CommandID::FACTORY_RESET> {
public:
struct CommandPayload {
- uint8_t password[20];
+ uint8_t admin_password[20];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " admin_password:\t" << admin_password<< std::endl;
+ return ss.str();
+ }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
@@ -710,7 +720,12 @@ class FactoryReset : Command<CommandID::FACTORY_RESET> {
class BuildAESKey : Command<CommandID::NEW_AES_KEY> {
public:
struct CommandPayload {
- uint8_t password[20];
+ uint8_t admin_password[20];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " admin_password:\t" << admin_password<< std::endl;
+ return ss.str();
+ }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>