def on_get_quote_response(self, agent, url, response): if agent is None: raise Exception("agent deleted while being processed") if response.error: # this is a connection error, retry get quote if isinstance(response.error, IOError) or (isinstance(response.error, tornado.web.HTTPError) and response.error.code == 599): self.process_agent(agent, cloud_verifier_common.CloudAgent_Operational_State.GET_QUOTE_RETRY) else: #catastrophic error, do not continue error = "Unexpected Get Quote response error for cloud agent " + agent['agent_id'] + ", Error: " + str(response.error) logger.critical(error) self.process_agent(agent, cloud_verifier_common.CloudAgent_Operational_State.FAILED) else: try: json_response = json.loads(response.body) # validate the cloud agent response if cloud_verifier_common.process_quote_response(agent, json_response['results']): if agent['provide_V']: self.process_agent(agent, cloud_verifier_common.CloudAgent_Operational_State.PROVIDE_V) else: self.process_agent(agent, cloud_verifier_common.CloudAgent_Operational_State.GET_QUOTE) else: self.process_agent(agent, cloud_verifier_common.CloudAgent_Operational_State.INVALID_QUOTE) cloud_verifier_common.notifyError(agent) # if self.get_q_log_file_base_name is not None and writeTime: # self.get_q_log_file.write("%s\n" % t.secs) # self.get_q_log_file.flush() except Exception as e: logger.exception(e)
async def invoke_get_quote(self, agent, need_pubkey): if agent is None: raise Exception("agent deleted while being processed") params = cloud_verifier_common.prepare_get_quote(agent) partial_req = "1" if need_pubkey: partial_req = "0" res = tornado_requests.request( "GET", "http://%s:%d/quotes/integrity?nonce=%s&mask=%s&vmask=%s&partial=%s" % (agent['ip'], agent['port'], params["nonce"], params["mask"], params['vmask'], partial_req), context=None) response = await res if response.status_code != 200: # this is a connection error, retry get quote if response.status_code == 599: asyncio.ensure_future( self.process_agent( agent, cloud_verifier_common. CloudAgent_Operational_State.GET_QUOTE_RETRY)) else: # catastrophic error, do not continue error = "Unexpected Get Quote response error for cloud agent " + \ agent['agent_id'] + ", Error: " + str(response.status_code) logger.critical(error) asyncio.ensure_future( self.process_agent( agent, cloud_verifier_common. CloudAgent_Operational_State.FAILED)) else: try: json_response = json.loads(response.body) # validate the cloud agent response if cloud_verifier_common.process_quote_response( agent, json_response['results']): if agent['provide_V']: asyncio.ensure_future( self.process_agent( agent, cloud_verifier_common. CloudAgent_Operational_State.PROVIDE_V)) else: asyncio.ensure_future( self.process_agent( agent, cloud_verifier_common. CloudAgent_Operational_State.GET_QUOTE)) else: asyncio.ensure_future( self.process_agent( agent, cloud_verifier_common. CloudAgent_Operational_State.INVALID_QUOTE)) except Exception as e: logger.exception(e)
async def invoke_get_quote(agent, need_pubkey): if agent is None: raise Exception("agent deleted while being processed") params = cloud_verifier_common.prepare_get_quote(agent) partial_req = "1" if need_pubkey: partial_req = "0" version = keylime_api_version.current_version() res = tornado_requests.request( "GET", "http://%s:%d/v%s/quotes/integrity?nonce=%s&mask=%s&vmask=%s&partial=%s&ima_ml_entry=%d" % (agent['ip'], agent['port'], version, params["nonce"], params["mask"], params['vmask'], partial_req, params['ima_ml_entry']), context=None) response = await res if response.status_code != 200: # this is a connection error, retry get quote if response.status_code == 599: asyncio.ensure_future(process_agent(agent, states.GET_QUOTE_RETRY)) else: # catastrophic error, do not continue logger.critical( "Unexpected Get Quote response error for cloud agent %s, Error: %s", agent['agent_id'], response.status_code) asyncio.ensure_future(process_agent(agent, states.FAILED)) else: try: json_response = json.loads(response.body) # validate the cloud agent response if 'provide_V' not in agent: agent['provide_V'] = True agentAttestState = get_AgentAttestStates().get_by_agent_id( agent['agent_id']) if cloud_verifier_common.process_quote_response( agent, json_response['results'], agentAttestState): if agent['provide_V']: asyncio.ensure_future( process_agent(agent, states.PROVIDE_V)) else: asyncio.ensure_future( process_agent(agent, states.GET_QUOTE)) else: asyncio.ensure_future( process_agent(agent, states.INVALID_QUOTE)) # store the attestation state store_attestation_state(agentAttestState) except Exception as e: logger.exception(e)