Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOTP window isn't time but counter related #10

Open
Gummibeer opened this issue Aug 29, 2016 · 3 comments
Open

TOTP window isn't time but counter related #10

Gummibeer opened this issue Aug 29, 2016 · 3 comments

Comments

@Gummibeer
Copy link

Gummibeer commented Aug 29, 2016

From my understanding the window in a TOTP is also a value in seconds like the timestep - but in this package it's used as a counter window and this is something strange.
For example I have a timestep of 30 seconds and want to allow this otp also 5secs before and after - there is no way cause the window is counter and not time based.

A solution would be something like this:

public function validate($otp, $counter = null)
{
    if ($counter === null) {
        $counter = time();
    }
    $window = $this->getWindow();
    foreach(range($window * -1, $window) as $timeDrift) {
        $current = self::timestampToCounter($counter + $timeDrift, $this->getTimeStep());
        if ($otp === parent::calculate($current)) {
            return true;
        }
    }
    return false;
}
@rchouinard
Copy link
Owner

This is actually the way TOTP works. RFC 6238 extends RFC 4226 by converting a timestamp into a counter value based on a defined algorithm. The counter value will change every TIME_STEP seconds.

In practice this means the window size must be a multiple of TIME_STEP, you cannot have partial window size.

@Gummibeer
Copy link
Author

Ok, have read it a bit different but yes, After a second read it's like this.
Is there another RFC for time based otp that allows a time drift in seconds unrelated to the time step?

@pavarnos
Copy link
Contributor

does #9 answer your question? we have tokens that drift away from standard time (because they are cheap physical devices with an internal clock that has no way to sync with the internet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants