? Pending

User tests: Successful: Unsuccessful:

avatar cheesegrits
cheesegrits
27 Dec 2017

Pull Request for Issue # .

Summary of Changes

Strip zero padding from plaintext response in OpenSSL decrypt, otherwise encrypting / decrypting is not symmetrical, unless the plain text was exactly the same as the OpenSSL block length. So encoding a plain text string, then decoding it, the decoded result will (most likely) not be "==" or "===" the plain text.

NOTE - the rtrim() is exactly what the com_users UserModel does when fetching the OTP ...

https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_users/Model/UserModel.php#L1061

... which I wish I'd known before spending an hour or so banging my head on this one. And seems to me like the rtrim() should just go in decrypt, and not be something that has to be applied to the returned value.

Testing Instructions

Insert this code at the bottom of ./index.php

$key = \JFactory::getConfig()->get('secret');
$aes = new Joomla\CMS\Encrypt\Aes($key, 256);
$plaintext = "this is a test, this is only a test, do not adjust your set";
$encrypted = $aes->encryptString($plaintext);
$decrypted = $aes->decryptString($encrypted);
if ($plaintext === $decrypted) {
	echo "YAY!";
}
else
{
	echo "WTAF?!?";
	var_dump($plaintext, $decrypted);
}

... then load the page.

Expected result

Expect result is "YAY!", my decrypted result === my plain text.

Actual result

Actual result is "WTAF?!?". My decrypted result was not === my plain text, because it got zero padded.

Apply the PR, and YAY!

Documentation Changes Required

None?

avatar cheesegrits cheesegrits - open - 27 Dec 2017
avatar cheesegrits cheesegrits - change - 27 Dec 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 27 Dec 2017
Category Libraries
avatar joomla-cms-bot joomla-cms-bot - edited - 27 Dec 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 27 Dec 2017
Title
Strip zero padding from openssl_decrypt response
[4.0] Strip zero padding from openssl_decrypt response
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 27 Dec 2017

Changed Title to "[4.0] ".


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19182.

avatar franz-wohlkoenig franz-wohlkoenig - test_item - 27 Dec 2017 - Tested successfully
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 27 Dec 2017

I have tested this item successfully on 215c370


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19182.

avatar laoneo
laoneo - comment - 10 Apr 2018

Now the rtrim in the UserModel is not needed anymore, can you remove that then please. Thanks.

@mbabker are you ok with the change?

avatar laoneo laoneo - change - 10 Apr 2018
Labels Added: ?
avatar laoneo laoneo - close - 21 Jul 2018
avatar laoneo laoneo - merge - 21 Jul 2018
avatar laoneo laoneo - change - 21 Jul 2018
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-07-21 09:17:10
Closed_By laoneo
avatar laoneo
laoneo - comment - 21 Jul 2018

Thanks.

Add a Comment

Login with GitHub to post a comment