Description
I got asked by a colleague if this is a good library to use, and I'm sorry to conclude it is not secure due to its missing replay protections. This library only verifies if the code is correct (within allowable time window), but does not care if the same (or a later) code has been already provided or not.
Typically, I'd expect the high-level API to be
public long isValidCode(String secret, String code, long lastSuccessfulBucket) {}
returning the ID of the successful bucket or some special value if the code is invalid. (Maybe there's a better way to do that in Java, I'm not a Java guy :) But you get the idea.)
The key is that the backend DB should store the bucket for the last successful TOTP code - and never accept any from the same or previous buckets (since they could be replayed etc.). Currently, there's no way of knowing if the coming TOTP code is being replayed or not.
Unfortunately, due to this I cannot recommend the library for production. Which is a pity since I like its features.