-
Notifications
You must be signed in to change notification settings - Fork 38
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
Fix addwindow #19
Fix addwindow #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.rebar3 | ||
.eunit | ||
.rebar | ||
ebin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ valid_totp(Token, Secret, Opts) -> | |
Token -> | ||
true; | ||
_ -> | ||
Window = proplists:get_value(window, Opts, 0), | ||
Window = proplists:get_value(addwindow, Opts, 0), | ||
case check_candidate(Token, Secret, IntervalsNo - Window, IntervalsNo + Window, Opts) of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
false -> | ||
false; | ||
|
@@ -119,21 +119,20 @@ valid_totp(Token, Secret, Opts) -> | |
-spec time_interval(proplist()) -> time(). | ||
time_interval(Opts) -> | ||
IntervalLength = proplists:get_value(interval_length, Opts, 30), | ||
AddSeconds = proplists:get_value(addwindow, Opts, 0) * proplists:get_value(interval_length, Opts, 30), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain to me why this behavior should be changed? We extensively use this in our application tests. |
||
{MegaSecs, Secs, _} = proplists:get_value(timestamp, Opts, os:timestamp()), | ||
trunc((MegaSecs * 1000000 + (Secs + AddSeconds)) / IntervalLength). | ||
trunc((MegaSecs * 1000000 + (Secs)) / IntervalLength). | ||
|
||
check_candidate(Token, Secret, Current, Last, Opts) when Current =< Last -> | ||
case Current of | ||
Last -> | ||
false; | ||
check_candidate(_, _, Current, Last, _) when Current > Last -> | ||
false; | ||
|
||
check_candidate(Token, Secret, Current, Last, Opts) -> | ||
Candidate = hotp(Secret, Current, Opts), | ||
case Candidate of | ||
Token -> | ||
Current; | ||
_ -> | ||
Candidate = hotp(Secret, Current, Opts), | ||
case Candidate of | ||
Token -> | ||
Current; | ||
_ -> | ||
check_candidate(Token, Secret, Current + 1, Last, Opts) end end. | ||
check_candidate(Token, Secret, Current + 1, Last, Opts) end. | ||
|
||
|
||
-spec prepend_zeros(token(), non_neg_integer()) -> token(). | ||
prepend_zeros(Token, N) -> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me.
window
is the parameter that expands the number of allowed interval tokens to be used (basically +/-window
intervals are considered valid).addwindow
is supposed to offset the interval that you check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nalundgaard, that's very useful to know! It would be great if the docs described these options in a bit more detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danturn Indeed! It's definitely worth tracking separately. The examples hint at what the options do, but they really don't explain in detail their intention, so you kind of have to piece it together from reading the code and being familiar with the hotp/totp RFC nomenclature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danturn maybe you will like #22.