|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-01-11 22:18 UTC] sergiuthepenguin at gmail dot com
Description: ------------ openssl_decrypt function doesn't appear to properly check authentication tag length. Not in all cases, at least. Run the script in your browser and hit refresh a few times. Test script: --------------- https://gist.github.com/SergiuThePenguin/55366527804b592ed86b29c8079b697a PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 13:00:01 2025 UTC |
Thanks for the shorter code. I can reproduce the issue with OpenSSL 1.0.2 and 1.1.0. The linked Ruby issue is actually same. Here's even a shorter reproducer $text = 'The quick brown fox jumps over the lazy dog.'; $key = random_bytes(32); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-gcm')); $cipherText = openssl_encrypt($text, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag, 'test-aad', 16); $ret = openssl_decrypt($cipherText, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag[0], 'test-aad'); var_dump($ret); This prints the decrypted text, more logic were IMO bool(false). I'd say it's definitely not a good behavior. In how far it is a security issue, is another question. An application should assert the correct tag length in first place. However, this behavior definitely increases the security risk due to programmer mistakes. The documentation states the tag length accepted by openssl_encrypt is between 4 and 16, however the below comes through with the tag length of 3 $cipherText = openssl_encrypt($text, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag, 'test-aad', 3); We need to discuss further how this should be fixed. Perhaps raising the default tag length could be a solution, something like to 12 bytes as a default for AES. This of course doesn't eliminate the need to check this in the application. Thanks.