This repository was archived by the owner on Nov 24, 2024. It is now read-only.
Fixed insecure cryptography in PBECipher.java #23
+13
−63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By default (with the default constants and settings) the DefaultPlexusCipher object takes a plaintext and a human-readable password that I will refer to as “pwd”. It then generates a key and an IV to be used with AES/CBC/PKCS5Padding. The encrypt64 method generates a random 8 byte salt, computes SHA256(pwd|salt), and then uses the first 16 bytes of the hash as the AES key and the last 16 bytes of the hash as the IV. The salt is then prepended to the ciphertext and the result is base64 encoded and outputted.
This key derivation algorithm is extremely insecure and ciphertexts produced by plexus-cipher are currently easy to brute force. SHA256 is meant to be fast. During a brute force attempt, identifying the correct key and IV is fairly easy: the correct key and IV will yield a decryption with significantly less Shannon entropy than all of the failed decryption attempts, which will produce outputs indistinguishable from random bytes (which will have high Shannon entropy). Data that needs to be encrypted tends to have some sort of structure, and is often times composed of ASCII characters.
An ideal fix here is to just use a well-established key derivation function such as PBKDF2 (as I have done). OWASP recommends to use 310000+ iterations with PBKDF2.
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
This fix is not backwards compatible and will will cause people using Plexus Cipher to have to re-encrypt their information. The existing cryptography provides little protection in its current state though.