Currently there is no way to tell when decryption has failed due to an incorrect encryption key. The decrypt method returns random binary data in such cases. I believe it's critical that developers using this module be able to detect and react properly when the decryption fails.

The attached patch adds an HMAC option to the Mcrypt encryption method. When a failure is detected based on the HMAC, the decrypt method returns FALSE. Please consider for inclusion.

CommentFileSizeAuthor
#2 enable-hmac-2576541-1.patch5.52 KBglekli
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gergely Lekli created an issue. See original summary.

glekli’s picture

FileSize
5.52 KB
greggles’s picture

Thanks for the idea and the patch.

Is this different from what https://www.drupal.org/project/real_aes provides?

rlhawk’s picture

The Real AES module uses OpenSSL, instead of the antiquated Mcrypt, and it's what I'd recommend as the best, and most secure, encryption option. It uses the Defuse library (https://github.com/defuse/php-encryption), which is fantastic.

I'm working on improving the Mcrypt plugin for Encrypt and adding HMAC to the improvements is probably a good idea, but I'd steer people to Real AES anyway.

glekli’s picture

It seems like that module could provide similar functionality. Nevertheless, I was going to say the same as rlhawk: this module would benefit from it as well.

greggles’s picture

I think there is a general goal of merging the Real AES code into this module and deprecating or downplaying the encryption method in this module, no?

rlhawk’s picture

Yes, that's what I'd prefer to do for Encrypt 3.x. We should not be writing our own encryption methods, but should instead use a solid, well-written, modern library like Defuse. See this post for more info.

In the meantime, we should certainly improve the Mcrypt encryption method, since it's included with Encrypt 2.x.

rlhawk’s picture

Status: Needs review » Fixed

HMAC authentication is a feature of the new Mcrypt AES (CBC Mode) encryption method, introduced in Encrypt 7.x-2.2. I'm marking this issue as fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.