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

Crypt encrypt/ decrypt infinite loops #184

Open
piotr-cz opened this issue Jul 11, 2013 · 0 comments
Open

Crypt encrypt/ decrypt infinite loops #184

piotr-cz opened this issue Jul 11, 2013 · 0 comments
Labels

Comments

@piotr-cz
Copy link
Contributor

When public or private keys of Key are not set, Crypt->encrypt and Crypt->decrypt fall into infinite loops (tested with Cipher_Simple).

Example:

use Joomla\Crypt;

$key        = new Crypt\Key('simple');
// $key->public = 'omitted';
$crypt      = new Crypt\Crypt(new Crypt\Cipher_Simple, $key);

$secret     = $crypt->encrypt('Hello world');

Results in
Fatal error: Maximum execution time of 30 seconds exceeded in xxx\libraries\Joomla\Crypt\Cipher\Simple.php on line 86. Same with Cipher_Mcrypt.

I suggest checking the length of keys before calling Cipher type in Crypt like so:

public function encrypt($data)
{
    if (!strlen($key->public))
    {
        throw new \InvalidArgumentException('Public key not set.');
    }

    return $this->cipher->encrypt($data, $this->key);
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant