Skip to content

Commit

Permalink
fixes #445 Encrypt connection passwords - you will need to edit and s…
Browse files Browse the repository at this point in the history
…ave connections to update to encrypted versions of passwords
  • Loading branch information
pollen8 committed Feb 19, 2013
1 parent 6f905e6 commit dcdffe2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions administrator/components/com_fabrik/models/connection.php
Expand Up @@ -168,6 +168,13 @@ public function save($data)
$session = JFactory::getSession();
$model = JModelLegacy::getInstance('Connection', 'FabrikFEModel');
$model->setId($data['id']);
$crypt = FabrikWorker::getCrypt();

$params = new stdClass;
$params->encryptedPw = true;
$data['params'] = json_encode($params);
$data['password'] = $crypt->encrypt($data['password']);

$options = $model->getConnectionOptions(JArrayHelper::toObject($data));
$db = JDatabase::getInstance($options);
if (JError::isError($db))
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_fabrik/models/list.php
Expand Up @@ -574,7 +574,7 @@ public function save($data)
$date = JFactory::getDate();
$row = $this->getTable();

$id = $data['id'];
$id = JArrayHelper::getValue($data, 'id');
$row->load($id);

$params = new JRegistry($row->params);
Expand Down
32 changes: 32 additions & 0 deletions components/com_fabrik/models/connection.php
Expand Up @@ -136,6 +136,31 @@ public function getTableDdForThisConnection($javascript = '', $name = 'table_joi
return JHTML::_('select.genericlist', $tableOptions, $name, $options, 'value', 'text', $selected);
}

/**
* Decrypt once a connection password - if its params->encryptedPw option is true
*
* @param JTable &$cnn Connection
*
* @since 3.1rc1
*
* @return void
*/

protected function decryptPw(&$cnn)
{
if (isset($cnn->decrypted) && $cnn->decrypted)
{
return;
}
$crypt = FabrikWorker::getCrypt();
$params = json_decode($cnn->params);
if (is_object($params) && $params->encryptedPw == true)
{
$cnn->password = $crypt->decrypt($cnn->password);
$cnn->decrypted = true;
}
}

/**
* Get a connection table object
*
Expand Down Expand Up @@ -167,6 +192,7 @@ public function &getConnection($id = null)
{
$this->connection = FabTable::getInstance('connection', 'FabrikTable');
$this->connection->bind($connProperties);
$this->decryptPw($this->connection);
return $this->connection;
}

Expand All @@ -183,6 +209,7 @@ public function &getConnection($id = null)
// $$$ rob store the connection for later use as it may be required by modules/plugins
$session->set($key, serialize($this->connection->getProperties()));
}
$this->decryptPw($this->connection);
return $this->connection;
}

Expand Down Expand Up @@ -349,6 +376,10 @@ public function getConnections()
$query->select('*, id AS value, description AS text')->from('#__fabrik_connections')->where('published = 1');
$db->setQuery($query);
$connections = $db->loadObjectList();
foreach ($connections as &$cnn)
{
$this->decryptPw($cnn);
}
return $connections;
}

Expand Down Expand Up @@ -529,6 +560,7 @@ public function &loadDefaultConnection()
// jos_fabrik_connections and not jos_{package}_connections
$row = FabTable::getInstance('Connection', 'FabrikTable');
$row->load(array('default' => 1));
$this->decryptPw($row);
$this->defaultConnection = $row;
}
$this->connection = $this->defaultConnection;
Expand Down

0 comments on commit dcdffe2

Please sign in to comment.