Esempio 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)
    except Exception as err:
        logger.error(f"Failed to open KV storage interface, Exiting 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:
        logger.error("Failed to execute boot time flow, Exiting SGX Enclave manager...")
        exit(1)

    try:
        sleep_interval = int(config["EnclaveManager"]["sleep_interval"])
    except:
        logger.error("Failed to get sleep interval from config file. setting sleep interval to 10 secs")
        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)
Esempio 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 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 SGX Enclave manager: {err}")
        exit(1)

    # Binding with ZMQ Port
    try:
        context = zmq.Context()
        socket = context.socket(zmq.REP)
        ZMQ_PORT = config.get("Listener")["zmq_port"]
        logger.info("This is the ZMQ_PORT")
        logger.info(ZMQ_PORT)
        socket.bind("tcp://*:" + ZMQ_PORT)
    except Exception:
        logger.exception("Failed to bind socket")

    try:
        while True:
            # Wait for the next request
            message = socket.recv()
            logger.info("Received request at enclave manager: %s" % message)
            response = enclave_manager.process_work_orders(kv_helper, message)
            logger.info("enclave completed processing.sending back response")
            socket.send_string(response)
    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)
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:
        if config["KvStorage"].get("remote_url") is None:
            storage_path = TCFHOME + '/' + config['KvStorage']['StoragePath']
            storage_size = config['KvStorage']['StorageSize']
            kv_helper = KvStorage()
            if not kv_helper.open(storage_path, storage_size):
                logger.error("Failed to open KV Storage DB")
                sys.exit(-1)
            logger.info("employ the local LMDB")
        else:
            database_url = config["KvStorage"]["remote_url"]
            logger.info(f"connect to remote LMDB @{database_url}")
            kv_helper = LMDBHelperProxy(database_url)
    except:
        logger.error(
            "Failed to open KV storage interface, Exiting SGX Enclave manager..."
        )
        exit(1)

    try:
        logger.info(
            "----------------------- Starting Boot time flow -----------------------"
        )
        enclave_manager.manager_on_boot(kv_helper)
        logger.info(
            "----------------------- Boot time flow Complete -----------------------"
        )
    except:
        logger.error(
            "Failed to execute boot time flow, Exiting SGX Enclave manager...")
        exit(1)

    try:
        sleep_interval = int(config["EnclaveManager"]["sleep_interval"])
    except:
        logger.error(
            "Failed to get sleep interval from config file. setting sleep interval to 10 secs"
        )
        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:
        logger.error(
            "Error while processing work-order. Shutting down enclave manager")
        exit(1)