-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insecure block cipher mode #27
Comments
What's the recommended way to migrate from the default to MODE_CBC? |
I'm wondering the same thing as @mjacksonw. |
Can we decrypt ECB values upon access and store them with CBC? Or better make a migration script, since we have SECRET_KEY and we can decrypt all possible ECB values and encrypt with more secure algo at once. Btw, there is a deprecation warning for ECB default now...
|
For migration, I would suggest dumping the data using the django management commands, and then making the change to CBC and reloading the data back in. For hashes (which are a one-way function), Django had to wait for the user to re-input their password to re-hash, so a more convoluted and gradual conversion was a necessary evil. But in this case, dumping the data will convert it to plaintext, and reloading will convert to CBC in one giant step - there's not really a need for a more complicated migration solution. Just make sure to backup. |
Anyway, I suppose there is a way to make migration automatic. Introspect all models, find fields with weak encryption algo, dump 'em, change the fields to CBC, load 'em back again. Pros: seamless for users (hopefully), cons: extra maintenance costs. |
The pycrypto library defaults to ECB mode for AES:
http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
I'm not sure why they do this, considering even their own documentation says not to use it:
https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.blockalgo-module.html#MODE_ECB
But, as you can see, the default call to
AES.new()
uses this cipher mode:https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.AES-module.html#new
The major difference that would need to be made to django-fields to support a stronger and secure block cipher mode (i.e. CBC) would be the addition of a random IV that is appended to the ciphertext. (An example of proper use is documented in the pycrypto AES module page linked above.
However, this change isn't backwards compatible for data previously encrypted.
I'll take a stab at upgrading the library to keep backwards compatible defaults, but enabling a stronger block cipher mode via kwords arguments (like how cipher type is decided). Still, any data using the insecure defaults will have to be dumped prior to upgrading to CBC, and then imported again after the change.
The text was updated successfully, but these errors were encountered: