PyOTP 1.3.0__tar.gz → 1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyotp-1.4/LICENSE +21 -0
- {pyotp-1.3.0 → pyotp-1.4}/PKG-INFO +1 -1
- {pyotp-1.3.0 → pyotp-1.4}/setup.py +1 -1
- {pyotp-1.3.0 → pyotp-1.4}/src/pyotp/hotp.py +3 -3
- {pyotp-1.3.0 → pyotp-1.4}/src/pyotp/totp.py +9 -8
- {pyotp-1.3.0 → pyotp-1.4}/test.py +12 -10
- {pyotp-1.3.0 → pyotp-1.4}/README.markdown +0 -0
- {pyotp-1.3.0 → pyotp-1.4}/src/pyotp/__init__.py +0 -0
- {pyotp-1.3.0 → pyotp-1.4}/src/pyotp/otp.py +0 -0
pyotp-1.4/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (C) 2011 by Mark Percival <m@mdp.im>
|
|
2
|
+
|
|
3
|
+
Python port copyright 2011 by Nathan Reynolds <email@nreynolds.co.uk>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -10,15 +10,15 @@ class HOTP(OTP):
|
|
|
10
10
|
@returns [Integer] OTP
|
|
11
11
|
"""
|
|
12
12
|
return self.generate_otp(count)
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def verify(self, otp, counter):
|
|
15
15
|
"""
|
|
16
16
|
Verifies the OTP passed in against the current time OTP
|
|
17
17
|
@param [String/Integer] otp the OTP to check against
|
|
18
18
|
@param [Integer] counter the counter of the OTP
|
|
19
19
|
"""
|
|
20
|
-
return otp == self.at(counter)
|
|
21
|
-
|
|
20
|
+
return unicode(otp) == unicode(self.at(counter))
|
|
21
|
+
|
|
22
22
|
def provisioning_uri(self, name, initial_count=0):
|
|
23
23
|
"""
|
|
24
24
|
Returns the provisioning URI for the OTP
|
|
@@ -7,12 +7,12 @@ import urllib
|
|
|
7
7
|
class TOTP(OTP):
|
|
8
8
|
def __init__(self, *args, **kwargs):
|
|
9
9
|
"""
|
|
10
|
-
@option options [Integer] interval (30) the time interval in seconds
|
|
11
|
-
This defaults to 30 which is standard.
|
|
10
|
+
@option options [Integer] interval (30) the time interval in seconds
|
|
11
|
+
for OTP This defaults to 30 which is standard.
|
|
12
12
|
"""
|
|
13
13
|
self.interval = kwargs.pop('interval', 30)
|
|
14
14
|
super(TOTP, self).__init__(*args, **kwargs)
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def at(self, for_time):
|
|
17
17
|
"""
|
|
18
18
|
Accepts either a Unix timestamp integer or a Time object.
|
|
@@ -22,14 +22,14 @@ class TOTP(OTP):
|
|
|
22
22
|
if not isinstance(for_time, datetime.datetime):
|
|
23
23
|
for_time = datetime.datetime.fromtimestamp(int(for_time))
|
|
24
24
|
return self.generate_otp(self.timecode(for_time))
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def now(self):
|
|
27
27
|
"""
|
|
28
28
|
Generate the current time OTP
|
|
29
29
|
@return [Integer] the OTP as an integer
|
|
30
30
|
"""
|
|
31
31
|
return self.generate_otp(self.timecode(datetime.datetime.now()))
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
def verify(self, otp, for_time=None):
|
|
34
34
|
"""
|
|
35
35
|
Verifies the OTP passed in against the current time OTP
|
|
@@ -37,8 +37,9 @@ class TOTP(OTP):
|
|
|
37
37
|
"""
|
|
38
38
|
if for_time is None:
|
|
39
39
|
for_time = datetime.datetime.now()
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
return unicode(otp) == unicode(self.at(for_time))
|
|
42
|
+
|
|
42
43
|
def provisioning_uri(self, name):
|
|
43
44
|
"""
|
|
44
45
|
Returns the provisioning URI for the OTP
|
|
@@ -51,7 +52,7 @@ class TOTP(OTP):
|
|
|
51
52
|
'name': urllib.quote(name, safe='@'),
|
|
52
53
|
'secret': self.secret,
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
|
|
55
56
|
def timecode(self, for_time):
|
|
56
57
|
i = time.mktime(for_time.timetuple())
|
|
57
58
|
return int(i / self.interval)
|
|
@@ -23,12 +23,13 @@ class HOTPExampleValuesFromTheRFC(unittest.TestCase):
|
|
|
23
23
|
self.assertEqual(hotp.at(7), 162583)
|
|
24
24
|
self.assertEqual(hotp.at(8), 399871)
|
|
25
25
|
self.assertEqual(hotp.at(9), 520489)
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
def testVerifyAnOTPAndNowAllowReuse(self):
|
|
28
28
|
hotp = pyotp.HOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
|
|
29
29
|
self.assertTrue(hotp.verify(520489, 9))
|
|
30
30
|
self.assertFalse(hotp.verify(520489, 10))
|
|
31
|
-
|
|
31
|
+
self.assertFalse(hotp.verify("520489", 10))
|
|
32
|
+
|
|
32
33
|
def testProvisioningURI(self):
|
|
33
34
|
hotp = pyotp.HOTP('wrn3pqx5uqxqvnqr')
|
|
34
35
|
self.assertEqual(hotp.provisioning_uri('mark@percival'), 'otpauth://hotp/mark@percival?secret=wrn3pqx5uqxqvnqr&counter=0')
|
|
@@ -40,19 +41,20 @@ class TOTPExampleValuesFromTheRFC(unittest.TestCase):
|
|
|
40
41
|
self.assertEqual(totp.at(1111111111), 50471)
|
|
41
42
|
self.assertEqual(totp.at(1234567890), 5924)
|
|
42
43
|
self.assertEqual(totp.at(2000000000), 279037)
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
def testMatchTheGoogleAuthenticatorOutput(self):
|
|
45
46
|
totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
|
|
46
47
|
with Timecop(1297553958):
|
|
47
48
|
self.assertEqual(totp.now(), 102705)
|
|
48
|
-
|
|
49
|
+
|
|
49
50
|
def testValidateATimeBasedOTP(self):
|
|
50
51
|
totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
|
|
51
52
|
with Timecop(1297553958):
|
|
52
53
|
self.assertTrue(totp.verify(102705))
|
|
54
|
+
self.assertTrue(totp.verify("102705"))
|
|
53
55
|
with Timecop(1297553958 + 30):
|
|
54
56
|
self.assertFalse(totp.verify(102705))
|
|
55
|
-
|
|
57
|
+
|
|
56
58
|
def testProvisioningURI(self):
|
|
57
59
|
totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
|
|
58
60
|
self.assertEqual(totp.provisioning_uri('mark@percival'), 'otpauth://totp/mark@percival?secret=wrn3pqx5uqxqvnqr')
|
|
@@ -62,23 +64,23 @@ class Timecop(object):
|
|
|
62
64
|
"""
|
|
63
65
|
Half-assed clone of timecop.rb, just enough to pass our tests.
|
|
64
66
|
"""
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
def __init__(self, freeze_timestamp):
|
|
67
69
|
self.freeze_timestamp = freeze_timestamp
|
|
68
|
-
|
|
70
|
+
|
|
69
71
|
def __enter__(self):
|
|
70
72
|
self.real_datetime = datetime.datetime
|
|
71
73
|
datetime.datetime = self.frozen_datetime()
|
|
72
|
-
|
|
74
|
+
|
|
73
75
|
def __exit__(self, type, value, traceback):
|
|
74
76
|
datetime.datetime = self.real_datetime
|
|
75
|
-
|
|
77
|
+
|
|
76
78
|
def frozen_datetime(self):
|
|
77
79
|
class FrozenDateTime(datetime.datetime):
|
|
78
80
|
@classmethod
|
|
79
81
|
def now(cls):
|
|
80
82
|
return cls.fromtimestamp(timecop.freeze_timestamp)
|
|
81
|
-
|
|
83
|
+
|
|
82
84
|
timecop = self
|
|
83
85
|
return FrozenDateTime
|
|
84
86
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|