From 2af38a3de8a3277bd1ad984a6fef8a2487f0346e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 1 Nov 2017 15:30:06 +0100 Subject: [PATCH] Improved FIDO U2F error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/classes/Plugins/SecondFactor/Key.php | 7 +++++-- libraries/classes/Plugins/SecondFactorPlugin.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Plugins/SecondFactor/Key.php b/libraries/classes/Plugins/SecondFactor/Key.php index 9e6e43336b..ead8abe8b8 100644 --- a/libraries/classes/Plugins/SecondFactor/Key.php +++ b/libraries/classes/Plugins/SecondFactor/Key.php @@ -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; } } diff --git a/libraries/classes/Plugins/SecondFactorPlugin.php b/libraries/classes/Plugins/SecondFactorPlugin.php index 3fb074ee8d..29d4e028db 100644 --- a/libraries/classes/Plugins/SecondFactorPlugin.php +++ b/libraries/classes/Plugins/SecondFactorPlugin.php @@ -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();