summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-03-02 18:25:32 -0500
committerEli Collins <elic@assurancetechnologies.com>2011-03-02 18:25:32 -0500
commit5008ed8363c1f74659cdee4def4dffda27312e84 (patch)
tree39b320ecbe540a5a4306e7c517505a39d7d73c7c
parentecdbfd6c1996edb1c00e1c16decb69803b648a05 (diff)
downloadpasslib-5008ed8363c1f74659cdee4def4dffda27312e84.tar.gz
work on interface documentation (bcrypt)
-rw-r--r--docs/lib/passlib.hash.apr_md5_crypt.rst5
-rw-r--r--docs/lib/passlib.hash.bcrypt.rst41
-rw-r--r--passlib/drivers/bcrypt.py37
3 files changed, 59 insertions, 24 deletions
diff --git a/docs/lib/passlib.hash.apr_md5_crypt.rst b/docs/lib/passlib.hash.apr_md5_crypt.rst
index 21bc751..19bf621 100644
--- a/docs/lib/passlib.hash.apr_md5_crypt.rst
+++ b/docs/lib/passlib.hash.apr_md5_crypt.rst
@@ -9,7 +9,7 @@ primarily used by the Apache webserver in ``htpasswd`` files.
It contains only minor changes to md5-crypt, and should
be considered just as strong / weak as md5-crypt itself.
-.. seealso:: :doc:`passlib.hash.md5_crypt`
+.. seealso:: :doc:`md5_crypt <passlib.hash.md5_crypt>`
Usage
=====
@@ -34,4 +34,5 @@ to the original MD5-Crypt, except for two changes:
References
==========
-* Apache's description of Apr-MD5-Crypt can be found at `<http://httpd.apache.org/docs/2.2/misc/password_encryptions.html>`_.
+* `<http://httpd.apache.org/docs/2.2/misc/password_encryptions.html>`_
+ - Apache's description of Apr-MD5-Crypt can be found at
diff --git a/docs/lib/passlib.hash.bcrypt.rst b/docs/lib/passlib.hash.bcrypt.rst
index 190bece..3070140 100644
--- a/docs/lib/passlib.hash.bcrypt.rst
+++ b/docs/lib/passlib.hash.bcrypt.rst
@@ -21,7 +21,7 @@ Usage
write usage instructions
-Functions
+Interface
=========
.. autoclass:: bcrypt
@@ -34,28 +34,39 @@ Bcrypt hashes have the format ``$2a${cost}${salt}{checksum}``, where:
* ``{cost}`` is the cost parameter, encoded as 2 zero-padded decimal digits,
which determines the number of rounds used via ``rounds=2**cost`` (cost is 12 in the example).
-* ``{salt}`` is the 22 character salt string, using the characters ``[./A-Za-z0-9]`` (``GhvMmNVjRW29ulnudl.Lbu`` in the example).
+* ``{salt}`` is the 22 character salt string, using the characters in the regexp range ``[./A-Za-z0-9]`` (``GhvMmNVjRW29ulnudl.Lbu`` in the example).
* ``{checksum}`` is the 31 character checksum, using the same characters as the salt (``AnUtN/LRfe1JsBm1Xu6LE3059z5Tr8m`` in the example).
-BCrypt's algorithm is described in detail in it's specification document,
-listed below.
+BCrypt's algorithm is described in detail in it's specification document [#f1]_.
Deviations
==========
This implementation of bcrypt differs from others in a few ways:
-* The bcrypt specification (and implementations) have no predefined
- or predictable behavior when passed a salt containing characters
- outside of the base64 range. To avoid this situtation,
- PassLib will simply throw an error if invalid characters
- are provided for the salt.
+* Restricted salt string character set:
-* Before generating a hash, PassLib encodes unicode passwords using UTF-8.
- While the algorithm accepts passwords containing any 8-bit value
- except for ``\x00``, it specifies no preference for encodings,
- or for handling unicode strings.
+ BCrypt does not specify what the behavior should be when
+ passed a salt string outside of the regexp range ``[./A-Za-z0-9]``.
+ In order to avoid this situtation, Passlib strictly limits salts to the
+ allowed character set, and will throw a ValueError if an invalid
+ salt character is encountered.
+
+* Unicode Policy:
+
+ The underlying algorithm takes in a password specified
+ as a series of non-null bytes, and does not specify what encoding
+ should be used; though a ``us-ascii`` compatible encoding
+ is implied by nearly all implementations of bcrypt
+ as well as all known reference hashes.
+
+ In order to provide support for unicode strings,
+ PassLib will encode unicode passwords using ``utf-8``
+ before running them through bcrypt. If a different
+ encoding is desired by an application, the password should be encoded
+ before handing it to PassLib.
References
==========
-* `<http://www.usenix.org/event/usenix99/provos/provos_html/>`_ - the bcrypt format specification
-* `<http://www.mindrot.org/projects/jBCrypt/>`_ - java implementation used as reference for PassLib
+.. [#f1] `<http://www.usenix.org/event/usenix99/provos/provos_html/>`_ - the bcrypt format specification
+
+.. [#] `<http://www.mindrot.org/projects/jBCrypt/>`_ - java implementation used as reference for PassLib's builtin implementation
diff --git a/passlib/drivers/bcrypt.py b/passlib/drivers/bcrypt.py
index 2fc56a3..c5e72c1 100644
--- a/passlib/drivers/bcrypt.py
+++ b/passlib/drivers/bcrypt.py
@@ -21,7 +21,7 @@ try:
except ImportError:
pybcrypt_hashpw = None
#libs
-from passlib.utils import autodocument, os_crypt
+from passlib.utils import os_crypt
from passlib.utils.drivers import BackendExtHash
#TODO: make this a lazy import, generally don't want to load it.
@@ -37,6 +37,35 @@ __all__ = [
#handler
#=========================================================
class bcrypt(BackendExtHash):
+ """This class implements the BCrypt password hash, and follows the :ref:`password-hash-api`.
+
+ It supports a fixed length salt, and a variable number of rounds.
+
+ The :meth:`encrypt()` and :meth:`genconfig` methods accept the following optional keywords:
+
+ :param salt:
+ Optional salt string.
+ If not specified, one will be autogenerated (this is recommended).
+ It specific, it must be 22 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
+
+ :param rounds:
+ Optional number of rounds to use.
+ Defaults to 12, must be between 4 and 31, inclusive.
+ This value is logarithmic, the actual number of iterations used will be ``2**rounds``.
+
+ :param ident:
+ selects specific version of BCrypt hash that will be used.
+ Typically you want to leave this alone, and let it default to ``2a``,
+ but it can be set to ``2`` to use the older version of BCrypt.
+
+ It will use the first available of three possible backends:
+
+ * `py-bcrypt <http://www.mindrot.org/projects/py-bcrypt/>`_, if installed.
+ * stdlib :func:`crypt()`, if the host OS supports BCrypt.
+ * a pure python implementation of BCrypt built into passlib (very slow).
+
+ You can see which backend is in use by calling the :meth:`get_backend()` method.
+ """
#=========================================================
#class attrs
#=========================================================
@@ -149,12 +178,6 @@ class bcrypt(BackendExtHash):
#eoc
#=========================================================
-autodocument(bcrypt, settings_doc="""
-:param ident:
- selects specific version of BCrypt hash that will be used.
- Typically you want to leave this alone, and let it default to ``2a``,
- but it can be set to ``2`` to use the older version of BCrypt.
-""")
#=========================================================
#eof
#=========================================================