-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
For a secure TOTP I need a method to check the validity of 3 TOTP codes.
In my example I check 24 hours ahead and behind. The 3 codes must exist in this period
and they must be consecutive.
The method must accept the secret and 3 TOTP codes and returns two results.
- boolean valid: true = the 3 codes are valid and they are consecutive.
- int shift: how many periods the codes are behind or ahead
Here an idea how this could look like:
TimeProvider timeProvider = new SystemTimeProvider();
CodeGenerator codeGenerator = new DefaultCodeGenerator();
DefaultCodeVerifier verifier = new DefaultCodeVerifier(codeGenerator, timeProvider);
long periods = TimeUnit.HOURS.toSeconds(24) / 30;
//would be nice if I could use verifier.getTimePeriod(), instead of the hardcoded 30
//or there is a method to set the discrepancy in seconds and the library calculates the periods
verifier.setAllowedTimePeriodDiscrepancy((int)periods);
// setAllowedTimePeriodDiscrepancy does not accept long
VerificationResult result = verifier.areCodesValid(secret, code1, code2, code3);
//result should contain a boolean, if the codes are valid and consecutive
//and it should return a time shift number (int). How many periods the codes are behind or ahead
For my example TOTP application I had to write my own TOTP verifier based on the now archived aerogear project. Would be nice if I could switch to your library.
See also this issue for more details why this method is needed.
Metadata
Metadata
Assignees
Labels
No labels