Skip to content

Commit

Permalink
Merge branch 'pr_90'
Browse files Browse the repository at this point in the history
Allow TOTP implementation to work with timestamps beyond 2038

From #90:
> This uses the system clock for storing the offset since the last update only.
Unix timestamp of the set_time command is stored locally as u64 to prevent year 2038 integer overrun and added to current local offset for TOTP generation.
> Passes https://github.com/Nitrokey/libnitrokey/blob/0275ebc610b255e3519baf866438244f288576bc/unittest/test_pro.py#L456 now.

Fixes #17
Fixes #90
  • Loading branch information
szszszsz committed Jun 18, 2019
2 parents cbd266b + 13077b9 commit baaf046
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/OTP/hotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,14 +1209,14 @@ time_t now;

// Get the local ATMEL time
time (&now);
current_time = now;

if (slot_no >= NUMBER_OF_TOTP_SLOTS)
return 0;

OTP_slot *slot = (OTP_slot *) get_totp_slot_addr(slot_no);

time_min = current_time / slot->interval_or_counter;
// Add last time stamp from app and elapsed seconds since last set_time operation
time_min = (current_time + now) / slot->interval_or_counter;

if (slot->type != 'T') // unprogrammed slot
return 0;
Expand Down
7 changes: 5 additions & 2 deletions src/OTP/report_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2176,9 +2176,12 @@ u32 new_time_minutes = (new_time - 1388534400) / 60; // 1388534400 = 01.01.20
CI_StringOut ("Local time set to = "); itoa (new_time,text); CI_StringOut ((char*)text);
CI_StringOut (" = "); ctime_r ((time_t*)&new_time,(char*)text); CI_StringOut ((char*)text); CI_StringOut ("\r\n"); } */
set_time (new_time);


// Reset runtime counter and store the time offset that was received from the app
set_time (0);
current_time = new_time;

// Write new timestamp to Flash
err = set_time_value (new_time_minutes);
if (err)
{
Expand Down

0 comments on commit baaf046

Please sign in to comment.