mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 06:57:03 +03:00
fix crypt error in case of oidc and normal login both is enabled
This commit is contained in:
parent
ed41d8e45f
commit
23f4e52873
1 changed files with 71 additions and 22 deletions
|
|
@ -16,19 +16,43 @@ class MainAccount extends Account
|
||||||
{
|
{
|
||||||
$oStorage = \RainLoop\Api::Actions()->StorageProvider();
|
$oStorage = \RainLoop\Api::Actions()->StorageProvider();
|
||||||
$sKey = $oStorage->Get($this, StorageType::ROOT, '.cryptkey');
|
$sKey = $oStorage->Get($this, StorageType::ROOT, '.cryptkey');
|
||||||
if ($sKey) {
|
|
||||||
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $oOldPass);
|
// Get the AppManager from the server container
|
||||||
if (!$sKey) {
|
$appManager = \OC::$server->getAppManager();
|
||||||
throw new ClientException(Notifications::CryptKeyError);
|
// Check if the OIDC Login app is enabled
|
||||||
}
|
$isEnabled = $appManager->isEnabledForUser('oidc_login');
|
||||||
$sKey = \SnappyMail\Crypt::EncryptToJSON($sKey, $this->IncPassword());
|
// If OIDC Login is enabled then we will assign $pwd instead of $this->IncPassword() and $pwd value is taken by following similar approach as https://github.com/the-djmaze/snappymail/blob/0db6c6ab5f9e05c46b13ebbdaf351341710438ac/plugins/login-gmail/index.php#L125
|
||||||
|
if ($isEnabled) {
|
||||||
|
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
$pwd = new \SnappyMail\SensitiveString($sUID);
|
||||||
if ($sKey) {
|
if ($sKey) {
|
||||||
$this->sCryptKey = null;
|
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $pwd);
|
||||||
if (\RainLoop\Api::Actions()->StorageProvider()->Put($this, StorageType::ROOT, '.cryptkey', $sKey)) {
|
if (!$sKey) {
|
||||||
return true;
|
throw new ClientException(Notifications::CryptKeyError);
|
||||||
|
}
|
||||||
|
$sKey = \SnappyMail\Crypt::EncryptToJSON($sKey, $pwd);
|
||||||
|
if ($sKey) {
|
||||||
|
$this->sCryptKey = null;
|
||||||
|
if (\RainLoop\Api::Actions()->StorageProvider()->Put($this, StorageType::ROOT, '.cryptkey', $sKey)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if ($sKey) {
|
||||||
|
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $oOldPass);
|
||||||
|
if (!$sKey) {
|
||||||
|
throw new ClientException(Notifications::CryptKeyError);
|
||||||
|
}
|
||||||
|
$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 false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,18 +63,43 @@ class MainAccount extends Account
|
||||||
// can use the old password to re-seal the cryptkey
|
// can use the old password to re-seal the cryptkey
|
||||||
$oStorage = \RainLoop\Api::Actions()->StorageProvider();
|
$oStorage = \RainLoop\Api::Actions()->StorageProvider();
|
||||||
$sKey = $oStorage->Get($this, StorageType::ROOT, '.cryptkey');
|
$sKey = $oStorage->Get($this, StorageType::ROOT, '.cryptkey');
|
||||||
if (!$sKey) {
|
|
||||||
$sKey = \SnappyMail\Crypt::EncryptToJSON(
|
// Get the AppManager from the server container
|
||||||
\sha1($this->IncPassword() . APP_SALT),
|
$appManager = \OC::$server->getAppManager();
|
||||||
$this->IncPassword()
|
// Check if the OIDC Login app is enabled
|
||||||
);
|
$isEnabled = $appManager->isEnabledForUser('oidc_login');
|
||||||
$oStorage->Put($this, StorageType::ROOT, '.cryptkey', $sKey);
|
// If OIDC Login app is enabled then we will assign $pwd instead of $this->IncPassword() and $pwd value is taken by following similar approach as https://github.com/the-djmaze/snappymail/blob/0db6c6ab5f9e05c46b13ebbdaf351341710438ac/plugins/login-gmail/index.php#L125
|
||||||
}
|
if ($isEnabled) {
|
||||||
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $this->IncPassword());
|
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
if (!$sKey) {
|
$pwd = new \SnappyMail\SensitiveString($sUID);
|
||||||
throw new ClientException(Notifications::CryptKeyError);
|
if (!$sKey) {
|
||||||
}
|
$sKey = \SnappyMail\Crypt::EncryptToJSON(
|
||||||
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
|
\sha1($pwd . APP_SALT),
|
||||||
|
$pwd
|
||||||
|
);
|
||||||
|
$oStorage->Put($this, StorageType::ROOT, '.cryptkey', $sKey);
|
||||||
|
}
|
||||||
|
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $pwd);
|
||||||
|
if (!$sKey) {
|
||||||
|
throw new ClientException(Notifications::CryptKeyError);
|
||||||
|
}
|
||||||
|
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!$sKey) {
|
||||||
|
$sKey = \SnappyMail\Crypt::EncryptToJSON(
|
||||||
|
\sha1($this->IncPassword() . APP_SALT),
|
||||||
|
$this->IncPassword()
|
||||||
|
);
|
||||||
|
$oStorage->Put($this, StorageType::ROOT, '.cryptkey', $sKey);
|
||||||
|
}
|
||||||
|
$sKey = \SnappyMail\Crypt::DecryptFromJSON($sKey, $this->IncPassword());
|
||||||
|
if (!$sKey) {
|
||||||
|
throw new ClientException(Notifications::CryptKeyError);
|
||||||
|
}
|
||||||
|
$this->sCryptKey = new SensitiveString(\hex2bin($sKey));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this->sCryptKey;
|
return $this->sCryptKey;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue