Add option to configure the encryption algorithm in Extension Manager
authorstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 13 Feb 2013 15:52:04 +0000 (15:52 +0000)
committerstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 13 Feb 2013 15:52:04 +0000 (15:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/sr_freecap/trunk@71175 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
Classes/Configuration/ConfigurationHelper.php [new file with mode: 0644]
Classes/Utility/EncryptionUtility.php
doc/manual.sxw
ext_autoload.php
ext_conf_template.txt [new file with mode: 0644]
ext_localconf.php

index 1cc9670..8e87ef6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-02-13  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Add option to configure the encryption algorithm in Extension Manager
+
 2013-02-12  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Cleanup audio file rendering
diff --git a/Classes/Configuration/ConfigurationHelper.php b/Classes/Configuration/ConfigurationHelper.php
new file mode 100644 (file)
index 0000000..1ea8ba8
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+namespace SJBR\SrFreecap\Configuration;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Class providing configuration help for extension SrFreecap
+ */
+class ConfigurationHelper {
+
+       /**
+        * Renders a select element that allows to choose the encryption algoritm to be used by the extension
+        *
+        * @param array $params: Field information to be rendered
+        * @param \TYPO3\CMS\Extensionmanager\ViewHelpers\Form\TypoScriptConstantsViewHelper $pObj: The calling parent object.
+        * @return string The HTML select field
+        */
+       public function buildEncryptionAlgorithmSelector (array $params, \TYPO3\CMS\Extensionmanager\ViewHelpers\Form\TypoScriptConstantsViewHelper $pObj) {
+               if (in_array('mcrypt', get_loaded_extensions())) {
+                       $encryptionAlgorithms = mcrypt_list_algorithms();
+                       if (!empty($encryptionAlgorithms)) {
+                               $field = '<br /><select id="' . $params['propertyName'] . '" name="' . $params['fieldName'] . '" />' . LF;
+                               foreach ($encryptionAlgorithms as $encryptionAlgorithm) {
+                                       $selected = $params['fieldValue'] == $encryptionAlgorithm ? 'selected="selected"' : '';
+                                       $field .= '<option name="' . $encryptionAlgorithm . '" value="' . $encryptionAlgorithm . '" ' . $selected . '>' . $encryptionAlgorithm . '</option>' . LF;
+                               }
+                               $field .= '</select><br /><br />' . LF;
+                       } else {
+                               $field = '<br />Available encryption algorithms could not be found. Algorithm blowfish will be used.<br />';
+                       }
+               } else {
+                       $field = '<br />PHP mcrypt extension is not available.<br />';
+               }
+               return $field;
+       }
+}
+?>
\ No newline at end of file
index 2f1fa6d..44cd631 100644 (file)
@@ -41,10 +41,16 @@ class EncryptionUtility {
         */
        public static function encrypt($string) {
                if (in_array('mcrypt', get_loaded_extensions())) {
-                       $key = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
-                       $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC), MCRYPT_RAND);
-                       $string = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $string, MCRYPT_MODE_CBC, $iv);
-                       $cypher = array(base64_encode($string), base64_encode($iv));
+                       $module = mcrypt_module_open($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['encryptionAlgorithm'], '', MCRYPT_MODE_CBC, '');
+                       if ($module !== FALSE) {
+                               $key = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
+                               $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_RAND);
+                               $string = mcrypt_encrypt($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['encryptionAlgorithm'], $key, $string, MCRYPT_MODE_CBC, $iv);
+                               $cypher = array(base64_encode($string), base64_encode($iv));
+                               mcrypt_module_close($module);
+                       } else {
+                               $cypher = array(base64_encode($string));
+                       }
                } else {
                        $cypher = array(base64_encode($string));                        
                }
@@ -61,7 +67,7 @@ class EncryptionUtility {
        public static function decrypt ($cypher){
                if (in_array('mcrypt', get_loaded_extensions())) {
                        $key = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
-                       $string = trim(mcrypt_decrypt(MCRYPT_BLOWFISH, $key, base64_decode($cypher[0]), MCRYPT_MODE_CBC, base64_decode($cypher[1])));
+                       $string = trim(mcrypt_decrypt($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['encryptionAlgorithm'], $key, base64_decode($cypher[0]), MCRYPT_MODE_CBC, base64_decode($cypher[1])));
                } else {
                        $string = base64_decode($cypher[0]);
                }
index 0e22e21..48e309a 100644 (file)
Binary files a/doc/manual.sxw and b/doc/manual.sxw differ
index 5de3468..e7ae65c 100644 (file)
@@ -2,6 +2,7 @@
 $extensionPath = t3lib_extMgm::extPath('sr_freecap');
 $extensionClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('sr_freecap') . 'Classes/';
 return array(
+       'SJBR\SrFreecap\Configuration\ConfigurationHelper' => $extensionClassesPath . 'Configuration/ConfigurationHelper.php',
        'SJBR\SrFreecap\Controller\AudioPlayerController' => $extensionClassesPath . 'Controller/AudioPlayerController.php',
        'SJBR\SrFreecap\Controller\FontMakerController' => $extensionClassesPath . 'Controller/FontMakerController.php',
        'SJBR\SrFreecap\Controller\ImageGeneratorController' => $extensionClassesPath . 'Controller/ImageGeneratorController.php',
diff --git a/ext_conf_template.txt b/ext_conf_template.txt
new file mode 100644 (file)
index 0000000..6579e03
--- /dev/null
@@ -0,0 +1,3 @@
+
+  # cat=basic; type=# cat=basic; type=user[SJBR\SrFreecap\Configuration\ConfigurationHelper->buildEncryptionAlgorithmSelector]; label=Encryption Algorithm: Select the encryption algorithm to be used by the extension.
+encryptionAlgorithm = blowfish
index 214c332..c1fdb3e 100644 (file)
@@ -2,6 +2,12 @@
 if (!defined('TYPO3_MODE')) {
        die('Access denied.');
 }
+// Unserializing the configuration so we can use it here
+$_EXTCONF = unserialize($_EXTCONF);
+
+// Setting the encryption algorithm
+$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['encryptionAlgorithm'] = isset($_EXTCONF['encryptionAlgorithm']) ? $_EXTCONF['encryptionAlgorithm'] : 'blowfish';
+
 // Dispatching requests to image generator and audio player
 $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['sr_freecap_EidDispatcher'] = 'EXT:' . $_EXTKEY . '/Resources/Private/Eid/EidDispatcher.php';