Exemplo n.º 1
0
def start_enclave_manager(config):
    """
    Instantiate KvStorage, Execute boot flow and run time flow
    """
    global enclave_data
    if config.get("KvStorage") is None:
        logger.error("Kv Storage path is missing")
        sys.exit(-1)
    try:
        logger.debug("initialize the enclave")
        # Extended measurements is a list of enclave basename and
        # enclave measurement
        extended_measurements = \
            enclave_helper.initialize_enclave(config.get("EnclaveModule"))
    except Exception as e:
        logger.exception("failed to initialize enclave; %s", str(e))
        sys.exit(-1)

    logger.info("creating a new enclave")
    enclave_signup_data = create_enclave_signup_data()

    logger.info("initialize enclave_manager")
    enclave_manager = EnclaveManager(config, enclave_signup_data,
                                     extended_measurements)
    logger.info("Enclave manager started")

    try:
        kv_helper = connector.open(config['KvStorage']['remote_url'])
    except Exception as err:
        logger.error("Failed to open KV storage interface; " +
                     "exiting Intel SGX Enclave manager: {err}")
        sys.exit(-1)

    try:
        logger.info("--------------- Starting Boot time flow ----------------")
        enclave_manager.manager_on_boot(kv_helper)
        logger.info("--------------- Boot time flow Complete ----------------")
    except Exception as err:
        logger.error("Failed to execute boot time flow; " +
                     "exiting Intel SGX Enclave manager: {err}")
        exit(1)

    try:
        sleep_interval = int(config["EnclaveManager"]["sleep_interval"])
    except Exception as err:
        logger.error(
            "Failed to get sleep interval from config file. " +
            "Setting sleep interval to 10 seconds: %s", str(err))
        sleep_interval = 10

    try:
        while True:
            # Poll KV storage for new work-order requests and process
            enclave_manager.process_work_orders(kv_helper)
            logger.info("Enclave manager sleeping for %d secs", sleep_interval)
            time.sleep(sleep_interval)
    except Exception as inst:
        logger.error("Error while processing work-order; " +
                     "shutting down enclave manager")
        logger.error("Exception: {} args {} details {}".format(
            type(inst), inst.args, inst))
        exit(1)
Exemplo n.º 2
0
def start_enclave_manager(config):
    """
    Instantiate KvStorage, Execute boot flow and run time flow
    """
    global enclave_data
    if config.get("KvStorage") is None:
        logger.error("Kv Storage path is missing")
        sys.exit(-1)
    try:
        logger.debug("initialize the enclave")
        # Extended measurements is a list of enclave basename and
        # enclave measurement
        extended_measurements = \
            enclave_helper.initialize_enclave(config.get("EnclaveModule"))
    except Exception as e:
        logger.exception("failed to initialize enclave; %s", str(e))
        sys.exit(-1)

    logger.info("creating a new enclave")
    enclave_signup_data = create_enclave_signup_data()

    logger.info("initialize enclave_manager")
    enclave_manager = EnclaveManager(config, enclave_signup_data,
                                     extended_measurements)
    logger.info("Enclave manager started")

    try:
        kv_helper = connector.open(config['KvStorage']['remote_url'])
    except Exception as err:
        logger.error("Failed to open KV storage interface; " +
                     "exiting Intel SGX Enclave manager: {err}")
        sys.exit(-1)

    try:
        logger.info("--------------- Starting Boot time flow ----------------")
        enclave_manager.manager_on_boot(kv_helper)
        logger.info("--------------- Boot time flow Complete ----------------")
    except Exception as err:
        logger.error("Failed to execute boot time flow; " +
                     "exiting Intel SGX Enclave manager: {err}")
        exit(1)

    if int(config["WorkloadExecution"]["sync_workload_execution"]) == 1:
        # Binding with ZMQ Port
        try:
            socket = bind_zmq_socket(config.get("EnclaveManager")["zmq_port"])
            logger.info("ZMQ Port hosted by Enclave")
        except Exception as ex:
            logger.exception("Failed to bind socket" +
                             "shutting down enclave manager")
            logger.error("Exception: {} args{} details{}".format(
                type(ex), ex.args, ex))
            exit(1)
        try:
            while True:
                # Wait for the next request
                logger.info("Enclave Manager waiting for next request")
                wo_id = socket.recv()
                wo_id = wo_id.decode()
                logger.info("Received request at enclave manager: %s" % wo_id)
                result = enclave_manager.process_work_order_sync(
                    kv_helper, wo_id)
                if result is None:
                    socket.send_string("Error while processing work order: " +
                                       str(wo_id))
                else:
                    socket.send_string("Work order processed: " + str(wo_id))
        except Exception as inst:
            logger.error("Error while processing work-order; " +
                         "shutting down enclave manager")
            logger.error("Exception: {} args {} details {}".format(
                type(inst), inst.args, inst))
            exit(1)
    else:
        try:
            sleep_interval = int(config["EnclaveManager"]["sleep_interval"])
        except Exception as err:
            logger.error(
                "Failed to get sleep interval from config file. " +
                "Setting sleep interval to 10 seconds: %s", str(err))
            sleep_interval = 10

        try:
            while True:
                # Poll KV storage for new work-order requests and process
                enclave_manager.process_work_orders(kv_helper)
                logger.info("Enclave manager sleeping for %d secs",
                            sleep_interval)
                time.sleep(sleep_interval)
        except Exception as inst:
            logger.error("Error while processing work-order; " +
                         "shutting down enclave manager")
            logger.error("Exception: {} args {} details {}".format(
                type(inst), inst.args, inst))
            exit(1)