Skip to content

Commit

Permalink
Move FOFEncrypt to Joomla namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Aug 23, 2017
1 parent e639049 commit bfd5bf2
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 182 deletions.
9 changes: 5 additions & 4 deletions administrator/components/com_users/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Access\Access;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Encrypt\Aes;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;
use Joomla\CMS\Model\Admin;
Expand Down Expand Up @@ -1018,8 +1019,8 @@ public function getOtpConfig($user_id = null)

if (strpos($config, '{') === false)
{
$openssl = new \FOFEncryptAes($key, 256);
$mcrypt = new \FOFEncryptAes($key, 256, 'cbc', null, 'mcrypt');
$openssl = new Aes($key, 256);
$mcrypt = new Aes($key, 256, 'cbc', null, 'mcrypt');

$decryptedConfig = $mcrypt->decryptString($config);

Expand Down Expand Up @@ -1051,7 +1052,7 @@ public function getOtpConfig($user_id = null)
}

// Create an encryptor class
$aes = new \FOFEncryptAes($key, 256);
$aes = new Aes($key, 256);

// Decrypt the data
$decryptedOtep = $aes->decryptString($encryptedOtep);
Expand Down Expand Up @@ -1118,7 +1119,7 @@ public function setOtpConfig($user_id, $otpConfig)

// Create an encryptor class
$key = $this->getOtpConfigEncryptionKey();
$aes = new \FOFEncryptAes($key, 256);
$aes = new Aes($key, 256);

// Create the encrypted option strings
if (!empty($otpConfig->method) && ($otpConfig->method != 'none'))
Expand Down
22 changes: 0 additions & 22 deletions libraries/fof/encrypt/randvalinterface.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage utils
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
namespace Joomla\CMS\Encrypt\AES;

defined('JPATH_PLATFORM') or die;

/**
* Abstract AES encryption class
*/
abstract class FOFEncryptAesAbstract
abstract class AbstractAES
{
/**
* Trims or zero-pads a key / IV
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage utils
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
namespace Joomla\CMS\Encrypt\AES;

defined('JPATH_PLATFORM') or die;

/**
* Interface for AES encryption adapters
*/
interface FOFEncryptAesInterface
interface AesInterface
{
/**
* Sets the AES encryption mode.
Expand Down Expand Up @@ -75,9 +76,7 @@ public function getBlockSize();
/**
* Is this adapter supported?
*
* @param FOFUtilsPhpfunc $phpfunc
*
* @return bool
*/
public function isSupported(FOFUtilsPhpfunc $phpfunc = null);
public function isSupported();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage utils
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
namespace Joomla\CMS\Encrypt\AES;

class FOFEncryptAesMcrypt extends FOFEncryptAesAbstract implements FOFEncryptAesInterface
use Joomla\CMS\Encrypt\Randval;

defined('JPATH_PLATFORM') or die;

class Mcrypt extends AbstractAES implements AesInterface
{
protected $cipherType = MCRYPT_RIJNDAEL_128;

Expand Down Expand Up @@ -55,7 +58,7 @@ public function encrypt($plainText, $key, $iv = null)

if (empty($iv))
{
$randVal = new FOFEncryptRandval();
$randVal = new Randval;
$iv = $randVal->generate($iv_size);
}

Expand All @@ -76,54 +79,49 @@ public function decrypt($cipherText, $key)
return $plainText;
}

public function isSupported(FOFUtilsPhpfunc $phpfunc = null)
public function isSupported()
{
if (!is_object($phpfunc) || !($phpfunc instanceof $phpfunc))
{
$phpfunc = new FOFUtilsPhpfunc();
}

if (!$phpfunc->function_exists('mcrypt_get_key_size'))
if (!function_exists('mcrypt_get_key_size'))
{
return false;
}

if (!$phpfunc->function_exists('mcrypt_get_iv_size'))
if (!function_exists('mcrypt_get_iv_size'))
{
return false;
}

if (!$phpfunc->function_exists('mcrypt_create_iv'))
if (!function_exists('mcrypt_create_iv'))
{
return false;
}

if (!$phpfunc->function_exists('mcrypt_encrypt'))
if (!function_exists('mcrypt_encrypt'))
{
return false;
}

if (!$phpfunc->function_exists('mcrypt_decrypt'))
if (!function_exists('mcrypt_decrypt'))
{
return false;
}

if (!$phpfunc->function_exists('mcrypt_list_algorithms'))
if (!function_exists('mcrypt_list_algorithms'))
{
return false;
}

if (!$phpfunc->function_exists('hash'))
if (!function_exists('hash'))
{
return false;
}

if (!$phpfunc->function_exists('hash_algos'))
if (!function_exists('hash_algos'))
{
return false;
}

$algorightms = $phpfunc->mcrypt_list_algorithms();
$algorightms = mcrypt_list_algorithms();

if (!in_array('rijndael-128', $algorightms))
{
Expand All @@ -140,7 +138,7 @@ public function isSupported(FOFUtilsPhpfunc $phpfunc = null)
return false;
}

$algorightms = $phpfunc->hash_algos();
$algorightms = hash_algos();

if (!in_array('sha256', $algorightms))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage utils
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
namespace Joomla\CMS\Encrypt\AES;

class FOFEncryptAesOpenssl extends FOFEncryptAesAbstract implements FOFEncryptAesInterface
use Joomla\CMS\Encrypt\Randval;

defined('JPATH_PLATFORM') or die;

class Openssl extends AbstractAES implements AesInterface
{
/**
* The OpenSSL options for encryption / decryption
Expand Down Expand Up @@ -81,7 +84,7 @@ public function encrypt($plainText, $key, $iv = null)

if (empty($iv))
{
$randVal = new FOFEncryptRandval();
$randVal = new Randval;
$iv = $randVal->generate($iv_size);
}

Expand All @@ -103,56 +106,51 @@ public function decrypt($cipherText, $key)
return $plainText;
}

public function isSupported(FOFUtilsPhpfunc $phpfunc = null)
public function isSupported()
{
if (!is_object($phpfunc) || !($phpfunc instanceof $phpfunc))
{
$phpfunc = new FOFUtilsPhpfunc();
}

if (!$phpfunc->function_exists('openssl_get_cipher_methods'))
if (!function_exists('openssl_get_cipher_methods'))
{
return false;
}

if (!$phpfunc->function_exists('openssl_random_pseudo_bytes'))
if (!function_exists('openssl_random_pseudo_bytes'))
{
return false;
}

if (!$phpfunc->function_exists('openssl_cipher_iv_length'))
if (!function_exists('openssl_cipher_iv_length'))
{
return false;
}

if (!$phpfunc->function_exists('openssl_encrypt'))
if (!function_exists('openssl_encrypt'))
{
return false;
}

if (!$phpfunc->function_exists('openssl_decrypt'))
if (!function_exists('openssl_decrypt'))
{
return false;
}

if (!$phpfunc->function_exists('hash'))
if (!function_exists('hash'))
{
return false;
}

if (!$phpfunc->function_exists('hash_algos'))
if (!function_exists('hash_algos'))
{
return false;
}

$algorightms = $phpfunc->openssl_get_cipher_methods();
$algorightms = openssl_get_cipher_methods();

if (!in_array('aes-128-cbc', $algorightms))
{
return false;
}

$algorightms = $phpfunc->hash_algos();
$algorightms = hash_algos();

if (!in_array('sha256', $algorightms))
{
Expand Down

0 comments on commit bfd5bf2

Please sign in to comment.