Properly update FIDO U2F counter on login

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2017-11-01 15:22:08 +01:00
parent c64e52c3c0
commit e67ea08eae
2 changed files with 15 additions and 3 deletions

View File

@ -47,12 +47,13 @@ class Key extends SecondFactorPlugin
public function getRegistrations()
{
$result = [];
foreach ($this->_second->config['settings']['registrations'] as $data) {
foreach ($this->_second->config['settings']['registrations'] as $index => $data) {
$reg = new \StdClass;
$reg->keyHandle = $data['keyHandle'];
$reg->publicKey = $data['publicKey'];
$reg->certificate = $data['certificate'];
$reg->counter = $data['counter'];
$reg->index = $index;
$result[] = $reg;
}
return $result;
@ -101,7 +102,8 @@ class Key extends SecondFactorPlugin
$this->getRegistrations(),
$response
);
// TODO: Store counter
$this->_second->config['settings']['registrations'][$authentication->index]['counter'] = $authentication->counter;
$this->_second->save();
return true;
} catch (\Exception $e) {
return false;

View File

@ -179,6 +179,16 @@ class SecondFactor
return $this->_backend->getError() . $this->_backend->setup();
}
/**
* Saves current configuration.
*
* @return true|PhpMyAdmin\Message
*/
public function save()
{
return UserPreferences::persistOption('2fa', $this->config, null);
}
/**
* Changes second factor settings
*
@ -209,7 +219,7 @@ class SecondFactor
return false;
}
}
$result = UserPreferences::persistOption('2fa', $this->config, null);
$result = $this->save();
if ($result !== true) {
$result->display();
}