def update(self, param, reset_failcount=True): if "tans" in param: # init tokens with tans tans = param.get("tans").split() tan_dict = {k: v for k, v in enumerate(tans)} # Avoid to generate TANs in the superclass PaperToken, since we get the tans from params param["papertoken_count"] = 0 # Determine the otplen from the TANs if len(tans) > 0: param["otplen"] = len(tans[0]) PaperTokenClass.update(self, param, reset_failcount=reset_failcount) else: # Init token without tans, so we create tans in the superclass PaperToken param["papertoken_count"] = param.get( "tantoken_count") or DEFAULT_COUNT PaperTokenClass.update(self, param, reset_failcount=reset_failcount) # After this creation, the init_details contain the complete list of the TANs tan_dict = self.init_details.get("otps", {}) for tankey, tanvalue in tan_dict.items(): # Get a 4 byte salt from the crypto module salt = geturandom(SALT_LENGTH, hex=True) # Now we add all TANs to the tokeninfo of this token. hashed_tan = hash(tanvalue, salt) self.add_tokeninfo("tan.tan{0!s}".format(tankey), "{0}:{1}".format(salt, hashed_tan))
def test_03_get_init_details(self): db_token = Token.query.filter(Token.serial == self.serial1).first() token = PaperTokenClass(db_token) token.update({}) # if no otpkey was given, an OTP key is created. init_detail = token.get_init_detail() self.assertTrue("otps" in init_detail)
def test_02_class_methods(self): db_token = Token.query.filter(Token.serial == self.serial1).first() token = PaperTokenClass(db_token) info = token.get_class_info() self.assertEqual(info.get("title"), "Paper Token") info = token.get_class_info("title") self.assertEqual(info, "Paper Token")
def test_01_create_token(self): db_token = Token(self.serial1, tokentype="paper") db_token.save() token = PaperTokenClass(db_token) token.update({}) self.assertEqual(token.token.serial, self.serial1) self.assertEqual(token.token.tokentype, "paper") self.assertEqual(token.type, "paper") class_prefix = token.get_class_prefix() self.assertEqual(class_prefix, "PPR") self.assertEqual(token.get_class_type(), "paper")
def update(self, param, reset_failcount=True): if "tans" in param: # init tokens with tans tans = param.get("tans").split() tan_dict = {k: v for k, v in enumerate(tans)} # Avoid to generate TANs in the superclass PaperToken, since we get the tans from params param["papertoken_count"] = 0 # Determine the otplen from the TANs if len(tans) > 0: param["otplen"] = len(tans[0]) PaperTokenClass.update(self, param, reset_failcount=reset_failcount) else: # Init token without tans, so we create tans in the superclass PaperToken param["papertoken_count"] = param.get("tantoken_count") or DEFAULT_COUNT PaperTokenClass.update(self, param, reset_failcount=reset_failcount) # After this creation, the init_details contain the complete list of the TANs tan_dict = self.init_details.get("otps", {}) for tankey, tanvalue in tan_dict.items(): # Get a 4 byte salt from the crypto module salt = geturandom(SALT_LENGTH, hex=True) # Now we add all TANs to the tokeninfo of this token. hashed_tan = binascii.hexlify(hash(tanvalue, salt)) self.add_tokeninfo("tan.tan{0!s}".format(tankey), "{0}:{1}".format(salt, hashed_tan))