aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc8
-rw-r--r--NK_C_API.h13
-rw-r--r--NitrokeyManager.cc6
-rw-r--r--libnitrokey/NitrokeyManager.h12
4 files changed, 36 insertions, 3 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 00694c7..01963fc 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -358,11 +358,15 @@ extern "C" {
});
}
- NK_C_API int NK_totp_get_time() {
+ NK_C_API int NK_totp_set_time_soft(uint64_t time) {
auto m = NitrokeyManager::instance();
return get_without_result([&]() {
- m->get_time(0); // FIXME check how that should work
+ m->set_time_soft(time);
});
+ }
+
+ NK_C_API int NK_totp_get_time() {
+ return 0;
}
NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN) {
diff --git a/NK_C_API.h b/NK_C_API.h
index 5bcc484..f23bb5d 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -386,6 +386,19 @@ extern "C" {
*/
NK_C_API int NK_totp_set_time(uint64_t time);
+ /**
+ * Set the device time used for TOTP to the given time. Contrary to
+ * {@code set_time(uint64_t)}, this command fails if {@code old_time}
+ * > {@code time} or if {@code old_time} is zero (where {@code
+ * old_time} is the current time on the device).
+ *
+ * @param time new device time as Unix timestamp (seconds since
+ * 1970-01-01)
+ * @return command processing error code
+ */
+ NK_C_API int NK_totp_set_time_soft(uint64_t time);
+
+ [[deprecated("NK_totp_get_time is deprecated -- use NK_totp_set_time_soft instead")]]
NK_C_API int NK_totp_get_time();
//passwords
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 085bf78..addfdbf 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -666,11 +666,15 @@ using nitrokey::misc::strcpyT;
return false;
}
- bool NitrokeyManager::get_time(uint64_t time) {
+ void NitrokeyManager::set_time_soft(uint64_t time) {
auto p = get_payload<SetTime>();
p.reset = 0;
p.time = time;
SetTime::CommandTransaction::run(device, p);
+ }
+
+ bool NitrokeyManager::get_time(uint64_t time) {
+ set_time_soft(time);
return true;
}
diff --git a/libnitrokey/NitrokeyManager.h b/libnitrokey/NitrokeyManager.h
index d4630b0..0689c3f 100644
--- a/libnitrokey/NitrokeyManager.h
+++ b/libnitrokey/NitrokeyManager.h
@@ -65,6 +65,18 @@ char * strndup(const char* str, size_t maxlen);
stick10::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number);
bool set_time(uint64_t time);
+ /**
+ * Set the device time used for TOTP to the given time. Contrary to
+ * {@code set_time(uint64_t)}, this command fails if {@code old_time}
+ * &gt; {@code time} or if {@code old_time} is zero (where {@code
+ * old_time} is the current time on the device).
+ *
+ * @param time new device time as Unix timestamp (seconds since
+ * 1970-01-01)
+ */
+ void set_time_soft(uint64_t time);
+
+ [[deprecated("get_time is deprecated -- use set_time_soft instead")]]
bool get_time(uint64_t time = 0);
bool erase_totp_slot(uint8_t slot_number, const char *temporary_password);
bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password);