Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Moved the encryption logic from the DataContainer to the Widget class (
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed May 26, 2011
1 parent 3df566b commit f786f79
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -14,6 +14,7 @@ Version 2.10.beta1 (XXXX-XX-XX)
- Changed: make "email" a unique field for users and members (#2493)
- Changed: do not show subpages if the website root page is not public (#2425)
- Changed: make the ellipsis string of the String class configurable (#2700)
- Changed: moved the encryption logic from the DataContainer to the Widget class (#2603)
- Improved: optimized the back end page speed (#2400)
- Improved: added CSS and JS combining to the back end front end
- Improved: standardized event and newsletter templates (#2889)
Expand Down
30 changes: 30 additions & 0 deletions system/drivers/DC_Table.php
Expand Up @@ -3041,6 +3041,15 @@ protected function generateTree($table, $id, $arrPrevNext, $blnHasSorting, $intM

foreach ($showFields as $k=>$v)
{
// Decrypt the value
if ($GLOBALS['TL_DCA'][$table]['fields'][$v]['eval']['encrypt'])
{
$objRow->$v = deserialize($objRow->$v);

$this->import('Encryption');
$objRow->$v = $this->Encryption->decrypt($objRow->$v);
}

if (strpos($v, ':') !== false)
{
list($strKey, $strTable) = explode(':', $v);
Expand Down Expand Up @@ -3428,6 +3437,18 @@ protected function parentView()
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][1], $row[$i]['id']), 'class="blink"');
$imagePasteNew = $this->generateImage('new.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pastenew'][1], $row[$i]['id']));

// Decrypt encrypted value
foreach ($row[$i] as $k=>$v)
{
if ($GLOBALS['TL_DCA'][$table]['fields'][$k]['eval']['encrypt'])
{
$v = deserialize($v);

$this->import('Encryption');
$row[$i][$k] = $this->Encryption->decrypt($v);
}
}

// Make items sortable
if ($blnHasSorting)
{
Expand Down Expand Up @@ -3708,6 +3729,15 @@ protected function listView()
// Label
foreach ($showFields as $k=>$v)
{
// Decrypt the value
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['encrypt'])
{
$row[$v] = deserialize($row[$v]);

$this->import('Encryption');
$row[$v] = $this->Encryption->decrypt($row[$v]);
}

if (strpos($v, ':') !== false)
{
list($strKey, $strTable) = explode(':', $v);
Expand Down
48 changes: 34 additions & 14 deletions system/libraries/Encryption.php
Expand Up @@ -97,20 +97,30 @@ public static function getInstance()
* @param mixed
* @return string
*/
public function encrypt($strValue)
public function encrypt($varValue)
{
if ($strValue == '')
// Recursively encrypt arrays
if (is_array($varValue))
{
foreach ($varValue as $k=>$v)
{
$varValue[$k] = $this->encrypt($v);
}

return $varValue;
}

if ($varValue == '')
{
return '';
}

$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->resTd), MCRYPT_RAND);
mcrypt_generic_init($this->resTd, md5($GLOBALS['TL_CONFIG']['encryptionKey']), $iv);

$strEncrypted = mcrypt_generic($this->resTd, $strValue);
$strEncrypted = mcrypt_generic($this->resTd, $varValue);
$strEncrypted = base64_encode($iv.$strEncrypted);

mcrypt_generic_deinit($this->resTd);

return $strEncrypted;
}

Expand All @@ -120,28 +130,38 @@ public function encrypt($strValue)
* @param mixed
* @return string
*/
public function decrypt($strValue)
public function decrypt($varValue)
{
if ($strValue == '')
// Recursively decrypt arrays
if (is_array($varValue))
{
return '';
foreach ($varValue as $k=>$v)
{
$varValue[$k] = $this->decrypt($v);
}

return $varValue;
}

$strValue = base64_decode($strValue);
if ($varValue == '')
{
return '';
}

$varValue = base64_decode($varValue);
$ivsize = mcrypt_enc_get_iv_size($this->resTd);
$iv = substr($strValue, 0, $ivsize);
$strValue = substr($strValue, $ivsize);
$iv = substr($varValue, 0, $ivsize);
$varValue = substr($varValue, $ivsize);

if ($strValue == '')
if ($varValue == '')
{
return '';
}

mcrypt_generic_init($this->resTd, md5($GLOBALS['TL_CONFIG']['encryptionKey']), $iv);
$strDecrypted = mdecrypt_generic($this->resTd, $strValue);

$strDecrypted = mdecrypt_generic($this->resTd, $varValue);
mcrypt_generic_deinit($this->resTd);

return $strDecrypted;
}
}
Expand Down
14 changes: 13 additions & 1 deletion system/libraries/Widget.php
Expand Up @@ -168,7 +168,13 @@ public function __set($strKey, $varValue)
break;

case 'value':
$this->varValue = $varValue;
// Decrypt the value if it is encrypted
$this->varValue = deserialize($varValue);
if ($this->arrConfiguration['encrypt'])
{
$this->import('Encryption');
$this->varValue = $this->Encryption->decrypt($this->varValue);
}
break;

case 'class':
Expand Down Expand Up @@ -253,6 +259,12 @@ public function __get($strKey)
break;

case 'value':
// Encrypt the value
if ($this->arrConfiguration['encrypt'])
{
$this->import('Encryption');
return $this->Encryption->encrypt($this->varValue);
}
return $this->varValue;
break;

Expand Down
13 changes: 0 additions & 13 deletions system/modules/backend/DataContainer.php
Expand Up @@ -199,13 +199,6 @@ protected function row()
$xlabel .= ' <a href="' . $this->addToUrl('key=list') . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_import'][1]) . '" onclick="Backend.getScrollOffset();">' . $this->generateImage('tablewizard.gif', $GLOBALS['TL_LANG']['MSC']['tw_import'][0], 'style="vertical-align:text-bottom;"') . '</a>';
}

// Decrypt the value if it is encrypted
if ($arrData['eval']['encrypt'])
{
$this->import('Encryption');
$this->varValue = $this->Encryption->decrypt($this->varValue);
}

// Input field callback
if (is_array($arrData['input_field_callback']))
{
Expand Down Expand Up @@ -278,12 +271,6 @@ protected function row()
$varValue = serialize($varValue);
}

// Encrypt the value
if ($arrData['eval']['encrypt'])
{
$varValue = $this->Encryption->encrypt($varValue);
}

// Save the current value
try
{
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/ImageSize.php
Expand Up @@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/InputUnit.php
Expand Up @@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/ListWizard.php
Expand Up @@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/ModuleWizard.php
Expand Up @@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/OptionWizard.php
Expand Up @@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/TableWizard.php
Expand Up @@ -74,10 +74,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'rows':
$this->intRows = $varValue;
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/TextField.php
Expand Up @@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/TimePeriod.php
Expand Up @@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
Expand Down
4 changes: 0 additions & 4 deletions system/modules/backend/TrblField.php
Expand Up @@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'value':
$this->varValue = deserialize($varValue);
break;

case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
Expand Down
9 changes: 9 additions & 0 deletions system/tmp/autoload.csv
Expand Up @@ -83,3 +83,12 @@
"BackendModule","system/modules/backend/BackendModule.php"
"RepositoryBackendModule","system/modules/rep_client/RepositoryBackendModule.php"
"DatabaseInstaller","system/modules/rep_client/DatabaseInstaller.php"
"Newsletter","system/modules/newsletter/Newsletter.php"
"Password","system/modules/backend/Password.php"
"Encryption","system/libraries/Encryption.php"
"ContentAlias","system/modules/frontend/ContentAlias.php"
"FileTree","system/modules/backend/FileTree.php"
"ImageSize","system/modules/backend/ImageSize.php"
"TrblField","system/modules/backend/TrblField.php"
"RadioTable","system/modules/backend/RadioTable.php"
"RadioButton","system/modules/backend/RadioButton.php"
1 change: 1 addition & 0 deletions system/tmp/classes.csv
Expand Up @@ -29,3 +29,4 @@
"ModuleFaqList","1"
"ModuleSearch","1"
"RepositoryManager","1"
"ContentAlias","1"
9 changes: 6 additions & 3 deletions system/tmp/templates.csv
Expand Up @@ -37,15 +37,18 @@
"mod_faqlist.html5","system/modules/faq/templates/mod_faqlist.html5"
"mod_search_advanced.html5","system/modules/frontend/templates/mod_search_advanced.html5"
"mod_search.html5","system/modules/frontend/templates/mod_search.html5"
"ce_headline.html5","system/modules/frontend/templates/ce_headline.html5"
"ce_accordion.html5","system/modules/frontend/templates/ce_accordion.html5"
"ce_text.html5","system/modules/frontend/templates/ce_text.html5"
"search_default.html5","system/modules/frontend/templates/search_default.html5"
"be_preview.html5","system/modules/backend/templates/be_preview.html5"
"mod_logout_1cl.html5","system/modules/frontend/templates/mod_logout_1cl.html5"
"be_switch.html5","system/modules/backend/templates/be_switch.html5"
"repository_mgrlist.html5","system/modules/rep_client/templates/repository_mgrlist.html5"
"repository_mgrupdt.html5","system/modules/rep_client/templates/repository_mgrupdt.html5"
"be_login.html5","system/modules/backend/templates/be_login.html5"
"be_widget_pw.html5","system/modules/backend/templates/be_widget_pw.html5"
"ce_headline.html5","system/modules/frontend/templates/ce_headline.html5"
"ce_accordion.html5","system/modules/frontend/templates/ce_accordion.html5"
"ce_text.html5","system/modules/frontend/templates/ce_text.html5"
"be_widget_rdo.html5","system/modules/backend/templates/be_widget_rdo.html5"
"be_widget_chk.html5","system/modules/backend/templates/be_widget_chk.html5"
"be_widget.html5","system/modules/backend/templates/be_widget.html5"
"be_main.html5","system/modules/backend/templates/be_main.html5"

0 comments on commit f786f79

Please sign in to comment.