From 17932f2905dbbc2105f1a0973034f7e1e145b1e8 Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 18 Nov 2021 13:51:11 +0100 Subject: [PATCH] Bugfix: broken TOTP plugin --- plugins/two-factor-auth/index.php | 45 ++++++++++--------- .../v/0.0.0/app/libraries/snappymail/totp.php | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/plugins/two-factor-auth/index.php b/plugins/two-factor-auth/index.php index f2dcb870e..0209e39cd 100644 --- a/plugins/two-factor-auth/index.php +++ b/plugins/two-factor-auth/index.php @@ -1,14 +1,15 @@ addTemplate('templates/PopupsTwoFactorAuthTest.html'); } - public function DoLogin(\RainLoop\Model\Account $oAccount) + public function DoLogin(MainAccount $oAccount) { if ($this->TwoFactorAuthProvider($oAccount)) { $aData = $this->getTwoFactorInfo($oAccount); if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) { $sCode = \trim($this->jsonParam('totp_code', '')); if (empty($sCode)) { - $this->Logger()->Write("TFA: Code required for {$oAccount->ParentEmailHelper()}"); + $this->Logger()->Write("TFA: Code required for {$oAccount->Email()}"); throw new ClientException(\RainLoop\Notifications::AuthError); } @@ -48,23 +49,23 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin $aBackupCodes = \explode(' ', \trim(\preg_replace('/[^\d]+/', ' ', $aData['BackupCodes']))); $bUseBackupCode = \in_array($sCode, $aBackupCodes); if ($bUseBackupCode) { - $this->removeBackupCodeFromTwoFactorInfo($oAccount->ParentEmailHelper(), $sCode); + $this->removeBackupCodeFromTwoFactorInfo($oAccount->Email(), $sCode); } } if (!$bUseBackupCode && !$this->TwoFactorAuthProvider($oAccount)->VerifyCode($aData['Secret'], $sCode)) { $this->Manager()->Actions()->LoggerAuthHelper($oAccount); - $this->Logger()->Write("TFA: Code failed for {$oAccount->ParentEmailHelper()}"); + $this->Logger()->Write("TFA: Code failed for {$oAccount->Email()}"); throw new ClientException(\RainLoop\Notifications::AuthError); } - $this->Logger()->Write("TFA: Code verified for {$oAccount->ParentEmailHelper()}"); + $this->Logger()->Write("TFA: Code verified for {$oAccount->Email()}"); } } } public function DoGetTwoFactorInfo() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); @@ -75,13 +76,13 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin public function DoCreateTwoFactorSecret() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); } - $sEmail = $oAccount->ParentEmailHelper(); + $sEmail = $oAccount->Email(); $sSecret = $this->TwoFactorAuthProvider($oAccount)->CreateSecret(); @@ -107,7 +108,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin public function DoShowTwoFactorSecret() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); @@ -121,7 +122,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin public function DoEnableTwoFactor() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); @@ -133,7 +134,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin $oSettings->SetConf('EnableTwoFactor', !empty($sValue)); } - $sEmail = $oAccount->ParentEmailHelper(); + $sEmail = $oAccount->Email(); $bResult = false; $mData = $this->getTwoFactorInfo($oAccount); @@ -156,7 +157,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin public function DoVerifyTwoFactorCode() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); @@ -173,7 +174,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin public function DoClearTwoFactorInfo() : array { - $oAccount = $this->getAccountFromToken(); + $oAccount = $this->getMainAccountFromToken(); if (!$this->TwoFactorAuthProvider($oAccount)) { return $this->jsonResponse(__FUNCTION__, false); @@ -191,9 +192,9 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin { return $this->Manager()->Actions()->Logger(); } - protected function getAccountFromToken() : \RainLoop\Model\Account + protected function getMainAccountFromToken() : MainAccount { - return $this->Manager()->Actions()->GetAccount(); + return $this->Manager()->Actions()->getMainAccountFromToken(); } protected function StorageProvider() : \RainLoop\Providers\Storage { @@ -201,7 +202,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin } private $oTwoFactorAuthProvider; - protected function TwoFactorAuthProvider(\RainLoop\Model\Account $oAccount) : ?TwoFactorAuthInterface + protected function TwoFactorAuthProvider(MainAccount $oAccount) : ?TwoFactorAuthInterface { if (!$this->oTwoFactorAuthProvider) { require __DIR__ . '/providers/interface.php'; @@ -211,9 +212,9 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin return $this->oTwoFactorAuthProvider; } - protected function getTwoFactorInfo(\RainLoop\Model\Account $oAccount, bool $bRemoveSecret = false) : array + protected function getTwoFactorInfo(MainAccount $oAccount, bool $bRemoveSecret = false) : array { - $sEmail = $oAccount->ParentEmailHelper(); + $sEmail = $oAccount->Email(); $mData = null; @@ -273,7 +274,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin return $aResult; } - protected function removeBackupCodeFromTwoFactorInfo(\RainLoop\Model\Account $oAccount, string $sCode) : bool + protected function removeBackupCodeFromTwoFactorInfo(MainAccount $oAccount, string $sCode) : bool { if (!$oAccount || empty($sCode)) { diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/totp.php b/snappymail/v/0.0.0/app/libraries/snappymail/totp.php index 83b00f28e..bd0c56e99 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/totp.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/totp.php @@ -29,7 +29,7 @@ abstract class TOTP return false; } - public function CreateSecret() : string + public static function CreateSecret() : string { $CHARS = \array_keys(static::$map); $length = 16;