summaryrefslogtreecommitdiff
path: root/otp2289/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'otp2289/server.py')
-rw-r--r--otp2289/server.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/otp2289/server.py b/otp2289/server.py
index b765af6..fca3f06 100644
--- a/otp2289/server.py
+++ b/otp2289/server.py
@@ -58,10 +58,9 @@ class OTPState:
58 Constructs an OTPState object with the given arguments. 58 Constructs an OTPState object with the given arguments.
59 59
60 Keyword Arguments: 60 Keyword Arguments:
61 :param ot_hex: The one-time hex from the last successful 61 :param ot_hex: The one-time hex from the last successful authentication
62 authentication or the first OTP of a newly 62 or None for a newly initialized sequence.
63 initialized sequence 63 :type ot_hex: str or None
64 :type ot_hex: str
65 64
66 :param current_step: The current step that is sent with the challenge 65 :param current_step: The current step that is sent with the challenge
67 :type current_step: int 66 :type current_step: int
@@ -81,7 +80,9 @@ class OTPState:
81 self._step = OTPGenerator.validate_step(current_step) 80 self._step = OTPGenerator.validate_step(current_step)
82 except OTPGeneratorException as exp: 81 except OTPGeneratorException as exp:
83 raise OTPStateException(exp.args[0]) 82 raise OTPStateException(exp.args[0])
84 self._current_digest = self.validate_hex(ot_hex) 83 self._current_digest = None
84 if ot_hex is not None:
85 self._current_digest = self.validate_hex(ot_hex)
85 self._new_digest_hex = None # set upon a successful validation 86 self._new_digest_hex = None # set upon a successful validation
86 87
87 @property 88 @property
@@ -223,6 +224,7 @@ class OTPState:
223 if self._hash_algo == 'md5': 224 if self._hash_algo == 'md5':
224 digest = hashlib.md5(response_bytes).digest() 225 digest = hashlib.md5(response_bytes).digest()
225 if ( 226 if (
227 self._current_digest is None or
226 OTPGenerator.strxor(digest[0:8], digest[8:]) == 228 OTPGenerator.strxor(digest[0:8], digest[8:]) ==
227 self._current_digest 229 self._current_digest
228 ): 230 ):
@@ -234,6 +236,7 @@ class OTPState:
234 if self._hash_algo == 'sha1': 236 if self._hash_algo == 'sha1':
235 digest = hashlib.sha1(response_bytes).digest() 237 digest = hashlib.sha1(response_bytes).digest()
236 if ( 238 if (
239 self._current_digest is None or
237 OTPGenerator.sha1_digest_folding( 240 OTPGenerator.sha1_digest_folding(
238 hashlib.sha1( 241 hashlib.sha1(
239 response_bytes).digest()) == self._current_digest 242 response_bytes).digest()) == self._current_digest
@@ -255,7 +258,10 @@ class OTPState:
255 :return: The dict representation of the object 258 :return: The dict representation of the object
256 :rtype: dict 259 :rtype: dict
257 """ 260 """
258 return {'ot_hex': binascii.hexlify(self._current_digest).decode(), 261 ot_hex = self._current_digest
262 if ot_hex is not None:
263 ot_hex = binascii.hexlify(self._current_digest).decode()
264 return {'ot_hex': ot_hex,
259 'current_step': self._step, 265 'current_step': self._step,
260 'seed': self._seed, 266 'seed': self._seed,
261 'hash_algo': self._hash_algo} 267 'hash_algo': self._hash_algo}