Improve solution #657

This commit is contained in:
the-djmaze 2022-11-13 10:27:30 +01:00
parent c74c6474a3
commit 01f26451d0
2 changed files with 4 additions and 4 deletions

View file

@ -41,7 +41,7 @@ class Application extends \RainLoop\Config\AbstractConfig
$sCipher = $this->Get('security', 'encrypt_cipher', '');
if (!$sCipher || !\SnappyMail\Crypt::cipherSupported($sCipher)) {
$sCipher && \SnappyMail\Log::warning('OpenSSL', "No support for {$sCipher}");
$sCipher && \SnappyMail\Log::warning('Crypt', "OpenSSL no support for cipher '{$sCipher}'");
$aCiphers = \SnappyMail\Crypt::listCiphers();
$this->Set('security', 'encrypt_cipher', $aCiphers[\array_rand($aCiphers)]);
$this->Save();

View file

@ -18,7 +18,6 @@ abstract class Crypt
$list = \array_diff($list, \array_map('strtoupper',$list));
$list = \array_filter($list, function($v){
// DES/ECB/bf/rc insecure, GCM/CCM not supported
// AEAD
return !\preg_match('/(^(des|bf|rc))|-(ecb|gcm|ccm|ocb|siv|cts)|wrap/i', $v);
});
\natcasesort($list);
@ -37,6 +36,7 @@ abstract class Crypt
static::$cipher = $cipher;
return true;
}
Log::error('Crypt', "OpenSSL no support for cipher '{$cipher}'");
return false;
}
@ -99,14 +99,14 @@ abstract class Crypt
$nonce = \random_bytes(\SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
return ['sodium', $nonce, static::SodiumEncrypt($data, $nonce, $key)];
} catch (\Throwable $e) {
Log::error('Sodium', $e->getMessage());
Log::error('Crypt', 'Sodium ' . $e->getMessage());
}
try {
$iv = \random_bytes(\openssl_cipher_iv_length(static::$cipher));
return ['openssl', $iv, static::OpenSSLEncrypt($data, $iv, $key)];
} catch (\Throwable $e) {
Log::error('OpenSSL', $e->getMessage());
Log::error('Crypt', 'OpenSSL ' . $e->getMessage());
}
$salt = \random_bytes(16);