<commit_before><?php

class EnvCrypt
{
    protected static function getKey()
    {
        global $sugar_config;

        // populate default key as a file system based blowfish
        $result = blowfishGetKey('custom_encrypt');

        if(empty($sugar_config['dbconfig']['filesystem_encryption_only'])) {
            if (false !== getenv('sugar_blowfish_key')) {
                $key = getenv('sugar_blowfish_key');
                if (strlen($key) > 56 || strlen($key) < 4) {
                    $GLOBALS['log']->security("Retrieved encryption key from ENV variable 'sugar_blowfish_key'. It's  " . strlen($key)
                            . " chars long but should be more than 4 chars but less than 56 chars long (32 to 448 bits).");
                } else {
                    $result = getenv('sugar_blowfish_key');
                }
            } else {
                $GLOBALS['log']->security("Could not retrieve encryption key from ENV variable 'sugar_blowfish_key'. Will use the file system based one. To suppress this security message and leverage only file system based blowfish encryption set on config_override.php \$sugar_config['dbconfig']['filesystem_encryption_only'] = true;");
            }
        }
<commit_msg>Improvements on retrieving blowfish key only once and logging<commit_after><?php

class EnvCrypt
{
    protected static function getKey()
    {
        global $sugar_config;

        // populate default key as a file system based blowfish
        $result = blowfishGetKey('custom_encrypt');

        if(empty($sugar_config['dbconfig']['filesystem_encryption_only'])) {
            $key = getenv('sugar_blowfish_key');
            if ($key !== false) {
                if (strlen($key) > 56 || strlen($key) < 4) {
                    $GLOBALS['log']->security("Retrieved encryption key from ENV variable 'sugar_blowfish_key'. It's  " . strlen($key)
                            . " chars long but should be between 4 and 56 chars long (32 to 448 bits). Will use the file system based one.");
                } else {
                    $result = $key;
                }
            } else {
                $GLOBALS['log']->security("Could not retrieve encryption key from ENV variable 'sugar_blowfish_key'. Will use the file system based one. To suppress this security message and leverage only file system based blowfish encryption set on config_override.php \$sugar_config['dbconfig']['filesystem_encryption_only'] = true;");
            }
        }

{'fraction_non_alphanumeric': 0.10481927710843374, 'fraction_numerical': 0.008835341365461847, 'mean_word_length': 2.3257676902536715, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1448305', 'n_tokens_mistral': 698, 'n_tokens_neox': 639, 'n_words': 205}