From 018e91bc0c2e5520792025d326fe6e9a061f0a6e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 16 Feb 2023 10:28:30 +0100 Subject: [PATCH] add any further debug loggings --- .../Controller/Admin/d3webauthnadminlogin.php | 9 ++++++++- src/Application/Controller/d3webauthnlogin.php | 8 ++++++++ src/Application/Model/Webauthn.php | 18 ++++++++++++++---- src/Application/Model/WebauthnErrors.php | 4 ++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Application/Controller/Admin/d3webauthnadminlogin.php b/src/Application/Controller/Admin/d3webauthnadminlogin.php index e7359ec..f95133b 100755 --- a/src/Application/Controller/Admin/d3webauthnadminlogin.php +++ b/src/Application/Controller/Admin/d3webauthnadminlogin.php @@ -110,11 +110,18 @@ class d3webauthnadminlogin extends AdminController $this->addTplParam('isAdmin', isAdmin()); } catch (WebauthnException $e) { d3GetOxidDIC()->get('d3ox.webauthn.'.Session::class) - ->setVariable(WebauthnConf::GLOBAL_SWITCH, true); + ->setVariable(WebauthnConf::GLOBAL_SWITCH, true); d3GetOxidDIC()->get('d3ox.webauthn.'.UtilsView::class)->addErrorToDisplay($e); d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->error($e->getDetailedErrorMessage(), ['UserId' => $userId]); d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug($e->getTraceAsString()); d3GetOxidDIC()->get('d3ox.webauthn.'.Utils::class)->redirect('index.php?cl=login'); + } catch (AssertionFailedException $e) { + d3GetOxidDIC()->get('d3ox.webauthn.'.Session::class) + ->setVariable(WebauthnConf::GLOBAL_SWITCH, true); + d3GetOxidDIC()->get('d3ox.webauthn.'.UtilsView::class)->addErrorToDisplay($e); + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->error($e->getMessage(), ['UserId' => $userId]); + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug($e->getTraceAsString()); + d3GetOxidDIC()->get('d3ox.webauthn.'.Utils::class)->redirect('index.php?cl=login'); } } diff --git a/src/Application/Controller/d3webauthnlogin.php b/src/Application/Controller/d3webauthnlogin.php index f367a1a..0e96cbb 100755 --- a/src/Application/Controller/d3webauthnlogin.php +++ b/src/Application/Controller/d3webauthnlogin.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace D3\Webauthn\Application\Controller; +use Assert\AssertionFailedException; use D3\TestingTools\Production\IsMockable; use D3\Webauthn\Application\Model\Webauthn; use D3\Webauthn\Application\Model\WebauthnConf; @@ -103,6 +104,13 @@ class d3webauthnlogin extends FrontendController d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug($e->getTraceAsString()); Registry::getUtilsView()->addErrorToDisplay($e); d3GetOxidDIC()->get('d3ox.webauthn.'.Utils::class)->redirect('index.php?cl=start'); + } catch (AssertionFailedException $e) { + d3GetOxidDIC()->get('d3ox.webauthn.'.Session::class) + ->setVariable(WebauthnConf::GLOBAL_SWITCH, true); + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->error($e->getMessage(), ['UserId' => $userId]); + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug($e->getTraceAsString()); + Registry::getUtilsView()->addErrorToDisplay($e); + d3GetOxidDIC()->get('d3ox.webauthn.'.Utils::class)->redirect('index.php?cl=start'); } } diff --git a/src/Application/Model/Webauthn.php b/src/Application/Model/Webauthn.php index 22abc64..e2e9b51 100644 --- a/src/Application/Model/Webauthn.php +++ b/src/Application/Model/Webauthn.php @@ -15,7 +15,9 @@ declare(strict_types=1); namespace D3\Webauthn\Application\Model; +use Assert\Assert; use Assert\AssertionFailedException; +use Assert\InvalidArgumentException; use D3\TestingTools\Production\IsMockable; use D3\Webauthn\Application\Model\Credential\PublicKeyCredential; use D3\Webauthn\Application\Model\Credential\PublicKeyCredentialList; @@ -134,6 +136,7 @@ class Webauthn * @return string * @throws DoctrineDriverException * @throws DoctrineException + * @throws InvalidArgumentException */ public function getRequestOptions(string $userId): string { @@ -143,11 +146,16 @@ class Webauthn d3GetOxidDIC()->set(UserEntity::class.'.args.user', $user); /** @var UserEntity $userEntity */ $userEntity = d3GetOxidDIC()->get(UserEntity::class); + $existingCredentials = $this->getExistingCredentials($userEntity); + + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug( + 'found user credentials: '.count($existingCredentials).' for ID '.$userId) + ); // We generate the set of options. $publicKeyCredentialRequestOptions = $this->getServer()->generatePublicKeyCredentialRequestOptions( PublicKeyCredentialRequestOptions::USER_VERIFICATION_REQUIREMENT_PREFERRED, // Default value - $this->getExistingCredentials($userEntity) + $existingCredentials ); d3GetOxidDIC()->get('d3ox.webauthn.'.Session::class) @@ -155,9 +163,11 @@ class Webauthn $json = $this->jsonEncode($publicKeyCredentialRequestOptions); - if ($json === false) { - throw oxNew(Exception::class, "can't encode request options"); - } + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug( + 'request options: '.$json + ); + + Assert::that($json)->minLength(1, "can't encode request options"); return $json; } diff --git a/src/Application/Model/WebauthnErrors.php b/src/Application/Model/WebauthnErrors.php index cd616f1..0df2980 100644 --- a/src/Application/Model/WebauthnErrors.php +++ b/src/Application/Model/WebauthnErrors.php @@ -38,6 +38,10 @@ class WebauthnErrors */ public function translateError(string $msg, string $type = null): string { + d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->debug( + 'error occured: '.$msg + ); + $lang = d3GetOxidDIC()->get('d3ox.webauthn.'.Language::class); $type = $type ? '_'.$type : null;