Exemplo n.º 1
0
    def _verify_unique_id_signature(self, verif_key, verif_key_sig):
        """
        Method to get nonce from the worker which shall be used to get a
        unique verification key from the KME

        Parameters :
            @param verif_key - Unique verification key
            @param verif_key_sig - Signature of the key as generated by the KME
        Returns :
            @returns result - 0 or 1 boolean result of verification
        """
        params = {
            "uniqueVerificationKey": verif_key,
            "uniqueVerificationKeySignature": verif_key_sig
        }
        json_request = get_request_json("VerifyUniqueIdSignature",
                                        random.randint(0, 100000), params)
        res = 0
        try:
            response = self.zmq_socket.send_request_zmq(
                json.dumps(json_request))
            res = json.loads(response)["verification_result"]
        except Exception as ex:
            logger.error("Exception while sending data over ZMQ:" + str(ex))
        return res
Exemplo n.º 2
0
    def _signup_worker(self, unique_verif_key):
        """
        Signup worker ky sending signup request to worker.

        Parameters:
            @param unique_verif_key - Unique verification key obtained from
            the KME
        Returns:
            @returns worker_signup_json - Signup details of worker after signup
        """
        params = {"uniqueVerificationKey": unique_verif_key}
        json_request = get_request_json("ProcessWorkerSignup",
                                        random.randint(0, 100000), params)
        try:
            # Send signup request to Graphene worker
            worker_signup = self.zmq_socket.send_request_zmq(
                json.dumps(json_request))
        except Exception as ex:
            logger.error("Exception while sending data over ZMQ:" + str(ex))
            return None

        if worker_signup is None:
            logger.error("Unable to get Graphene worker signup data")
            return None
        logger.debug("Graphene signup result {}".format(worker_signup))
        try:
            worker_signup_json = json.loads(worker_signup)
        except Exception as ex:
            logger.error("Exception during signup json creation:" + str(ex))
            return None
        return worker_signup_json
Exemplo n.º 3
0
    def PreProcessWorkOrder(self, **params):
        """
        RPC method registered with the KME listener to pre-process a
        work order request.

        Parameters :
            @param params - variable-length argument list
        Returns :
            @returns response - A jrpc response
        """
        wo_request = get_request_json("PreProcessWorkOrder",
                                      random.randint(0, 100000))
        wo_request["params"] = params
        wo_response = self._execute_work_order(json.dumps(wo_request), "")
        wo_response_json = json.loads(wo_response)

        if "result" in wo_response_json:
            return wo_response_json["result"]
        else:
            logger.error("Could not preprocess work order at KME")
            # For all negative cases, response should have an error field.
            # Hence constructing JSONRPC error response with
            # error code and message mapped to KME enclave response
            err_code = wo_response_json["error"]["code"]
            err_msg = wo_response_json["error"]["message"]
            data = {
                "workOrderId": wo_response_json["error"]["data"]["workOrderId"]
            }
            raise JSONRPCDispatchException(err_code, err_msg, data)
Exemplo n.º 4
0
    def GetUniqueVerificationKey(self, **params):
        """
        RPC method registered with the KME listener to generate an
        unique verification key before a WPE registration.

        Parameters :
            @param params - variable-length argument list
        Returns :
            @returns response - A jrpc response
        """
        logger.info("in kme_enclave_manager.py GetUniqueVerificationKey")
        try:
            wo_request = get_request_json("GetUniqueVerificationKey",
                                          random.randint(0, 100000))
            wo_request["params"] = params
            wo_response = self._execute_work_order(json.dumps(wo_request), "")
            wo_response_json = json.loads(wo_response)

            data = {"workOrderId": wo_request["params"]["workOrderId"]}

            if "result" in wo_response_json:
                return wo_response_json["result"]
            else:
                logger.error("Could not get UniqueVerificationKey - %s",
                             wo_response_json)
                # For all negative cases, response should have an error field.
                # Hence constructing JSONRPC error response with
                # error code and message mapped to KME enclave response
                err_code = wo_response_json["error"]["code"]
                err_msg = wo_response_json["error"]["message"]
                raise JSONRPCDispatchException(err_code, err_msg, data)
        except Exception as e:
            raise JSONRPCDispatchException(WorkOrderStatus.FAILED, str(e),
                                           data)
Exemplo n.º 5
0
    def _create_signup_data(self):
        """
        Creates Graphene worker signup data.

        Returns :
            signup_data: Signup data containining information of worker
                         like public encryption and verification key,
                         worker quote, mrencalve.
                         In case of error return None.
        """
        json_request = get_request_json("ProcessWorkerSignup",
                                        random.randint(0, 100000))
        try:
            # Send signup request to Graphene worker
            worker_signup = self.zmq_socket.send_request_zmq(
                json.dumps(json_request))
        except Exception as ex:
            logger.error("Exception while sending data over ZMQ:" + str(ex))
            return None

        if worker_signup is None:
            logger.error("Unable to get Graphene worker signup data")
            return None
        logger.debug("Graphene signup result {}".format(worker_signup))
        try:
            worker_signup_json = json.loads(worker_signup)
        except Exception as ex:
            logger.error("Exception during signup json creation:" + str(ex))
            return None
        # Create Signup Graphene object
        signup_data = GrapheneEnclaveInfo(self._config, worker_signup_json)
        return signup_data
Exemplo n.º 6
0
    def _generate_nonce(self):
        """
        Generate a nonce that is supposed to be used by the KME to generate
        the unique verification key

        Returns:
            @returns nonce - A 32 character nonce generated by worker
        """
        nonce = None
        json_request = get_request_json("GenerateNonce",
                                        random.randint(0, 100000))
        try:
            # Get a nonce generated at Graphene worker
            response = self.zmq_socket.send_request_zmq(
                json.dumps(json_request))
            nonce = json.loads(response)["nonce"]
        except Exception as ex:
            logger.error("Exception while sending data over ZMQ:" + str(ex))
        return nonce
Exemplo n.º 7
0
    def RegisterWorkOrderProcessor(self, **params):
        """
        RPC method registered with the KME listener to register a WPE
        with a KME.

        Parameters :
            @param params - variable-length argument list
        Returns :
            @returns response - A jrpc response
        """
        wo_request = get_request_json("RegisterWorkOrderProcessor",
                                      random.randint(0, 100000))
        wo_request["params"] = params
        wo_response = self._execute_work_order(json.dumps(wo_request), "")
        wo_response_json = json.loads(wo_response)

        if "result" in wo_response_json:
            return wo_response_json["result"]
        else:
            logger.error("Could not register WPE")
            return wo_response_json
Exemplo n.º 8
0
    def _execute_wo_in_trusted_enclave(self, input_json_str):
        """
        Submits workorder request to Graphene Worker and retrieves
        the response

        Parameters :
            input_json_str: JSON formatted str of the request to execute
        Returns :
            JSON response received from Graphene worker.
        """
        json_request = get_request_json("ProcessWorkOrder",
                                        random.randint(0, 100000),
                                        input_json_str)
        result = self.zmq_socket.send_request_zmq(json.dumps(json_request))
        if result is None:
            logger.error("Graphene work order execution error")
            return None
        try:
            json_response = json.loads(result)
        except Exception as ex:
            logger.error("Error loading json execution result: " + str(ex))
            return None
        return json_response