Added idea to use crypt seal in the future when login password changes

This commit is contained in:
the-djmaze 2023-08-28 16:59:00 +02:00
parent 335b6bc5c8
commit 8b246e64a6

View file

@ -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;