From 8b246e64a68856d234c01d4f57b26200dedb8a17 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 28 Aug 2023 16:59:00 +0200 Subject: [PATCH] Added idea to use crypt seal in the future when login password changes --- .../libraries/RainLoop/Model/MainAccount.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php index d369e20bc..e560f99cb 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php @@ -4,17 +4,45 @@ namespace RainLoop\Model; use RainLoop\Utils; use RainLoop\Exceptions\ClientException; +use RainLoop\Providers\Storage\Enumerations\StorageType; class MainAccount extends Account { /** * @var string */ - private $sCryptKey; - + private string $sCryptKey = ''; +/* + public function resealCryptKey(string $sOldPass, string $sNewPass) : string + { + $oStorage = \RainLoop\Api::Actions()->StorageProvider(); + $sKey = $oStorage->Get($this, StorageType::ROOT, 'cryptkey'); + if ($sKey) { + $sKey = \SnappyMail\Crypt::DecryptUrlSafe($sKey, $sOldPass); + $sKey = \SnappyMail\Crypt::EncryptUrlSafe($sKey, $sNewPass); + $oStorage->Put($this, StorageType::ROOT, 'cryptkey', $sKey); + $sKey = \SnappyMail\Crypt::DecryptUrlSafe($sKey, $sNewPass); + $this->SetCryptKey($sKey); + } + } +*/ public function CryptKey() : string { if (!$this->sCryptKey) { +/* + // Seal the cryptkey so that people who change their login password + // can use the old password to re-seal the cryptkey + $oStorage = \RainLoop\Api::Actions()->StorageProvider(); + $sKey = $oStorage->Get($this, StorageType::ROOT, 'cryptkey'); + if (!$sKey) { + $sKey = $this->IncPassword(); +// $sKey = \random_bytes(32); + $sKey = \SnappyMail\Crypt::EncryptUrlSafe($sKey, $this->IncPassword()); + $oStorage->Put($this, StorageType::ROOT, 'cryptkey', $sKey); + } + $sKey = \SnappyMail\Crypt::DecryptUrlSafe($sKey, $this->IncPassword()); + $this->SetCryptKey($sKey); +*/ $this->SetCryptKey($this->IncPassword()); } return $this->sCryptKey;