aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-20 12:26:53 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:56 +0200
commit8d21114df0ee75e2129916acb38b212704ed78cf (patch)
tree625eced9f399e5028cd51958e5ff38b90aa9be67 /NitrokeyManager.cc
parent02a46831a552d443adfbd3c61542cf6925675349 (diff)
downloadlibnitrokey-8d21114df0ee75e2129916acb38b212704ed78cf.tar.gz
libnitrokey-8d21114df0ee75e2129916acb38b212704ed78cf.tar.bz2
Working TOTP handling (passing RFC tests)
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index d35e333..0fb4c57 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -68,6 +68,7 @@ namespace nitrokey{
uint32_t NitrokeyManager::get_TOTP_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time,
uint8_t last_interval) {
assert(is_valid_totp_slot_number(slot_number));
+ slot_number = get_internal_slot_number_for_totp(slot_number);
auto gt = get_payload<GetTOTP>();
gt.slot_number = slot_number;
gt.challenge = challenge;
@@ -119,8 +120,10 @@ namespace nitrokey{
return false;
}
+ enum totp_config{digits8=0, enter, tokenID};
+
bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret,
- uint16_t time_window, const char *temporary_password) {
+ uint16_t time_window, bool use_8_digits, const char *temporary_password) {
assert(is_valid_totp_slot_number(slot_number));
assert(strlen(secret)==20); //160 bits
assert(strlen(slot_name)<=15);
@@ -131,7 +134,9 @@ namespace nitrokey{
strcpy((char *) payload.slot_secret, secret);
strcpy((char *) payload.slot_name, slot_name);
payload.slot_interval = time_window; //FIXME naming
- payload.slot_config; //TODO
+ bitset<8> config; //FIXME better config manipulation
+ config.set(totp_config::digits8, use_8_digits);
+ payload.slot_config = (uint8_t) config.to_ulong();
auto auth = get_payload<Authorize>();
strcpy((char *) (auth.temporary_password), temporary_password);
@@ -168,5 +173,20 @@ namespace nitrokey{
return true;
}
+ bool NitrokeyManager::set_time(uint64_t time) {
+ auto p = get_payload<SetTime>();
+ p.reset = 1;
+ p.time = time;
+ SetTime::CommandTransaction::run(*device, p);
+ return false;
+ }
+
+ bool NitrokeyManager::mark_time() {
+ auto p = get_payload<SetTime>();
+ p.reset = 0;
+ SetTime::CommandTransaction::run(*device, p);
+ return false;
+ }
+
} \ No newline at end of file