Skip to content

Commit

Permalink
Improve solution #657
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Nov 13, 2022
1 parent c74c647 commit 01f2645
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function Load() : bool

$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();
Expand Down
6 changes: 3 additions & 3 deletions snappymail/v/0.0.0/app/libraries/snappymail/crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static function listCiphers() : array
$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);
Expand All @@ -37,6 +36,7 @@ public static function setCipher(string $cipher) : bool
static::$cipher = $cipher;
return true;
}
Log::error('Crypt', "OpenSSL no support for cipher '{$cipher}'");
return false;
}

Expand Down Expand Up @@ -99,14 +99,14 @@ public static function Encrypt($data, string $key = null) : array
$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);
Expand Down

0 comments on commit 01f2645

Please sign in to comment.