def offlinerefill(): """ This endpoint allows to fetch new offline OTP values for a token, that is already offline. According to the definition it will send the missing OTP values, so that the client will have as much otp values as defined. :param serial: The serial number of the token, that should be refilled. :param refilltoken: The authorization token, that allows refilling. :param pass: the last password (maybe password+OTP) entered by the user :return: """ result = False otps = {} serial = getParam(request.all_data, "serial", required) refilltoken = getParam(request.all_data, "refilltoken", required) password = getParam(request.all_data, "pass", required) tokenobj_list = get_tokens(serial=serial) if len(tokenobj_list) != 1: raise ParameterError("The token does not exist") else: tokenobj = tokenobj_list[0] machine_defs = list_token_machines(serial) # check if is still an offline token: for mdef in machine_defs: if mdef.get("application") == "offline": # check refill token: if tokenobj.get_tokeninfo("refilltoken") == refilltoken: # refill otps = MachineApplication.get_refill( tokenobj, password, mdef.get("options")) refilltoken = MachineApplication.generate_new_refilltoken( tokenobj) response = send_result(True) content = json.loads(response.data) content["auth_items"] = { "offline": [{ "refilltoken": refilltoken, "response": otps }] } response.data = json.dumps(content) return response raise ParameterError( "Token is not an offline token or refill token is incorrect")
def offlinerefill(): """ This endpoint allows to fetch new offline OTP values for a token, that is already offline. According to the definition it will send the missing OTP values, so that the client will have as much otp values as defined. :param serial: The serial number of the token, that should be refilled. :param refilltoken: The authorization token, that allows refilling. :param pass: the last password (maybe password+OTP) entered by the user :return: """ result = False otps = {} serial = getParam(request.all_data, "serial", required) refilltoken = getParam(request.all_data, "refilltoken", required) password = getParam(request.all_data, "pass", required) tokenobj_list = get_tokens(serial=serial) if len(tokenobj_list) != 1: raise ParameterError("The token does not exist") else: tokenobj = tokenobj_list[0] machine_defs = list_token_machines(serial) # check if is still an offline token: for mdef in machine_defs: if mdef.get("application") == "offline": # check refill token: if tokenobj.get_tokeninfo("refilltoken") == refilltoken: # refill otps = MachineApplication.get_refill(tokenobj, password, mdef.get("options")) refilltoken = MachineApplication.generate_new_refilltoken(tokenobj) response = send_result(True) content = json.loads(response.data) content["auth_items"] = {"offline": [{"refilltoken": refilltoken, "response": otps}]} response.data = json.dumps(content) return response raise ParameterError("Token is not an offline token or refill token is incorrect")
def test_05_list_machines_for_token(self): machinelist = list_token_machines(self.serial) self.assertEqual(len(machinelist), 1) self.assertEqual(machinelist[0].get("resolver"), "reso1") self.assertEqual(machinelist[0].get("machine_id"), "192.168.0.1")