freedomofpress/securedrop — pull request #786 by garrettr (2014-12-06 00:05:08+00:00)
Title: Harden document interface logins

Increases the allowed window for TOTP tokens from 0:30 to 1:30 (one minute and thirty seconds) as an additional mitigation for potential clock skew between the server and the client. This is an additional mitigation (along with #739) for #736.

Since increasing the window makes it easier for brute force attacks on the two factor token, this PR also implements the following hardening techniques (based on the optional hardening measures in the `google-authenticator` PAM module):

1. TOTP (time-based) tokens are now single use. This can prevent and/or help detect MITM attacks on the token.
* Attempting to log in multiple times with the same token will fail with a helpful error message ("please wait until a new two-factor token is generated before logging in again").
* There is a usability trade-off: if you mis-type your password, you will have to wait for the token to recycle before you can try again. We think the added security is worth this trade-off.
* This correctly handles HOTP separately. Since an HOTP token is only re-used consecutively with extremely small probability, we simply report a generic login failure.
2. All login attempts are throttled. A user cannot make more than 5 login attempts per minute. This makes it harder for attackers to brute force a user's password, and nearly impossible for them to brute force their two-factor token.