summaryrefslogtreecommitdiff
path: root/docs/lib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2016-06-29 12:16:14 -0400
committerEli Collins <elic@assurancetechnologies.com>2016-06-29 12:16:14 -0400
commit34d04654c3409697f73e33cd60bd8dc36baa3d92 (patch)
tree76beb8bab1e4e4079afc7ef5815b85d2d38c5cd2 /docs/lib
parentbbe932442823cf96cbc77ce523f6ca8f7ebfc1bb (diff)
downloadpasslib-34d04654c3409697f73e33cd60bd8dc36baa3d92.tar.gz
CryptContext: added "harden_verify" support
v1.6 deprecated the "min_verify_time" feature, since it required admins to awkwardly hard-code the amount of time they wanted .verify() to take. This was a useful feature, though, since it provided the ability for contexts to mask which accounts had older, weaker, hashes. This commit adds in a replacement feature: CryptContext now supports a "harden_verify" flag, which causes it to autocalculate how long the default hash should take, and make sure to spend at least that much time. Another improvement is that this autocalc is performed at the context level, not per hash like min_verify_time was, making it overall more reliable. It also offers a new "context.dummy_verify()" call for faking the delay for missing accounts. Changes: * Added "harden_verify" option to CryptContext, along with code to autocalculate min_verify_time delay via timing when context is first accessed. XXX: this timing code needs some battle-testing, and may be adjusted later. * Added .dummy_verify() method, integrated it into .verify() and .verify_and_update(). * updated warnings & docs to report harden_verify as replacement for "min_verify_time" option. * to help workflow for adding delay on missing accounts, .verify() and .verify_and_update() now support passing in hash=None, and treat it as "never verifying"
Diffstat (limited to 'docs/lib')
-rw-r--r--docs/lib/passlib.context-tutorial.rst10
-rw-r--r--docs/lib/passlib.context.rst32
2 files changed, 40 insertions, 2 deletions
diff --git a/docs/lib/passlib.context-tutorial.rst b/docs/lib/passlib.context-tutorial.rst
index b513c5a..19bdb2b 100644
--- a/docs/lib/passlib.context-tutorial.rst
+++ b/docs/lib/passlib.context-tutorial.rst
@@ -414,6 +414,9 @@ All of the documented :ref:`context-options` are allowed.
admin__pbkdf2_sha1__min_rounds = 18000
admin__pbkdf2_sha1__default_rounds = 20000
+ ; delay failed verify() calls to mask hashes with weak rounds
+ harden_verify = true
+
Initializing the CryptContext
-----------------------------
Applications which choose to use a policy file will typically want
@@ -517,10 +520,15 @@ the following code at the correct place::
# this example both checks the user's password AND upgrades deprecated hashes...
#
# vars:
- # 'hash' containing the specified user's hash,
+ # 'hash' containing the specified user's hash.
# 'secret' containing the putative password
# 'category' containing a category assigned to the user account
#
+ # NOTE: if the user account is missing, or has no hash,
+ # you can pass ``hash=None`` to verify_and_update()
+ # mask this from the attacker by simulating the delay
+ # a real verification would have taken.
+ # hash=None will never verify.
ok, new_hash = user_pwd_context.verify_and_update(secret, hash, category=category)
if not ok:
diff --git a/docs/lib/passlib.context.rst b/docs/lib/passlib.context.rst
index a85ba52..437a7e5 100644
--- a/docs/lib/passlib.context.rst
+++ b/docs/lib/passlib.context.rst
@@ -181,6 +181,36 @@ Options which directly affect the behavior of the CryptContext instance:
.. versionchanged:: 1.7
Per deprecation roadmap above, this option is now ignored.
+ See ``harden_verify`` below for a replacement.
+
+.. _context-harden-verify-option:
+
+``harden_verify``
+
+ If set to ``true``, CryptContext will pause the first time :meth:`verify`
+ is called, in order to calculate the "average" time it would take
+ to verify a hash created using the default settings.
+
+ Subsequent :meth:`verify` calls using will have their time padded
+ to this minimum time, in order to make it harder for an attacker
+ to guess which accounts have weak hashes.
+
+ Applications may also wish to call :meth:`dummy_verify` for login
+ attempts where the user does not exist, in order to mask which
+ users accounts have valid hashes.
+
+ This option can be set to ``true`` or ``false``.
+ ``false`` is currently the default, though this (may) be changed
+ in Passlib 2.0.
+
+ .. warning::
+
+ This feature is new, and adjustments may need to be made
+ to when (and how) the code calculates what the "minimum verification time"
+ is supposed to be.
+
+ .. versionadded:: 1.7
+
.. _context-algorithm-options:
Algorithm Options
@@ -395,6 +425,7 @@ instance:
.. automethod:: CryptContext.encrypt
.. automethod:: CryptContext.verify
.. automethod:: CryptContext.identify
+.. automethod:: CryptContext.dummy_verify
.. rst-class:: html-toggle
@@ -413,7 +444,6 @@ Hash Migration
Applications which want to detect and re-encrypt deprecated
hashes will want to use one of the following methods:
-
.. automethod:: CryptContext.verify_and_update
.. automethod:: CryptContext.needs_update
.. automethod:: CryptContext.hash_needs_update