aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc25
-rw-r--r--NK_C_API.h2
-rw-r--r--NitrokeyManager.cc15
-rw-r--r--include/NitrokeyManager.h4
-rw-r--r--include/stick10_commands.h12
5 files changed, 57 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 440e824..5571f0d 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -173,4 +173,29 @@ extern int NK_totp_get_time(){
return 0;
}
+extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN){
+ auto m = NitrokeyManager::instance();
+ try {
+ m->change_admin_PIN(current_PIN, new_PIN);
+ }
+ catch (CommandFailedException & commandFailedException){
+ NK_last_command_status = commandFailedException.last_command_status;
+ return commandFailedException.last_command_status;
+ }
+ return 0;
+}
+
+extern int NK_change_user_PIN(char *current_PIN, char *new_PIN){
+ auto m = NitrokeyManager::instance();
+ try {
+ m->change_user_PIN(current_PIN, new_PIN);
+ }
+ catch (CommandFailedException & commandFailedException){
+ NK_last_command_status = commandFailedException.last_command_status;
+ return commandFailedException.last_command_status;
+ }
+ return 0;
+}
+
+
} \ No newline at end of file
diff --git a/NK_C_API.h b/NK_C_API.h
index 0c91095..a692a26 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -23,6 +23,8 @@ extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64
extern int NK_totp_set_time(uint64_t time);
extern int NK_totp_get_time();
extern uint8_t NK_get_last_command_status();
+extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN);
+extern int NK_change_user_PIN(char *current_PIN, char *new_PIN);
}
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 2a0033f..2b46927 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -176,7 +176,7 @@ namespace nitrokey{
bool NitrokeyManager::authorize(const char *pin, const char *temporary_password) {
auto authreq = get_payload<FirstAuthenticate>();
- assert(strlen(pin) < sizeof authreq.card_password); //160 bits
+ assert(strlen(pin) < sizeof authreq.card_password);
assert(strlen(temporary_password) < sizeof authreq.temporary_password);
strcpyT(authreq.card_password, pin);
@@ -200,5 +200,18 @@ namespace nitrokey{
return false;
}
+ void NitrokeyManager::change_user_PIN(char *current_PIN, char *new_PIN) {
+ auto p = get_payload<ChangeUserPin>();
+ strcpyT(p.old_pin, current_PIN);
+ strcpyT(p.new_pin, new_PIN);
+ ChangeUserPin::CommandTransaction::run(*device, p);
+ }
+ void NitrokeyManager::change_admin_PIN(char *current_PIN, char *new_PIN) {
+ auto p = get_payload<ChangeAdminPin>();
+ strcpyT(p.old_pin, current_PIN);
+ strcpyT(p.new_pin, new_PIN);
+ ChangeAdminPin::CommandTransaction::run(*device, p);
+ }
+
} \ No newline at end of file
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index d4e19e7..a3399fa 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -37,6 +37,9 @@ namespace nitrokey {
const char * get_totp_slot_name(uint8_t slot_number);
const char * get_hotp_slot_name(uint8_t slot_number);
+ void change_user_PIN(char *current_PIN, char *new_PIN);
+ void change_admin_PIN(char *current_PIN, char *new_PIN);
+
private:
NitrokeyManager();
~NitrokeyManager();
@@ -51,6 +54,7 @@ namespace nitrokey {
uint8_t get_internal_slot_number_for_totp(uint8_t slot_number) const;
bool erase_slot(uint8_t slot_number);
uint8_t *get_slot_name(uint8_t slot_number) const;
+
};
}
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index ca836db..d923d93 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -611,6 +611,12 @@ class ChangeUserPin : Command<CommandID::CHANGE_USER_PIN> {
struct CommandPayload {
uint8_t old_pin[25];
uint8_t new_pin[25];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " old_pin:\t" << old_pin<< std::endl;
+ ss << " new_pin:\t" << new_pin<< std::endl;
+ return ss.str();
+ }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
@@ -633,6 +639,12 @@ class ChangeAdminPin : Command<CommandID::CHANGE_ADMIN_PIN> {
struct CommandPayload {
uint8_t old_pin[25];
uint8_t new_pin[25];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " old_pin:\t" << old_pin<< std::endl;
+ ss << " new_pin:\t" << new_pin<< std::endl;
+ return ss.str();
+ }
} __packed;
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>