Resolve #161 part 2

This commit is contained in:
djmaze 2021-11-18 09:22:24 +01:00
parent ac5daa5c22
commit 779e7c7685

View file

@ -241,10 +241,11 @@ trait Contacts
public function setContactsSyncData(\RainLoop\Model\Account $oAccount, array $aData) : bool public function setContactsSyncData(\RainLoop\Model\Account $oAccount, array $aData) : bool
{ {
$oMainAccount = $this->getAccountFromToken();
if ($aData['Password']) { if ($aData['Password']) {
$aData['Password'] = \SnappyMail\Crypt::EncryptToJSON($aData['Password'], $oAccount->CryptKey()); $aData['Password'] = \SnappyMail\Crypt::EncryptToJSON($aData['Password'], $oMainAccount->CryptKey());
} }
$aData['PasswordHMAC'] = $aData['Password'] ? \hash_hmac('sha1', $aData['Password'], $oAccount->CryptKey()) : null; $aData['PasswordHMAC'] = $aData['Password'] ? \hash_hmac('sha1', $aData['Password'], $oMainAccount->CryptKey()) : null;
return $this->StorageProvider()->Put( return $this->StorageProvider()->Put(
$oAccount, $oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG, \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
@ -263,15 +264,16 @@ trait Contacts
$aData = \json_decode($sData); $aData = \json_decode($sData);
if ($aData) { if ($aData) {
if ($aData['Password']) { if ($aData['Password']) {
$oMainAccount = $this->getAccountFromToken();
// Verify oAccount password hasn't changed so that Password can be decrypted // Verify oAccount password hasn't changed so that Password can be decrypted
if ($aData['PasswordHMAC'] !== \hash_hmac('sha1', $aData['Password'], $oAccount->CryptKey())) { if ($aData['PasswordHMAC'] !== \hash_hmac('sha1', $aData['Password'], $oMainAccount->CryptKey())) {
// Failed // Failed
$aData['Password'] = null; $aData['Password'] = null;
} else { } else {
// Success // Success
$aData['Password'] = \SnappyMail\Crypt::DecryptFromJSON( $aData['Password'] = \SnappyMail\Crypt::DecryptFromJSON(
$aData['Password'], $aData['Password'],
$oAccount->CryptKey() $oMainAccount->CryptKey()
); );
} }
} }