HomePhabricator

Simplify and correct some challenge TTL lockout code

Description

Simplify and correct some challenge TTL lockout code

Summary:
Depends on D19889. Ref T13222. Some of this logic is either not-quite-right or a little more complicated than it needs to be.

Currently, we TTL TOTP challenges after three timesteps -- once the current code could no longer be used. But we actually have to TTL it after five timesteps -- once the most-future acceptable code could no longer be used. Otherwise, you can enter the most-future code now (perhaps the attacker compromises NTP and skews the server clock back by 75 seconds) and then an attacker can re-use it in three timesteps.

Generally, simplify things a bit and trust TTLs more. This also makes the "wait" dialog friendlier since we can give users an exact number of seconds.

The overall behavior here is still a little odd because we don't actually require you to respond to the challenge you were issued (right now, we check that the response is valid whenever you submit it, not that it's a valid response to the challenge we issued), but that will change in a future diff. This is just moving us generally in the right direction, and doesn't yet lock everything down properly.

Test Plan:

  • Added a little snippet to the control caption to list all the valid codes to make this easier:
$key = new PhutilOpaqueEnvelope($config->getFactorSecret());
$valid = array();
foreach ($this->getAllowedTimesteps() as $step) {
  $valid[] = self::getTOTPCode($key, $step);
}

$control->setCaption(
  pht(
    'Valid Codes: '.implode(', ', $valid)));
  • Used the most-future code to sign L3.
  • Verified that L4 did not unlock until the code for L3 left the activation window.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13222

Differential Revision: https://secure.phabricator.com/D19890

Details

Provenance
epriestleyAuthored on Dec 14 2018, 3:50 PM
epriestleyPushed on Dec 20 2018, 10:44 PM
Reviewer
amckinley
Differential Revision
D19890: Simplify and correct some challenge TTL lockout code
Parents
rP2de632d4fe98: Update continue/break for php 7.3
Branches
Unknown
Tags
Unknown
Tasks
T13222: 2018 Week 48-51 Bonus Content
Build Status
Buildable 21406
Build 29154: Run Core Tests