summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-08-04 12:06:04 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-05 10:17:30 +0200
commit7b3174e6c5271a2e7160625ce70aa28f120fb662 (patch)
tree0308f03a48504350bdac25e4c396bb67dd2e3e05
parentfd95d2ec8b0160657709f1655887739191f33932 (diff)
downloadlibnitrokey-7b3174e6c5271a2e7160625ce70aa28f120fb662.tar.gz
libnitrokey-7b3174e6c5271a2e7160625ce70aa28f120fb662.tar.bz2
Handle OTP slot config in C API during writing
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NK_C_API.cc10
-rw-r--r--NK_C_API.h15
-rw-r--r--NitrokeyManager.cc13
-rw-r--r--include/NitrokeyManager.h10
4 files changed, 32 insertions, 16 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 0e3a642..a9ed22b 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -224,10 +224,11 @@ extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_passwor
}
extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
- bool use_8_digits, const char *temporary_password) {
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *temporary_password) {
auto m = NitrokeyManager::instance();
try {
- m->write_HOTP_slot(slot_number, slot_name, secret, hotp_counter, use_8_digits, temporary_password);
+ m->write_HOTP_slot(slot_number, slot_name, secret, hotp_counter, use_8_digits, use_enter, use_tokenID,
+ temporary_password);
NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
@@ -238,10 +239,11 @@ extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const
}
extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window,
- bool use_8_digits, const char *temporary_password) {
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *temporary_password) {
auto m = NitrokeyManager::instance();
try {
- m->write_TOTP_slot(slot_number, slot_name, secret, time_window, use_8_digits, temporary_password);
+ m->write_TOTP_slot(slot_number, slot_name, secret, time_window, use_8_digits, use_enter, use_tokenID,
+ temporary_password);
NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
diff --git a/NK_C_API.h b/NK_C_API.h
index af226ac..a25c528 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -95,7 +95,8 @@ extern int NK_unlock_user_password(const char* admin_password);
* @param admin_temporary_password current admin temporary password
* @return command processing error code
*/
-extern int NK_write_config(bool numlock, bool capslock, bool scrolllock, bool enable_user_password, bool delete_user_password, const char *admin_temporary_password);
+extern int NK_write_config(bool numlock, bool capslock, bool scrolllock,
+ bool enable_user_password, bool delete_user_password, const char *admin_temporary_password);
/**
* Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and PIN protected OTP
@@ -151,7 +152,8 @@ extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_passwor
* @param temporary_password char[25](Pro) admin temporary password
* @return command processing error code
*/
-extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter, bool use_8_digits, const char *temporary_password);
+extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *temporary_password);
/**
* Write TOTP slot data to the device
@@ -163,7 +165,8 @@ extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const
* @param temporary_password char[20](Pro) admin temporary password
* @return command processing error code
*/
-extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, bool use_8_digits, const char *temporary_password);
+extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window,
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *temporary_password);
/**
* Get HOTP code from the device
@@ -201,7 +204,8 @@ extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64
* otherwise should be set to empty string - ''
* @return TOTP code
*/
-extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval, const char* user_temporary_password);
+extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge,
+ uint64_t last_totp_time, uint8_t last_interval, const char* user_temporary_password);
/**
* Set time on the device (for TOTP requests)
@@ -284,7 +288,8 @@ extern const char *NK_get_password_safe_slot_password(uint8_t slot_number);
* @param slot_password char[20](Pro) password string
* @return command processing error code
*/
-extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, const char *slot_password);
+extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name,
+ const char *slot_login, const char *slot_password);
/**
* Erase the password safe slot from the device
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index ef7358f..488c5fe 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -138,8 +138,9 @@ namespace nitrokey{
}
- bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter,
- bool use_8_digits, const char *temporary_password) {
+ bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret,
+ uint8_t hotp_counter, bool use_8_digits,
+ bool use_enter, bool use_tokenID, const char *temporary_password) {
assert(is_valid_hotp_slot_number(slot_number));
assert(strlen(secret)==20); //160 bits
assert(strlen(slot_name)<=15);
@@ -151,6 +152,8 @@ namespace nitrokey{
strcpyT(payload.slot_name, slot_name);
payload.slot_counter = hotp_counter;
payload.use_8_digits = use_8_digits;
+ payload.use_enter = use_enter;
+ payload.use_tokenID = use_tokenID;
auto auth = get_payload<Authorize>();
strcpyT(auth.temporary_password, temporary_password);
@@ -162,7 +165,8 @@ namespace nitrokey{
}
bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret,
- uint16_t time_window, bool use_8_digits, const char *temporary_password) {
+ uint16_t time_window, bool use_8_digits,
+ bool use_enter, bool use_tokenID, const char *temporary_password) {
auto payload = get_payload<WriteToTOTPSlot>();
assert(is_valid_totp_slot_number(slot_number));
assert(strlen(secret) == sizeof payload.slot_secret); //160 bits
@@ -174,6 +178,9 @@ namespace nitrokey{
strcpyT(payload.slot_name, slot_name);
payload.slot_interval = time_window; //FIXME naming
payload.use_8_digits = use_8_digits;
+ payload.use_enter = use_enter;
+ payload.use_tokenID = use_tokenID;
+ payload.slot_token_id
auto auth = get_payload<Authorize>();
strcpyT(auth.temporary_password, temporary_password);
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index e9b3be2..0a27bd8 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -21,10 +21,12 @@ namespace nitrokey {
static NitrokeyManager *instance();
bool first_authenticate(const char *pin, const char *temporary_password);
- bool write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter,
- bool use_8_digits, const char *temporary_password);
- bool write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret,
- uint16_t time_window, bool use_8_digits, const char *temporary_password);
+ bool write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
+ bool use_8_digits,
+ bool use_enter, bool use_tokenID, const char *temporary_password);
+ bool write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window,
+ bool use_8_digits,
+ bool use_enter, bool use_tokenID, const char *temporary_password);
uint32_t get_HOTP_code(uint8_t slot_number, const char *user_temporary_password);
uint32_t get_TOTP_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval,
const char *user_temporary_password);