Improved FIDO U2F error reporting

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

View File

@ -13,6 +13,7 @@ use PhpMyAdmin\SecondFactor;
use PhpMyAdmin\Template;
use PhpMyAdmin\Plugins\SecondFactorPlugin;
use Samyoul\U2F\U2FServer\U2FServer;
use Samyoul\U2F\U2FServer\U2FException;
/**
* Hardware key based second factor
@ -105,7 +106,8 @@ class Key extends SecondFactorPlugin
$this->_second->config['settings']['registrations'][$authentication->index]['counter'] = $authentication->counter;
$this->_second->save();
return true;
} catch (\Exception $e) {
} catch (U2FException $e) {
$this->_message = $e->getMessage();
return false;
}
}
@ -188,7 +190,8 @@ class Key extends SecondFactorPlugin
'counter' => $registration->getCounter(),
];
return true;
} catch (\Exception $e) {
} catch (U2FException $e) {
$this->_message = $e->getMessage();
return false;
}
}

View File

@ -34,6 +34,11 @@ class SecondFactorPlugin
*/
protected $_provided;
/**
* @var string
*/
protected $_message;
/**
* Creates object
*
@ -43,6 +48,7 @@ class SecondFactorPlugin
{
$this->_second = $second;
$this->_provided = false;
$this->_message = '';
}
/**
@ -53,6 +59,11 @@ class SecondFactorPlugin
public function getError()
{
if ($this->_provided) {
if (!empty($this->_message)) {
return Message::rawError(
sprintf(__('Two-factor authentication failed: %s'), $this->_message)
)->getDisplay();
}
return Message::rawError(
__('Two-factor authentication failed.')
)->getDisplay();