summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES8
-rw-r--r--docs/lib/passlib.exc.rst7
-rw-r--r--docs/lib/passlib.totp.rst4
-rw-r--r--docs/new_app_quickstart.rst8
-rw-r--r--passlib/crypto/digest.py19
-rw-r--r--passlib/totp.py67
6 files changed, 57 insertions, 56 deletions
diff --git a/CHANGES b/CHANGES
index 180bb09..f0b8312 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,15 +9,15 @@ Release History
Future Changes
==============
-The following is not a comprehensive list, merely a summary of important
-planned future changes which may impact developers:
+The following is not a comprehensive list of upcoming changes,
+but merely a summary of important changes which may impact developers:
-* 1.8:
+* v1.8:
- Removal of long-deprecated :class:`CryptPolicy` class.
- Removal of deprecated methods from :mod:`passlib.apache`.
-* 2.0:
+* v2.0:
- A *large* number of deprecated methods and features will be removed;
primarily the deprecated :meth:`!hasher.encrypt` alias.
diff --git a/docs/lib/passlib.exc.rst b/docs/lib/passlib.exc.rst
index 81c97b2..f90f330 100644
--- a/docs/lib/passlib.exc.rst
+++ b/docs/lib/passlib.exc.rst
@@ -21,7 +21,12 @@ Exceptions
.. autoexception:: PasslibSecurityError
-.. autoexception:: TokenReuseError
+TOTP Exceptions
+---------------
+.. autoexception:: TokenError
+.. autoexception:: MalformedTokenError
+.. autoexception:: InvalidTokenError
+.. autoexception:: UsedTokenError
Warnings
========
diff --git a/docs/lib/passlib.totp.rst b/docs/lib/passlib.totp.rst
index e535a39..fdb5fe4 100644
--- a/docs/lib/passlib.totp.rst
+++ b/docs/lib/passlib.totp.rst
@@ -68,8 +68,8 @@ Helper Classes
Deviations
==========
-* The TOTP Spec [#totpspec]_ includes an potentially offset from the base time (``T0``).
- Passlib omits this (fixing it at ``0``), but so do pretty much all other TOTP implementations.
+* The TOTP Spec [#totpspec]_ includes an param (``T0)``) providing an optional offset from the base time.
+ Passlib omits this parameter (fixing it at ``0``), but so do pretty much all other TOTP implementations.
.. rubric:: Footnotes
diff --git a/docs/new_app_quickstart.rst b/docs/new_app_quickstart.rst
index 508a385..2dccb30 100644
--- a/docs/new_app_quickstart.rst
+++ b/docs/new_app_quickstart.rst
@@ -66,12 +66,12 @@ All four hashes share the following properties:
* variable rounds for configuring flexible cpu cost on a per-hash basis.
* at least 96 bits of salt.
* basic algorithm has seen heavy scrutiny and use for at least 10 years
- (except for Argon2, from is from circa 2013).
+ (except for Argon2, born around 2013).
* in use across a number of OSes and/or a wide variety of applications.
Argon2 is much younger than the others, but has seen heavy scrunity,
and was purpose-designed for password hashing. In the near future, it stands likely to
-become *THE* recommended standard.
+become *the* recommended standard.
.. rst-class:: html-toggle
@@ -180,8 +180,8 @@ standard format for encoding password hashes using this algorithm
Furthermore, when compared to Argon2 and BCrypt, PBKDF2 has proven more susceptible to cracking
using modern GPU-based techniques.
-Making Descision
-----------------
+Making a Decision
+-----------------
For new applications, this decision comes down to a couple of questions:
1. Does the hash need to be natively supported by your operating system's :func:`!crypt` api,
diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py
index b02fdbc..78c2ad4 100644
--- a/passlib/crypto/digest.py
+++ b/passlib/crypto/digest.py
@@ -207,9 +207,9 @@ def lookup_hash(digest, return_unknown=False):
Can be used to look up a hash constructor by name, normalize hash name representation, etc.
:arg digest:
- This can be a digest constructor (e.g. :func:`hashlib.sha256`),
- a string containing a :mod:`!hashlib` digest name (e.g. ``"sha256"``),
- an IANA-assigned hash name. Case is ignored, underscores are converted to hyphens,
+ A string containing a :mod:`!hashlib` digest name (e.g. ``"sha256"``),
+ an IANA-assigned hash name, or even a digest constructor (e.g. :func:`hashlib.sha256`).
+ Case is ignored, underscores are converted to hyphens,
and various other cleanups are made.
:param return_unknown:
@@ -217,11 +217,11 @@ def lookup_hash(digest, return_unknown=False):
can be found. However, if this flag is False, it will instead return a dummy record
without a constructor function. This is mainly used by :func:`norm_hash_name`.
- Multiple calls made with the same input, or made with inputs that reference the same hash,
- should all return the same :class:`!lookup_hash` instance.
+ :returns HashInfo:
+ :class:`!HashInfo` instance containing information about specified digest.
- :returns:
- :class:`HashInfo` instance for specified digest.
+ Multiple calls resolving to the same hash should always
+ return the same :class:`!HashInfo` instance.
"""
# check for cached entry
cache = _hash_info_cache
@@ -353,13 +353,14 @@ class HashInfo(SequenceMixin):
.. autoattribute:: iana_name
.. autoattribute:: aliases
- Also acts as a sequence of ``(const, digest_size, block_size)``.
+ This object can also be treated a 3-element sequence
+ containing ``(const, digest_size, block_size)``.
"""
#=========================================================================
# instance attrs
#=========================================================================
- #: Canonical (hashlib-compatible) name (e.g. ``"sha256"``).
+ #: Canonical / hashlib-compatible name (e.g. ``"sha256"``).
name = None
#: IANA assigned name (e.g. ``"sha-256"``), may be ``None`` if unknown.
diff --git a/passlib/totp.py b/passlib/totp.py
index a911e11..d918569 100644
--- a/passlib/totp.py
+++ b/passlib/totp.py
@@ -309,28 +309,33 @@ class OTPContext(object):
which will be used to encrypt TOTP keys for storage.
Arguments
- ---------
+ =========
:param secrets:
- collection of (tag, secret) pairs.
- this should include historical secrets that are still in use,
- as well as the default secret to use when encrypting new keys.
-
- can be list of (tag, secret) pairs, or a mapping of tag -> secret.
-
- each tag should be string that starts with regex range ``[a-z0-9]``,
+ Dict of application secrets to use when encrypting/decrypting
+ TOTP keys for storage. If specified, this should include
+ at least one secret to use when encrypting new keys,
+ as well as 0 or more olders secrets that need to be kept around
+ to decrypt existing stored keys.
+
+ Dict should map tags -> secrets, so that each secret is identified
+ by a unique tag. This tag will be stored along with the encrypted
+ key in order to determine which secret should be used for decryption.
+ Tag should be string that starts with regex range ``[a-z0-9]``,
and the remaining characters must be in ``[a-z0-9_.-]``.
- this can also be a json formatted string matching one of
- the above formats, OR a multiline string with the format
- ``"tag: value\ntag: value\n..."``.
+ Instead of a python dict, this can also be a json formatted string
+ containing a dict, OR a multiline string with the format
+ ``"tag: value\\ntag: value\\n..."``
:param secrets_path:
Alternately, callers can specify a separate file where the
- application-wide secrets are stored.
+ application-wide secrets are stored, using either of the string
+ formats described in **secrets**.
:param default_tag:
- specifies which tag should be used as the default for new keys.
- if omitted, the tags will be sorted, and the largest tag picked.
+ Specifies which tag in **secrets** should be used as the default
+ for encrypting new keys. If omitted, the tags will be sorted,
+ and the largest tag used as the default.
if all tags are numeric, they will be sorted numerically;
otherwise they will be sorted alphabetically.
@@ -342,33 +347,22 @@ class OTPContext(object):
This value corresponds to log2() of the number of PBKDF2
rounds used.
- :param app_secret_tag:
- :param app_secret_map:
-
- TODO: fix docs for these two.
-
- Optional password which will be used to encrypt the secret key.
-
- *(The key is encrypted using PBKDF2-HMAC-SHA256, see the source
- of the* :func:`encrypt_key` *function for details)*.
-
- If the TOTP object had a password provided to the constructor,
- to or :meth:`from_json`, you can set ``password=True`` here
- to simply re-use the previously encrypted secret key.
-
.. warning::
- The **secrets** should be kept in a secure location by your application,
- and contain a large amount of entropy (to prevent brute-force guessing).
- Since the encrypt/decrypt cycle is expected to be required
- to (de-)serialize TOTP instances every time a user logs in,
- the default work-factor (``cost``) is kept relatively low.
+ The application secret(s) should be stored in a secure location by
+ your application, and each secret should contain a large amount
+ of entropy (to prevent brute-force attacks if the encrypted keys
+ are leaked).
:func:`generate_secret` is provided as a convenience helper
to generate a new application secret of suitable size.
+ Best practice is to load these values from a file via **secrets_path**,
+ and then have your application give up permission to read this file
+ once it's running.
+
Public Methods
- --------------
+ ==============
.. automethod:: new
.. automethod:: from_uri
.. automethod:: from_json
@@ -376,7 +370,7 @@ class OTPContext(object):
..
Semi-Private Methods
- --------------------
+ ====================
The following methods are used internally by the :class:`TOTP` and :class:`HOTP`
classes in order to encrypt & decrypt keys using the provided application
secrets:
@@ -1441,6 +1435,7 @@ class BaseOTP(object):
:param encrypt:
Whether to output should be encrypted.
+
* ``"auto"`` (the default) -- uses encrypted key if application
secret is available, otherwise uses raw key.
* True -- uses encrypted key, or raises TypeError
@@ -1919,7 +1914,7 @@ class TotpMatch(SequenceMixin):
"""
#: TOTP counter value which token matched against.
#: (Best practice it to subsequently ignore tokens for this counter
- #: and earlier)
+ #: and earlier)
counter = 0
#: Timestamp when verification was performed.