None of the JCrypt implementations are properly authenticating the ciphertext. As a result, an active attacker can flip bits at will until they get a useful result. Combine the CCA with #8328 and you get a nice padding oracle attack against the Rijndael256-CBC encryption.
Further reading:
TL;DR Encrypt then MAC. See how defuse/php-encryption implements its encryption and authentication. (In fact, I highly recommend switching to that and exercising liberal use of your delete key on the existing cryptography code.)
@paragonie-scott Would you be able to provide a mergeable pull request with the changes you are proposing please? Code speaks louder than comments :-)
You won't like my pull request here.
Unfortunately the php-encryption library requires PHP 5.4 while we're still in 5.3.10+ world (ya, shoot us ;-) ). So that's not much of an option.
Labels |
Added:
?
|
Category | ⇒ | Libraries |
@joomla/security Some help on this issue would be appreciated. I'm in over my head on this.
I only have very limited knowledge on crypto, not really sure how to help with this :(
You could reference what defuse/php-encryption v1.1 did (or, even better, just use that library outright). It uses mcrypt and supports PHP 5.3.
To prevent a chosen ciphertext attack:
$eKey
and $aKey
. HKDF-SHA-256 can do this safely (Defuse's library includes an implementation).$eKey
(and preferably with a 16-byte random IV from random_bytes()
, provided by random_compat).When decrypting an encrypted message:
$eKey
and $aKey
again.$aKey
.hash_equals()
) that the MAC provided with the message is equal to the one you just recalcualted. If it fails, throw an exception. (If the user fails to handle the exception, it must terminate execution.)$eKey
.This also resolves the data corruption by trim()
issue. But seriously, use the version 1.1 tag of defuse/php-encryption instead of writing your own. When you can support modern PHP (5.6+ or, by the time that comes up, likely 7.x+), you can just change the version requirements for Defuse's library to 1.2 or 2.0.
cc @defuse who can agree/disagree with whether using 1.1 of his library is a good idea or not. (I rewrote it to leverage OpenSSL for 1.2, which introduced the 5.4+ requirement.)
That said, PR incomin'
That said, PR incomin
Awesome, thanks a lot!
I think we can remove the no-code-attached label now ;)
I'm going to close this issue so that the discussion can continue on the Pull Request :)
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-11-13 18:39:39 |
Closed_By | ⇒ | wilsonge |
Update: It appears that the IV is a static value rather than a per-message random value. This sort of defeats the entire purpose of using CBC mode.