This commit is contained in:
the-djmaze 2024-04-13 13:18:31 +02:00
parent 3ced479ac9
commit fffc044998

View file

@ -14,18 +14,21 @@ class MainAccount extends Account
public function resealCryptKey(SensitiveString $oOldPass) : bool public function resealCryptKey(SensitiveString $oOldPass) : bool
{ {
$sKey = $this->CryptKey(); $oStorage = \RainLoop\Api::Actions()->StorageProvider();
$sKey = $oStorage->Get($this, StorageType::ROOT, '.cryptkey');
if ($sKey) { if ($sKey) {
$sKey = \SnappyMail\Crypt::EncryptToJSON(\bin2hex($sKey), $this->IncPassword()); $sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $oOldPass);
if ($sKey) { if (!$sKey) {
\RainLoop\Api::Actions()->StorageProvider()->Put($this, StorageType::ROOT, '.cryptkey', $sKey); throw new ClientException(Notifications::CryptKeyError);
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $this->IncPassword());
if ($sKey) {
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
} }
$sKey = \SnappyMail\Crypt::EncryptToJSON($sKey, $this->IncPassword());
if ($sKey) {
$this->sCryptKey = null;
if (\RainLoop\Api::Actions()->StorageProvider()->Put($this, StorageType::ROOT, '.cryptkey', $sKey)) {
return true; return true;
} }
} }
}
return false; return false;
} }
@ -44,11 +47,10 @@ class MainAccount extends Account
$oStorage->Put($this, StorageType::ROOT, '.cryptkey', $sKey); $oStorage->Put($this, StorageType::ROOT, '.cryptkey', $sKey);
} }
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $this->IncPassword()); $sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $this->IncPassword());
if ($sKey) { if (!$sKey) {
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
} else {
throw new ClientException(Notifications::CryptKeyError); throw new ClientException(Notifications::CryptKeyError);
} }
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
} }
return $this->sCryptKey; return $this->sCryptKey;
} }