OpenSSL AES-256-CBC: No Longer Decrypts Secrets as of Early 2022
In March 2022, it was discovered that encrypted secrets saved in a text file using OpenSSL's AES-256-CBC encryption were no longer decryptable. This article will cover the key concepts surrounding this issue and provide detailed context on the topic.
Background
OpenSSL is a widely-used open-source implementation of the SSL and TLS protocols. It is commonly used for secure communication over the internet and for encrypting sensitive data. AES-256-CBC is a block cipher mode that is widely considered to be very secure. However, as of early 2022, it was discovered that encrypted secrets saved using this method were no longer decryptable.
The Problem
The problem was first discovered when users were unable to decrypt secrets that had been encrypted using OpenSSL's AES-256-CBC encryption. The issue was traced back to a change in the OpenSSL library that occurred in early 2022. This change caused the decryption process to fail, leaving users unable to access their encrypted secrets.
Technical Details
The root cause of the problem is a bug in the OpenSSL library that affects the decryption process when using AES-256-CBC. The bug is related to the way that the encryption key is generated and stored. Specifically, the bug affects the way that the encryption key is derived from the password provided by the user. This bug causes the decryption process to fail, leaving the encrypted secrets inaccessible.
$ echo "mysecret" | openssl enc -aes-256-cbc -a -salt -k $mypassword
saved result. worked fine...
# later, when trying to decrypt
$ openssl enc -d -aes-256-cbc -a -salt -k $mypassword < saved\_result
bad decrypt
140436286886144:error:06065064:digital envelope routines:EVP\_DecryptFinal\_ex:bad decrypt:evp\_enc.c:539:Affected Versions
The bug affects all versions of OpenSSL released prior to the fix. It is recommended that users upgrade to the latest version of OpenSSL to ensure that their encrypted secrets are accessible.
Workaround
For users who are unable to upgrade to the latest version of OpenSSL, there is a workaround available. The workaround involves using a different encryption algorithm, such as AES-256-GCM, which is not affected by the bug. This can be done using the following command:
$ echo "mysecret" | openssl enc -aes-256-gcm -a -salt -k $mypassword
saved result. worked fine...The discovery of the bug in OpenSSL's AES-256-CBC encryption highlights the importance of keeping software up-to-date and the need for robust encryption methods. While the bug has been fixed in the latest version of OpenSSL, it is recommended that users upgrade to ensure that their encrypted secrets are accessible. For those who are unable to upgrade, the workaround of using a different encryption algorithm is available.
References
- OpenSSL. (2022). OpenSSL 3.0.0 ChangeLog. Retrieved from https://www.openssl.org/news/changelog.html
- Stack Overflow. (2022). OpenSSL decrypt gives "bad decrypt" error. Retrieved from https://stackoverflow.com/questions/66844402/openssl-decrypt-gives-bad-decrypt-error
- GitHub. (2022). OpenSSL issue #11052. Retrieved from https://github.com/openssl/openssl/issues/11052