public function testEncryption() { $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'encryptionKeyValue'; $encrypted = Tools::encrypt('my value'); $this->assertNotSame('my value', $encrypted, 'must be encrypted'); $decrypted = Tools::decrypt($encrypted); $this->assertSame('my value', $decrypted, 'must be original value'); }
/** * @test */ public function getSubstitutedConfigCustom() { $this->subject->setServer('pop.example.com'); $this->subject->setProtocol('pop'); $this->subject->setPort(123); $this->subject->setUsername('connor'); $this->subject->setPassword(\Ecodev\Newsletter\Tools::encrypt('skynet')); $config = 'server : ###SERVER### protocol: ###PROTOCOL### port : ###PORT### username: ###USERNAME### password: ###PASSWORD###'; $this->subject->setConfig(\Ecodev\Newsletter\Tools::encrypt($config)); $expected = 'server : pop.example.com protocol: pop port : 123 username: connor password: skynet'; $this->assertSame($expected, $this->subject->getSubstitutedConfig()); }
/** * Encrypts the field value * @param string $value The field value to be evaluated. * @param string $isIn The "isIn" value of the field configuration from TCA * @param bool $set defining if the value is written to the database or not. * @return string */ public function evaluateFieldValue($value, $isIn, &$set) { return \Ecodev\Newsletter\Tools::encrypt($value); }
/** * Encrypt old bounce account passwords and preserve old default config * * @return string[] */ private function getQueriesToEncryptOldBounceAccountPasswords() { // Fetch the old records - they will have a default port and an empty config. $rs = $this->databaseConnection->exec_SELECTquery('uid, password', 'tx_newsletter_domain_model_bounceaccount', 'port = 0 AND config = \'\''); $records = []; while ($record = $this->databaseConnection->sql_fetch_assoc($rs)) { $records[] = $record; } $this->databaseConnection->sql_free_result($rs); if (empty($records)) { return []; } // Keep the old config to not break old installations $config = Tools::encrypt("poll ###SERVER###\nproto ###PROTOCOL### \nusername \"###USERNAME###\"\npassword \"###PASSWORD###\"\n"); $queries = []; foreach ($records as $record) { $queries[] = $this->databaseConnection->UPDATEquery('tx_newsletter_domain_model_bounceaccount', 'uid=' . intval($record['uid']), ['password' => Tools::encrypt($record['password']), 'config' => $config]); } return ['Encrypt bounce account passwords' => $queries]; }
/** * Encrypt old bounce account passwords * * @global \TYPO3\CMS\Core\Database\DatabaseConnection $TYPO3_DB * @return string[] */ private static function getQueriesToEncryptOldBounceAccountPasswords() { // Prepare Queries // Keep the old config to not break old installations $config = Tools::encrypt("poll ###SERVER###\nproto ###PROTOCOL### \nusername \"###USERNAME###\"\npassword \"###PASSWORD###\"\n"); // Fetch and update the old records - they will have a default port and an empty config. global $TYPO3_DB; $rs = $TYPO3_DB->exec_SELECTquery('uid, password', 'tx_newsletter_domain_model_bounceaccount', 'port = 0 AND config = \'\''); while (($records[] = $TYPO3_DB->sql_fetch_assoc($rs)) || array_pop($records)) { } $TYPO3_DB->sql_free_result($rs); // Set Queries $queries = array(); if (!empty($records)) { foreach ($records as $row) { $queries[] = $TYPO3_DB->UPDATEquery('tx_newsletter_domain_model_bounceaccount', 'uid=' . intval($row['uid']), array('password' => Tools::encrypt($row['password']), 'config' => $config)); } } return $queries; }