Exemplo n.º 1
0
    def get(self):
        """This method handles the GET requests to retrieve status on agents from the Cloud Verifier.

        Currently, only agents resources are available for GETing, i.e. /agents. All other GET uri's
        will return errors. Agents requests require a single agent_id parameter which identifies the
        agent to be returned. If the agent_id is not found, a 404 response is returned.  If the agent_id
        was not found, it either completed successfully, or failed.  If found, the agent_id is still polling
        to contact the Cloud Agent.
        """
        session = self.make_session(engine)
        rest_params = common.get_restful_params(self.request.uri)
        if rest_params is None:
            common.echo_json_response(
                self, 405, "Not Implemented: Use /agents/ interface")
            return

        if "agents" not in rest_params:
            common.echo_json_response(self, 400, "uri not supported")
            logger.warning('GET returning 400 response. uri not supported: ' +
                           self.request.path)
            return

        agent_id = rest_params["agents"]

        if agent_id is not None:
            try:
                agent = session.query(VerfierMain).filter_by(
                    agent_id=agent_id).one_or_none()
            except SQLAlchemyError as e:
                logger.error(f'SQLAlchemy Error: {e}')

            if agent is not None:
                response = cloud_verifier_common.process_get_status(agent)
                common.echo_json_response(self, 200, "Success", response)
            else:
                common.echo_json_response(self, 404, "agent id not found")
        else:
            json_response = session.query(VerfierMain.agent_id).all()
            common.echo_json_response(self, 200, "Success",
                                      {'uuids': json_response})
            logger.info('GET returning 200 response for agent_id list')
Exemplo n.º 2
0
    def get(self):
        """This method handles the GET requests to retrieve status on agents from the Cloud Verifier.

        Currently, only agents resources are available for GETing, i.e. /agents. All other GET uri's
        will return errors. Agents requests require a single agent_id parameter which identifies the
        agent to be returned. If the agent_id is not found, a 404 response is returned.  If the agent_id
        was not found, it either completed successfully, or failed.  If found, the agent_id is still polling
        to contact the Cloud Agent.
        """
        print("receive a get")
        rest_params = common.get_restful_params(self.request.uri)
        if rest_params is None:
            common.echo_json_response(
                self, 405, "Not Implemented: Use /agents/ interface")
            return

        if "agents" not in rest_params:
            common.echo_json_response(self, 400, "uri not supported")
            logger.warning('GET returning 400 response. uri not supported: ' +
                           self.request.path)
            return

        agent_id = rest_params["agents"]

        if agent_id is not None:
            agent = self.db.get_agent(agent_id)
            if agent != None:
                response = cloud_verifier_common.process_get_status(agent)
                common.echo_json_response(self, 200, "Success", response)
                #logger.info('GET returning 200 response for agent_id: ' + agent_id)

            else:
                #logger.info('GET returning 404 response. agent id: ' + agent_id + ' not found.')
                common.echo_json_response(self, 404, "agent id not found")
        else:
            # return the available keys in the DB
            json_response = self.db.get_agent_ids()
            common.echo_json_response(self, 200, "Success",
                                      {'uuids': json_response})
            logger.info('GET returning 200 response for agent_id list')
    async def get(self):
        """This method handles the GET requests for Tenant verifiers to talk with Provider verifiers 
        """
        rest_params = common.get_restful_params(self.request.uri)

        global tree

        if rest_params is None:
            common.echo_json_response(
                self, 405, "Not Implemented: Use /agents/interface")
            return

        if "agents" in rest_params:
            agent_id = rest_params["agents"]

            if agent_id is not None:
                agent = self.db.get_agent(agent_id)
                if agent != None:
                    response = cloud_verifier_common.process_get_status(agent)
                    common.echo_json_response(self, 200, "Success", response)
                else:
                    #logger.info('GET returning 404 response. agent id: ' + agent_id + ' not found.')
                    common.echo_json_response(self, 404, "agent id not found")
            else:
                # return the available keys in the DB
                json_response = self.db.get_agent_ids()
                common.echo_json_response(self, 200, "Success",
                                          {'uuids': json_response})
                logger.info('GET returning 200 response for agent_id list')
        elif "verifier" in rest_params:

            partial_req = "1"  # don't need a pub key
            agent = self.db.get_agent_ids()
            new_agent = self.db.get_agent(agent[0])

            try:
                await nonce_col.put(rest_params["nonce"])
            except Exception as e:
                print('error: ', e)

            new_agent['quote_col'].append(rest_params["nonce"])

            self.db.update_all_agents('quote_col', new_agent['quote_col'])

            #Simulate busy TPM with async sleep function to allow testing of quote batching functionality
            await asyncio.sleep(10)

            try:
                agent = self.db.get_agent_ids()
                new_agent2 = self.db.get_agent(agent[0])

                tree = MerkleTree([], hashfunc)
                logger.info("Concurrent Nonces: " + str(nonce_col.qsize()))
                for nonce in range(nonce_col.qsize()):
                    temp = nonce_col.get()
                    t = await temp
                    logger.debug(t)
                    tree.append(t)
                    await nonce_col.put(t)
                logger.info("Making Merkle Tree in Provider Verifier")
                logger.info(beautify(tree))
                nonce_proof = tree.get_proof(rest_params['nonce'])

            except Exception as e:
                print('error:  ', e)

            rest_params['nonce'] = tree.merkle_root
            url = "http://%s:%d/quotes/integrity?nonce=%s&mask=%s&vmask=%s&partial=%s" % (
                new_agent['ip'], new_agent['port'], rest_params["nonce"],
                rest_params["mask"], rest_params['vmask'], partial_req)

            res = tornado_requests.request("GET", url, context=None)
            response = await res

            json_response = json.loads(response.body)

            json_response_result = json_response["results"]

            json_response_result['nonce_proof'] = proof_to_string(nonce_proof)

            json_response_result['merkle_head'] = tree.merkle_root

            logger.debug("To string of Nonce Proof",
                         json_response_result['merkle_head'])

            common.echo_json_response(self, 200, "Success",
                                      json_response_result)
        else:
            common.echo_json_response(self, 400, "uri not supported")
            logger.warning('GET returning 400 response. uri not supported: ' +
                           self.request.path)