summaryrefslogtreecommitdiff
path: root/django/utils/crypto.py
AgeCommit message (Collapse)Author
2016-11-14Fixed #27463 -- Fixed E741 flake8 warnings.Ramin Farajpour Cami
2015-02-06Sorted imports with isort; refs #23860.Tim Graham
2014-12-13Fixed #23812 -- Changed django.utils.six.moves.xrange imports to rangeMichael Hall
2014-07-11Bump the default iterations for PBKDF2.Alex Gaynor
The rate at which we've increased this has not been keeping up with hardware (and software) improvements, and we're now considerably behind where we should be. The delta between our performance and an optimized implementation's performance prevents us from improving that further, but hopefully once Python 2.7.8 and 3.4+ get into more hands we can more aggressively increase this number.
2014-05-31Note that the stdlib's version of pbkdf2_hmac will also be used in the ↵Alex Gaynor
upcoming Python 2.7.8 release
2014-05-28Fixed constant_time_compare on Python 2.7.7Florian Apolloner
Python 2.7.7 includes compare_digest in the hmac module, but it requires both arguments to have the same type. This is usually not a problem on Python 3 since everything is text, but we have mixed unicode and str on Python 2 -- hence make sure everything is bytes before feeding it into compare_digest.
2014-04-22Use the stdlib's compare_digest for constant time comparisons when availableAlex Gaynor
2014-04-17Typo fixAlex Gaynor
2014-04-17Use the stdlib's PBKDF2 implementation when available.Alex Gaynor
This is a bit faster than ours, which is good, because it lets you increase the iteration counts. This will be used on Python 3.4+, and, pending the acceptance of PEP466, on newer Python 2.7s.
2014-02-16Fixed #19980: Signer broken for binary keys (with non-ASCII chars).MattBlack85
With this pull request, request #878 should considered closed. Thanks to nvie for the patch.
2013-11-05Flake8 fixesAlex Gaynor
2013-11-04Simplify (and very very slightly speed up) the pbkdf2 implementationAlex Gaynor
2013-10-21Fixed #21253 -- PBKDF2 with cached HMAC keyFlorian Apolloner
This gives a 2x speed increase compared to the existing implementation. Thanks to Steve Thomas for the initial patch and Tim Graham for finishing it.
2013-10-18Fixed #21287 -- Fixed E123 pep8 warningsAlasdair Nicol
2013-09-24Fixed #21138 -- Increased the performance of our PBKDF2 implementation.Florian Apolloner
Thanks go to Michael Gebetsroither for pointing out this issue and help on the patch.
2013-09-19Increase default PBKDF2 iterationsPaul McMillan
Increases the default PBKDF2 iterations, since computers have gotten faster since 2011. In the future, we plan to increment by 10% per major version.
2013-08-30Fixed #20989 -- Removed useless explicit list comprehensions.Simon Charette
2013-06-02Switched to using some constants the hmac module exposes.Alex Gaynor
2013-03-18Clarified that constant_time_compare doesn't protect string lengths.Aymeric Augustin
2013-02-27[py3] Always fed hashlib with bytes.Łukasz Langa
2012-08-29Replaced many smart_bytes by force_bytesClaude Paroz
In all those occurrences, we didn't care about preserving the lazy status of the strings, but we really wanted to obtain a real bytestring.
2012-08-21Reverted type check added in 62954ba04c.Aymeric Augustin
Refs #17040.
2012-08-20[py3] Fixed #17040 -- ported django.utils.crypto.constant_time_compare.Aymeric Augustin
This is a private API; adding a type check is acceptable.
2012-08-07[py3] Ported django.utils.crypto.Aymeric Augustin
2012-08-07[py3] Ported django.utils.encoding.Aymeric Augustin
* Renamed smart_unicode to smart_text (but kept the old name under Python 2 for backwards compatibility). * Renamed smart_str to smart_bytes. * Re-introduced smart_str as an alias for smart_text under Python 3 and smart_bytes under Python 2 (which is backwards compatible). Thus smart_str always returns a str objects. * Used the new smart_str in a few places where both Python 2 and 3 want a str.
2012-07-22Used a Python 3-compatible syntax for building a translation tableClaude Paroz
2012-07-22[py3] Added Python 3 compatibility for xrange.Aymeric Augustin
2012-07-22[py3] Removed longs.Aymeric Augustin
2012-06-07Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.Claude Paroz
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
2012-06-06Delayed encoding of password and salt in password checking.Claude Paroz
Applied the rule that string encoding should happen as late as possible. This is also a preparation for Python 3 compatibility.
2012-05-20Imported reduce from functools for forward compatibility.Claude Paroz
In Python 3, reduce has to be imported from functools.
2012-05-19Marked bytestrings with b prefix. Refs #18269Claude Paroz
This is a preparation for unicode literals general usage in Django (Python 3 compatibility).
2012-02-23Improved get_random_string().Paul McMillan
Improved the behavior of get_random_string to re-seed itself each time it is called if the system does not have a secure random number generator. This will change the properties of the random string produced, but will be unpredictable to an attacker. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-02-23Cleanup to use get_random_string consistently.Paul McMillan
Removes several ad hoc implementations of get_random_string() and removes an innapropriate use of settings.SECRET_KEY. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17580 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-02-11Fixes #16827. Adds a length check to CSRF tokens before applying the ↵Paul McMillan
santizing regex. Thanks to jedie for the report and zsiciarz for the initial patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17500 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-02-02Fixed #17481. pbkdf2 hashes no longer ommit leading zeros. Paul McMillan
Some existing user passwords may need to be reset or converted after this change. See the 1.4-beta release notes for more details. Thanks bhuztez for the report and initial patch, claudep for the test. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17418 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-23Renovated password hashing. Many thanks to Justine Tunney for help with the ↵Paul McMillan
initial patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17253 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-28Removed a bunch more Python 2.4 workarounds now that we don't support that ↵Adrian Holovaty
version. Refs #15702 -- thanks to jonash for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-15Fixed Python 2.4 incompatibility introduced in [14218]Luke Plant
sha_constructor was incorrectly used instead of sha_hmac (which only made a difference under 2.4). Thanks to Steffan Kaminski for report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14233 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-14Fixed #14445 - Use HMAC and constant-time comparison functions where needed.Luke Plant
All adhoc MAC applications have been updated to use HMAC, using SHA1 to generate unique keys for each application based on the SECRET_KEY, which is common practice for this situation. In all cases, backwards compatibility with existing hashes has been maintained, aiming to phase this out as per the normal deprecation process. In this way, under most normal circumstances the old hashes will have expired (e.g. by session expiration etc.) before they become invalid. In the case of the messages framework and the cookie backend, which was already using HMAC, there is the possibility of a backwards incompatibility if the SECRET_KEY is shorter than the default 50 bytes, but the low likelihood and low impact meant compatibility code was not worth it. All known instances where tokens/hashes were compared using simple string equality, which could potentially open timing based attacks, have also been fixed using a constant-time comparison function. There are no known practical attacks against the existing implementations, so these security improvements will not be backported. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14218 bcc190cf-cafb-0310-a4f2-bffc1f526a37