def _execute_work_order(self, input_json_str, ext_data=""): """ Submits request to KME and retrieves the response Parameters : @param input_json_str - A JSON formatted str of the request @param ext_data - Extended data to pass to trusted code Returns : @returns json_response - A JSON formatted str of the response received from the enclave """ try: logger.info("Request sent to enclave %s", input_json_str) wo_request = work_order_request.SgxWorkOrderRequest( EnclaveType.KME, input_json_str, ext_data) wo_response = wo_request.execute() logger.info("_execute_work_order Done") try: json_response = json.dumps(wo_response, indent=4) logger.info("Response from enclave %s", json_response) except Exception as err: logger.error("ERROR: Failed to serialize JSON; %s", str(err)) except Exception as e: logger.error("failed to execute work order; %s", str(e)) wo_response = dict() wo_response["error"] = dict() wo_response["error"]["code"] = WorkOrderStatus.FAILED wo_response["error"]["message"] = str(e) json_response = json.dumps(wo_response, indent=4) return json_response
def _execute_wo_in_trusted_enclave(self, input_json_str): """ Submits workorder request to Worker enclave and retrieves the response Parameters : input_json_str - A JSON formatted str of the request to execute Returns : json_response - A JSON response received from the enclave. Errors are also wrapped in a JSON str if exceptions have occurred. """ try: pre_proc_output = self._wpe_requester\ .preprocess_work_order(input_json_str, self.encryption_key) if "error" in pre_proc_output: # If error in preprocessing response, skip workorder processing logger.error("Failed to preprocess at WPE enclave manager.") return pre_proc_output wo_request = work_order_request.SgxWorkOrderRequest( EnclaveType.WPE, input_json_str, pre_proc_output) wo_response = wo_request.execute() except Exception as e: logger.error("failed to execute work order; %s", str(e)) wo_response = dict() wo_response["error"] = dict() wo_response["error"]["code"] = WorkOrderStatus.FAILED wo_response["error"]["message"] = str(e) logger.info("unknown enclave type response = %s", wo_response) return wo_response
def _execute_work_order(self, input_json_str, ext_data=""): """ Submits request to KME and retrieves the response Parameters : @param input_json_str - A JSON formatted str of the request @param ext_data - Extended data to pass to trusted code Returns : @returns json_response - A JSON formatted str of the response received from the enclave """ try: logger.info("Request sent to enclave %s", input_json_str) wo_request = work_order_request.SgxWorkOrderRequest( self._config["EnclaveModule"], input_json_str, ext_data) wo_response = wo_request.execute() try: json_response = json.dumps(wo_response, indent=4) logger.info("Response from enclave %s", json_response) except Exception as err: logger.error("ERROR: Failed to serialize JSON; %s", str(err)) except Exception as e: logger.error("failed to execute work order; %s", str(e)) return json_response
def _execute_work_order(self, input_json_str): """ Submits workorder request to Worker enclave and retrieves the response Parameters : input_json_str - A JSON formatted str of the request to execute Returns : json_response - A JSON formatted str of the response received from the enclave. Errors are also wrapped in a JSON str if exceptions have occurred. """ wo_response = dict() try: wo_request = work_order_request.SgxWorkOrderRequest( self._config, input_json_str) wo_response = wo_request.execute() try: json_response = json.dumps(wo_response, indent=4) except Exception as err: wo_response["Response"] = dict() logger.error("ERROR: Failed to serialize JSON; %s", str(err)) wo_response["Response"]["Status"] = WorkOrderStatus.FAILED wo_response["Response"]["Message"] = "Failed to serialize JSON" json_response = json.dumps(wo_response) except Exception as e: wo_response["Response"] = dict() logger.error("failed to execute work order; %s", str(e)) wo_response["Response"]["Status"] = WorkOrderStatus.FAILED wo_response["Response"]["Message"] = str(e) json_response = json.dumps(wo_response) return json_response
def _send_wo_to_process(self, input_json_str, pre_proc_output): """ Send work order request to be processed within enclave. Parameters : input_json_str - A JSON formatted str of the request to execute pre_proc_output - Preprocessing outcome of the work-order request Returns : response - Response as received after work-order execution """ wo_request = work_order_request.SgxWorkOrderRequest( EnclaveType.WPE, input_json_str, pre_proc_output) return wo_request.execute()
def _execute_wo_in_trusted_enclave(self, input_json_str): """ Submits workorder request to Worker enclave and retrieves the response Parameters : input_json_str - A JSON formatted str of the request to execute Returns : json_response - A JSON formatted str of the response received from the enclave. Errors are also wrapped in a JSON str if exceptions have occurred. """ wo_request = work_order_request.SgxWorkOrderRequest( self._config, input_json_str) return wo_request.execute()
def _execute_wo_in_trusted_enclave(self, input_json_str): """ Submits workorder request to Worker enclave and retrieves the response Parameters : input_json_str - A JSON formatted str of the request to execute Returns : json_response - A JSON formatted str of the response received from the enclave. Errors are also wrapped in a JSON str if exceptions have occurred. """ try: wo_request = work_order_request.SgxWorkOrderRequest( EnclaveType.SINGLETON, input_json_str) except Exception as e: logger.exception('Failed to initialize SgxWorkOrderRequest; %s', str(e)) return wo_request.execute()
def _execute_wo_in_trusted_enclave(self, input_json_str): """ Submits workorder request to Worker enclave and retrieves the response Parameters : input_json_str - A JSON formatted str of the request to execute Returns : json_response - A JSON response received from the enclave. Errors are also wrapped in a JSON str if exceptions have occurred. """ pre_proc_output = self._wpe_requester\ .preprocess_work_order(input_json_str, self.encryption_key) if "error" in pre_proc_output: # If error in preprocessing response, skip workorder processing logger.error("Failed to preprocess at WPE enclave manager.") return pre_proc_output wo_request = work_order_request.SgxWorkOrderRequest( self._config.get("EnclaveModule"), input_json_str, pre_proc_output) return wo_request.execute()
def execute_work_order(enclave_data, input_json_str, indent=4): """ Submits workorder request to Worker enclave and retrieves the response """ try: wo_request = work_order_request.SgxWorkOrderRequest( enclave_data, input_json_str) wo_response = wo_request.execute() try: json_response = json.dumps(wo_response, indent=indent) except Exception as err: logger.error("ERROR: Failed to serialize JSON; %s", str(err)) wo_response["Response"]["Status"] = WorkOrderStatus.FAILED wo_response["Response"]["Message"] = "Failed to serialize JSON" json_response = json.dumps(wo_response) except Exception as e: logger.error("failed to execute work order; %s", str(e)) wo_response["Response"]["Status"] = WorkOrderStatus.FAILED wo_response["Response"]["Message"] = str(e) json_response = json.dumps(wo_response) return json_response