def _update_device_status_from_token(self, token, show_result=True): if self.token_entry_blocked_until > datetime.now( ) and self.waiting_period_enabled: if show_result: print('TOKEN_ENTRY_BLOCKED') return False token_value, token_count, token_type = OPAYGODecoder.get_activation_value_count_and_type_from_token( token=token, starting_code=self.starting_code, key=self.key, last_count=self.count, restricted_digit_set=self.restricted_digit_set, used_counts=self.used_counts) if token_value is None: if show_result: print('TOKEN_INVALID') self.invalid_token_count += 1 self.token_entry_blocked_until = datetime.now() + timedelta( minutes=2**self.invalid_token_count) return False elif token_value == -2: if show_result: print('OLD_TOKEN') return True else: if show_result: print('TOKEN_VALID', ' | Value:', token_value) if token_count > self.count or token_value == OPAYGOShared.COUNTER_SYNC_VALUE: self.count = token_count self.used_counts = OPAYGODecoder.update_used_counts( self.used_counts, token_value, token_count, token_type) self.invalid_token_count = 0 self._update_device_status_from_token_value( token_value, token_type) return True
def _update_device_status_from_extended_token(self, token): if self.token_entry_blocked_until > datetime.now( ) and self.waiting_period_enabled: print('TOKEN_ENTRY_BLOCKED') token_value, token_count = OPAYGODecoder.get_activation_value_count_from_extended_token( token) if token_value is None: print('TOKEN_INVALID') self.invalid_token_count += 1 self.token_entry_blocked_until = datetime.now() + timedelta( minutes=2**self.invalid_token_count) else: print('Special token entered, value: ' + str(token_value))
def _update_device_status_from_token(self, token): if self.token_entry_blocked_until > datetime.now( ) and self.waiting_period_enabled: print('TOKEN_ENTRY_BLOCKED') token_value, token_count, token_type = OPAYGODecoder.get_activation_value_count_and_type_from_token( token=token, starting_code=self.starting_code, key=self.key, last_count=self.count, restricted_digit_set=self.restricted_digit_set) if token_value is None: print('TOKEN_INVALID') self.invalid_token_count += 1 self.token_entry_blocked_until = datetime.now() + timedelta( minutes=2**self.invalid_token_count) else: self.invalid_token_count = 0 self.count = token_count self._update_device_status_from_token_value( token_value, token_type)
device_starting_code = 123456789 raise Exception("Please change the key and starting code and remove this exception. ") device_last_count = 4 days_to_activate = 7 if __name__ == '__main__': print('Generating code for device with key '+device_key_hex+' and starting code '+str(device_starting_code)+'. ') print('The code will have the count (number of codes generated before) of '+str(device_last_count)+'. ') print('The code will contain ' + str(days_to_activate) + ' days of activation. ') new_count, token = OPAYGOEncoder.generate_standard_token( starting_code=device_starting_code, key=codecs.decode(device_key_hex, 'hex'), value=days_to_activate, count=device_last_count, restricted_digit_set=False, mode=OPAYGOShared.TOKEN_TYPE_ADD_TIME ) print(token) value, count, type = OPAYGODecoder.get_activation_value_count_and_type_from_token( starting_code=device_starting_code, key=codecs.decode(device_key_hex, 'hex'), token=token, last_count=device_last_count ) print(value, count, type)