Remove the old unused \MailSo\Base\Crypt

This commit is contained in:
the-djmaze 2022-03-03 11:09:50 +01:00
parent 5bb190d974
commit 9f8854ae80
3 changed files with 21 additions and 74 deletions

View file

@ -1,43 +0,0 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Base;
/**
* @category MailSo
* @package Base
*/
class Crypt
{
public static function Encrypt(string $sString, string $sKey) : string
{
if (!\strlen($sString)) {
return '';
}
if (\is_callable('xxtea_encrypt')) {
return \xxtea_encrypt($sString, $sKey);
}
return Xxtea::encrypt($sString, $sKey);
}
public static function Decrypt(string $sString, string $sKey) : string
{
if (!\strlen($sString)) {
return '';
}
if (\is_callable('xxtea_decrypt')) {
return \xxtea_decrypt($sString, $sKey);
}
return Xxtea::decrypt($sString, $sKey);
}
}

View file

@ -27,26 +27,6 @@ class Utils
*/
SESSION_TOKEN = 'smsession';
public static function EncodeKeyValues(array $aValues, string $sCustomKey = '') : string
{
return \MailSo\Base\Utils::UrlSafeBase64Encode(
\MailSo\Base\Crypt::Encrypt(
\json_encode($aValues),
\md5(APP_SALT.$sCustomKey)
)
);
}
public static function DecodeKeyValues(string $sEncodedValues, string $sCustomKey = '') : array
{
return static::unserialize(
\MailSo\Base\Crypt::Decrypt(
\MailSo\Base\Utils::UrlSafeBase64Decode($sEncodedValues),
\md5(APP_SALT.$sCustomKey)
)
);
}
public static function EncodeKeyValuesQ(array $aValues, string $sCustomKey = '') : string
{
return \SnappyMail\Crypt::EncryptUrlSafe(
@ -63,15 +43,6 @@ class Utils
) ?: null;
}
public static function unserialize(string $sDecodedValues) : array
{
try {
return \json_decode($sDecodedValues, true, 512, JSON_THROW_ON_ERROR) ?: array();
} catch (\Throwable $e) {
return \unserialize($sDecodedValues) ?: array();
}
}
public static function GetSessionToken(bool $generate = true) : ?string
{
$sToken = static::GetCookie(self::SESSION_TOKEN, null);

View file

@ -83,7 +83,7 @@ abstract class Upgrade
\SnappyMail\Log::warning('UPGRADE', "ConvertInsecureAccount {$sEmail} no token");
continue;
}
$aAccountHash = \RainLoop\Utils::DecodeKeyValues($sToken);
$aAccountHash = static::DecodeKeyValues($sToken);
if (empty($aAccountHash[0]) || 'token' !== $aAccountHash[0] // simple token validation
|| 8 > \count($aAccountHash) // length checking
) {
@ -128,7 +128,7 @@ abstract class Upgrade
if (!empty($sData)) {
$aData = \json_decode($sData, true);
if (!$aData) {
$aData = \RainLoop\Utils::DecodeKeyValues($sData);
$aData = static::DecodeKeyValues($sData);
if ($aData) {
$oActions->setContactsSyncData($oAccount, $aData);
return array(
@ -143,4 +143,23 @@ abstract class Upgrade
return null;
}
/**
* Decodes old less secure data
*/
private static function DecodeKeyValues(string $sData, string $sCustomKey = '') : array
{
$sData = \MailSo\Base\Utils::UrlSafeBase64Decode($sData);
if (!\strlen($sData)) {
return '';
}
$sKey = \md5(APP_SALT . $sCustomKey);
$sData = \is_callable('xxtea_decrypt')
? \xxtea_decrypt($sData, $sKey)
: \MailSo\Base\Xxtea::decrypt($sData, $sKey);
try {
return \json_decode($sData, true, 512, JSON_THROW_ON_ERROR) ?: array();
} catch (\Throwable $e) {
return \unserialize($sData) ?: array();
}
}
}