diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2016-11-07 21:50:51 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2016-11-07 21:50:51 -0500 |
| commit | ea291cc3d8209ed298b1d73776684cef12fc55e6 (patch) | |
| tree | 6981a4db27d5fe54afe2164a8250dd0f130687e2 /docs/lib | |
| parent | c9f0d96ffb0c86013cfb5920fd8184ea40baf1ef (diff) | |
| download | passlib-ea291cc3d8209ed298b1d73776684cef12fc55e6.tar.gz | |
totp: stripped out the 'stateful' methods (TOTP.advance, TOTP.consume, and TOTP.last_counter).
switching to purely stateless object, will update docs so that apps are
instructed to persist verify()'s last_counter value independantly.
Diffstat (limited to 'docs/lib')
| -rw-r--r-- | docs/lib/passlib.totp-tutorial.rst | 81 | ||||
| -rw-r--r-- | docs/lib/passlib.totp.rst | 11 |
2 files changed, 5 insertions, 87 deletions
diff --git a/docs/lib/passlib.totp-tutorial.rst b/docs/lib/passlib.totp-tutorial.rst index 90868e3..fff2696 100644 --- a/docs/lib/passlib.totp-tutorial.rst +++ b/docs/lib/passlib.totp-tutorial.rst @@ -16,18 +16,14 @@ using the widely supported TOTP specification. This module is designed to support a variety of use cases, including: - * Low-level methods for creating OTP keys. + * Creating & transferring TOTP keys to client devices. - * Low-level methods for generating & verifying tokens. + * Generating & verifying tokens. - * Methods for transferring OTP keys from server to client via provisioning URIs. + * Securely storing TOTP keys. - * High level methods for encrypting & storing OTP keys and state. - - * High level methods for generating & verifying tokens with persistent state. - -This walkthrough starts with the simpler lowlevel cases, and builds up -to the more complex highlevel ones. +This walkthrough starts with the simpler cases, and builds up +to the more complex ones. .. seealso:: The :mod:`passlib.totp` api reference, which lists all details of all the classes and methods mentioned here. @@ -278,73 +274,6 @@ Use this to provide the last counter value that was authenticated: For more details, see the :meth:`TOTP.verify` method. -.. _totp-stateful-usage: - -Stateful Verification -===================== -TOTP has a number of edge cases that require applications to store some persistent state -about a TOTP token. This includes things such as the last-used counter value -(to prevent :ref:`token re-use <totp-reuse-warning>`), and verification history -(for client clock drift estimation). - -To make this easier, passlib offers a higher level stateful API, -which layers itself on top of the stateless api documented in `Basic Usage`_. -For the server-side, this is oriented around the :meth:`TOTP.consume` method, -which acts as a thin (stateful) wrapper around the :meth:`TOTP.verify` method. - -The :attr:`TOTP.last_counter` attribute can be used to track value of the last token which successfully -verified. The :meth:`TOTP.consume` method uses this to detect and prevent -re-use of the last verified token, and (upon successful verification) -updates this attribute to indicate the provided token has been "consumed". - -For instance, the following is a typical successful verification of a token:: - - >>> # load otp object from json-encoded value in database - >>> from passlib import totp - >>> data = '{"key":"GVDOQ7NP6XPJWE4CWCLFFSXZH6DTAZWM","type":"totp","v":1,"last_counter":49157801}' - >>> otp = totp.from_json(data) - - >>> # observe that last counter set to when user last successfully used a token - >>> otp.last_counter - 49157801 - - >>> # user provides valid token - >>> otp.consume('359275') - - >>> # observe that last counter has been updated by consume() - >>> otp.last_counter - 49157961 - - >>> # applications should re-persist to storage to prevent re-use of this token - >>> data = otp.to_json() - -Now that the :attr:`!last_counter` value has been updated, -if an attacker then comes along and attempts to re-use this token within :meth:`!verify`'s time window:: - - >>> # load otp object from json-encoded value in database - >>> from passlib import totp - >>> data = '{"key":"GVDOQ7NP6XPJWE4CWCLFFSXZH6DTAZWM","type":"totp","v":1,"last_counter":49157961}' - >>> otp = totp.from_json(data) - - >>> # observe that last counter set to when user last successfully used a token - >>> otp.last_counter - 49157961 - - >>> # attacker tries to reuse token - >>> otp.consume('359275') - ... - UsedTokenError: Token has already been used, please wait for another. - -.. seealso:: - - The :meth:`TOTP.consume` and :meth:`TOTP.to_json` methods, - the :attr:`TOTP.last_counter` attribute, and the :func:`~totp.from_json` constructor. - -.. - *Sidenote:* If implementing a TOTP client, the :meth:`TOTP.advance` method offers similar state - tracking on the client side (though this is really only offered as a parallel - to :meth:`HOTP.advance`, where client-side statefulness is needed). - .. _totp-context-usage: OTPContext Usage diff --git a/docs/lib/passlib.totp.rst b/docs/lib/passlib.totp.rst index 6916779..d3cb4db 100644 --- a/docs/lib/passlib.totp.rst +++ b/docs/lib/passlib.totp.rst @@ -38,7 +38,6 @@ TOTP – Client-Side Token Generation TOTP – Server-Side Token Verification ------------------------------------- .. automethod:: TOTP.verify -.. automethod:: TOTP.consume .. todo:: @@ -103,16 +102,6 @@ Most of this information will be serialized by :meth:`~TOTP.to_uri` and :meth:`~ .. autoattribute:: TOTP.alg .. autoattribute:: TOTP.period -TOTP – Internal State Attributes --------------------------------- -The following attributes are used to track the internal state of this generator, -and will be included in the output of :meth:`~TOTP.to_json`: - -.. autoattribute:: TOTP.last_counter - -(Note: All internal state attributes can be initialized via constructor options, -but this is mainly an internal / testing detail). - Support Classes --------------- .. autoclass:: TotpToken() |
