Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Changelog
+---------+------------+------------------------------------------------------+
| Version | Date | Changes |
+=========+============+======================================================+
| 1.0.2 | 2017-06-16 | - automatically pad secrets to expected length |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If autopad=True is removed, this should push the MINOR, not PATCH.

+---------+------------+------------------------------------------------------+
| 1.0.1 | 2015-07-31 | - fixed tests and build system, |
| | | - extended test coverage with Py3.5, PyPy and PyPy3, |
+---------+------------+------------------------------------------------------+
Expand Down
10 changes: 7 additions & 3 deletions onetimepass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
time-based. It is compatible with Google Authenticator application and
applications based on it.

@version: 1.0.1
@version: 1.0.2
@author: Tomasz Jaskowski
@contact: http://github.com/tadeck
@license: MIT
Expand Down Expand Up @@ -35,8 +35,8 @@
import time

__author__ = 'Tomasz Jaskowski <tadeck@gmail.com>'
__date__ = '31 July 2015'
__version_info__ = (1, 0, 1)
__date__ = '16 June 2017'
__version_info__ = (1, 1, 0)
__version__ = '%s.%s.%s' % __version_info__
__license__ = 'MIT'

Expand Down Expand Up @@ -110,6 +110,10 @@ def get_hotp(
# Get rid of all the spacing:
secret = secret.replace(b' ', b'')
try:
# Autopad if necessary
mod = len(secret) % 8
if mod:
secret += b'=' * (8 - mod)
key = base64.b32decode(secret, casefold=casefold)
except (TypeError):
raise TypeError('Incorrect secret')
Expand Down
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ def test_hotp_for_range_preceding_match(self):
secret = b'MFRGGZDFMZTWQ2LK'
self.assertFalse(valid_hotp(713385, secret, last=1, trials=2))

def test_autopadding(self):
"""
Check if unpadded and padded secrets resolve to the same token
"""
secret = b'MFRGGZDFMZTWQ2LK'
for length in [2, 4, 5, 7, 10, 12, 13, 15]:
fragment = secret[0:length]
fragment_padded = fragment + b'=' * (8 - len(fragment) % 8)
self.assertEqual(get_hotp(fragment_padded, 123),
get_hotp(fragment, 123))


class TotpGenerationTestCase(TestCase):
"""
Expand Down