Skip to content

Commit

Permalink
added support for variable intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
itzandroidtab committed Mar 23, 2024
1 parent 4ebcac2 commit 0467441
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Open source hardware TOTP token. Currently targets the LPC1756, LPC1758 and LPC1
* support to change the RTC calibration values in the settings
* support for setting the time + timezone (currently only GMT)
* 60 seconds screen timeout
* support for different intervals (supports 1 - 180 seconds)

### Images
Images can be found in the project logs at [hackaday](https://hackaday.io/project/194867-hardware-2fa-totp-authenticator)

### TODO
* encrypt profiles
* support for different intervals
* add support for more than 32 profiles (needs a rework if more profiles are required. The profiles are copied to ram and there is not enough for more at the moment. If we leave them in flash we can store a lot more)
* rework the calibration and time settings screens

Expand Down
12 changes: 11 additions & 1 deletion ui/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,17 @@ namespace menu {
(*interval_end) = 0x00;

// convert the string to a number
ret.interval = klib::string::stoi(str_end + 1);
const uint32_t interval = klib::string::stoi(str_end + 1);

// check if the interval is valid
if ((interval > 180) || (!interval)) {
// invalid, interval is too high or too low. clear the buffers and go to the next one
buffer.clear();

continue;
}

ret.interval = interval;

// get the length of the interval
auto digits_end = std::find(interval_end + 1, (buffer.data() + buffer.size()), ',');
Expand Down
19 changes: 11 additions & 8 deletions ui/totp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ namespace menu {
};

template <typename T, typename G>
void draw_timer(FrameBuffer& frame_buffer, const klib::vector2i position, const klib::time::ms time, const T sin, const G cos) {
for (uint32_t i = (time.value * (sin.size / 30)) / 1000; i < sin.size; i++) {
void draw_timer(FrameBuffer& frame_buffer, const uint32_t interval, const klib::vector2i position, const klib::time::ms time, const T sin, const G cos) {
for (uint32_t i = (time.value * (sin.size / interval)) / 1000; i < sin.size; i++) {
const uint32_t index = (sin.size + ((sin.size / 4) * 3) + i) % sin.size;

const klib::vector2i p = position + klib::vector2i{
Expand Down Expand Up @@ -99,12 +99,12 @@ namespace menu {
case storage::digit::digits_6:
return klib::crypt::totp<hash, 6>::hash(
reinterpret_cast<const uint8_t*>(entry.key.data()),
entry.key.size(), current.value, 30, 0
entry.key.size(), current.value, entry.interval, 0
);
case storage::digit::digits_8:
return klib::crypt::totp<hash, 8>::hash(
reinterpret_cast<const uint8_t*>(entry.key.data()),
entry.key.size(), current.value, 30, 0
entry.key.size(), current.value, entry.interval, 0
);
}

Expand Down Expand Up @@ -185,7 +185,10 @@ namespace menu {
klib::string::itoa(last_epoch.value, epoch_buf);

// update the seconds left in this cycle
klib::string::itoa(30 - (last_epoch.value % 30), seconds_left_buf);
klib::string::itoa(
entries[current].interval - (last_epoch.value % entries[current].interval),
seconds_left_buf
);

// the time has changed. Mark the totp as changed
// to force a update on the buffers
Expand All @@ -205,7 +208,7 @@ namespace menu {

// get the next token
const uint32_t next_token = get_token(
entries[current], last_epoch + klib::time::s(30)
entries[current], last_epoch + klib::time::s(entries[current].interval)
);

// copy the token to the buffer and set the width
Expand Down Expand Up @@ -307,11 +310,11 @@ namespace menu {

const klib::time::ms runtime = (
klib::io::systick<>::get_runtime() - last_update
) + klib::time::s(last_epoch.value % 30);
) + klib::time::s(last_epoch.value % entries[current].interval);

// draw all the circles
for (uint32_t i = 0; i < sizeof(lookuptable_sin) / sizeof(lookuptable_sin[0]); i++) {
draw_timer(frame_buffer, position, runtime, lookuptable_sin[i], lookuptable_cos[i]);
draw_timer(frame_buffer, entries[current].interval, position, runtime, lookuptable_sin[i], lookuptable_cos[i]);
}

// draw the time left in seconds in the circle
Expand Down

0 comments on commit 0467441

Please sign in to comment.