diff options
author | Terry Chia <terrycwk1994@gmail.com> | 2016-07-16 22:22:32 +0800 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-07-16 08:22:32 -0600 |
commit | 69617caca7ff98f1a991b476669f1afcdfb01fb0 (patch) | |
tree | eef6034da6f6ddc8faa691b7787c7b3d7389a79c /src | |
parent | c0f5a8272988c7b93b301d2b3a53cd6f1a350dff (diff) | |
download | cryptography-69617caca7ff98f1a991b476669f1afcdfb01fb0.tar.gz cryptography-69617caca7ff98f1a991b476669f1afcdfb01fb0.tar.bz2 cryptography-69617caca7ff98f1a991b476669f1afcdfb01fb0.zip |
Add flag to toggle key length check for HOTP and TOTP. (#3012)
* Add an enforce_key_length parameter to HOTP and TOTP.
* Document changes in docs.
* Add some words to the wordlist.
* Add versionadded to docs.
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/primitives/twofactor/hotp.py | 5 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/twofactor/totp.py | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/cryptography/hazmat/primitives/twofactor/hotp.py b/src/cryptography/hazmat/primitives/twofactor/hotp.py index 12bc7661..4ad1bdc2 100644 --- a/src/cryptography/hazmat/primitives/twofactor/hotp.py +++ b/src/cryptography/hazmat/primitives/twofactor/hotp.py @@ -19,14 +19,15 @@ from cryptography.hazmat.primitives.twofactor.utils import _generate_uri class HOTP(object): - def __init__(self, key, length, algorithm, backend): + def __init__(self, key, length, algorithm, backend, + enforce_key_length=True): if not isinstance(backend, HMACBackend): raise UnsupportedAlgorithm( "Backend object does not implement HMACBackend.", _Reasons.BACKEND_MISSING_INTERFACE ) - if len(key) < 16: + if len(key) < 16 and enforce_key_length is True: raise ValueError("Key length has to be at least 128 bits.") if not isinstance(length, six.integer_types): diff --git a/src/cryptography/hazmat/primitives/twofactor/totp.py b/src/cryptography/hazmat/primitives/twofactor/totp.py index 60705901..499f2824 100644 --- a/src/cryptography/hazmat/primitives/twofactor/totp.py +++ b/src/cryptography/hazmat/primitives/twofactor/totp.py @@ -15,7 +15,8 @@ from cryptography.hazmat.primitives.twofactor.utils import _generate_uri class TOTP(object): - def __init__(self, key, length, algorithm, time_step, backend): + def __init__(self, key, length, algorithm, time_step, backend, + enforce_key_length=True): if not isinstance(backend, HMACBackend): raise UnsupportedAlgorithm( "Backend object does not implement HMACBackend.", @@ -23,7 +24,7 @@ class TOTP(object): ) self._time_step = time_step - self._hotp = HOTP(key, length, algorithm, backend) + self._hotp = HOTP(key, length, algorithm, backend, enforce_key_length) def generate(self, time): counter = int(time / self._time_step) |