def LocalMain(config) : # enclave configuration is in the 'EnclaveConfig' table try : logger.debug('initialize the enclave') pdo_enclave_helper.initialize_enclave(config.get('EnclaveModule')) except Error as e : logger.exception('failed to initialize enclave; %s', e) sys.exit(-1) try : enclave_config = config.get('EnclaveData', {}) ledger_config = config.get('Sawtooth', {}) key_config = config.get('Key', {}) try : key_file = key_config['FileName'] key_path = key_config['SearchPath'] txn_keys = keys.TransactionKeys.read_from_file(key_file, search_path = key_path) except Exception as e : logger.error('unable to load transaction keys; %s', str(e)) sys.exit(-1) enclave = LoadEnclaveData(enclave_config, txn_keys) if enclave is None : enclave = CreateEnclaveData(enclave_config, ledger_config, txn_keys) assert enclave enclave.verify_registration(ledger_config) except Error as e: logger.exception('failed to initialize enclave; %s', e) sys.exit(-1) logger.info('start service for enclave\n%s', enclave.verifying_key) RunEnclaveService(config, enclave)
def LocalMain(config): ledger_config = config['Ledger'] ledger_type = ledger_config.get('LedgerType', os.environ.get('PDO_LEDGER_TYPE')) # load and initialize the enclave library try: logger.debug('initialize the enclave') pdo_enclave_helper.initialize_enclave(config) except Exception as e: logger.exception('failed to initialize enclave; %s', e) sys.exit(-1) # create the sawtooth transaction keys needed to register the enclave try: key_config = config['Key'] key_file = key_config['FileName'] key_path = key_config['SearchPath'] txn_keys = keys.read_transaction_keys_from_file(key_file, search_path = key_path,\ ledger_type = ledger_type) except KeyError as ke: logger.error('missing configuration for %s', str(ke)) sys.exit(-1) except Exception as e: logger.error('unable to load transaction keys; %s', str(e)) sys.exit(-1) # create or load the enclave data try: enclave_config = config['EnclaveData'] enclave = LoadEnclaveData(enclave_config, txn_keys) if enclave is None: enclave = CreateEnclaveData(enclave_config, ledger_config, txn_keys) assert enclave enclave.verify_registration(ledger_config) except KeyError as ke: logger.error('missing configuration for %s', str(ke)) sys.exit(-1) except Exception as e: logger.error('failed to initialize the enclave; %s', str(e)) sys.exit(-1) # set up the handlers for the enclave service try: StartEnclaveService(config, enclave) except Exception as e: logger.exception('failed to start the enclave service; %s', e) sys.exit(-1) # and run the service RunService()
def CreateAndRegisterEnclave(config): global enclave global txn_dependencies # if we are using the eservice then there is nothing to register since # the eservice has already registered the enclave if use_eservice: try: eservice_url = random.choice( config['Service']['EnclaveServiceURLs']) logger.info('use enclave service at %s', eservice_url) enclave = eservice_helper.EnclaveServiceClient(eservice_url) return enclave except Exception as e: logger.error('failed to contact enclave service; %s', str(e)) sys.exit(-1) enclave_config = config.get('EnclaveModule') ledger_config = config.get('Sawtooth') try: enclave_helper.initialize_enclave(enclave_config) enclave = enclave_helper.Enclave.create_new_enclave() except Exception as e: logger.error('failed to initialize the enclave; %s', str(e)) sys.exit(-1) try: if use_ledger: txnid = enclave.register_enclave(ledger_config) txn_dependencies.append(txnid) logger.info('enclave registration successful') enclave.verify_registration(ledger_config) logger.info('verified enclave registration') else: logger.debug('no ledger config; skipping enclave registration') except Exception as e: logger.error('failed to register the enclave; %s', str(e)) ErrorShutdown() return enclave
def CreateAndRegisterEnclave(config): global enclave global txn_dependencies if use_eservice: eservice_url = config.get('eservice-url') logger.info('use enclave service at %s', eservice_url) enclave = eservice_helper.EnclaveServiceClient(eservice_url) return enclave enclave_config = config.get('EnclaveModule') ledger_config = config.get('Sawtooth') try: enclave_helper.initialize_enclave(enclave_config, enclave_type="intkey") enclave = enclave_helper.Enclave.create_new_enclave() except Exception as e: logger.error('failed to initialize the enclave; %s', str(e)) sys.exit(-1) try: if use_ledger: txnid = enclave.register_enclave(ledger_config) txn_dependencies.append(txnid) logger.info('enclave registration successful') enclave.verify_registration(ledger_config) logger.info('verified enclave registration') else: logger.info('no ledger config; skipping enclave registration') except Exception as e: logger.error('failed to register the enclave; %s', str(e)) sys.exit(-1) return enclave
contract_id = crypto.byte_array_to_hex(crypto.random_bit_string(256))[:32] try : block_store_file = config['StorageService']['BlockStore'] block_store = BlockStoreManager(block_store_file, create_block_store=True) except Exception as e : logger.error('failed to initialize the block store; %s', str(e)) ErrorShutdown() # ----------------------------------------------------------------- # ----------------------------------------------------------------- plogger.setup_loggers({'LogLevel' : options.loglevel.upper(), 'LogFile' : options.logfile}) # ----------------------------------------------------------------- # ----------------------------------------------------------------- enclave_helper.initialize_enclave(config) enclave_client = enclave_helper.Enclave.create_new_enclave() enclave_client.attach_block_store(block_store) # ----------------------------------------------------------------- logger.info('test correct inputs') # ----------------------------------------------------------------- def test_secrets(secret_count) : global enclave_client global contract_id global contract_creator_id logger.info('test with secret count %d', secret_count) enclave_keys = enclave_client.enclave_keys secret_list = secret_helper.create_secret_list(
def CreateAndRegisterEnclave(config): """ creates and registers an enclave IMPORTANT: if an eservice is available it will be used, otherwise, the code interfaces directly with the python/swig wrapper in the eservice code """ global enclave global txn_dependencies ledger_config = config.get('Sawtooth') interpreter = config['Contract']['Interpreter'] # if we are using the eservice then there is nothing to register since # the eservice has already registered the enclave if use_eservice: enclaveclients = [] try: for url in config['Service']['EnclaveServiceURLs']: einfo = db.add_by_url(ledger_config, url) if einfo is None: logger.error("unable to connect to enclave service; %s", url) sys.exit(-1) if einfo.client.interpreter != interpreter: logger.error( 'contract and enclave expect different interpreters; <%s> != <%s>', einfo.client.interpreter, interpreter) sys.exit(-1) enclaveclients.append(einfo.client) except Exception as e: logger.error('unable to setup enclave services; %s', str(e)) sys.exit(-1) return enclaveclients # not using an eservice so build the local enclave try: global block_store block_store_file = config['StorageService']['BlockStore'] block_store = BlockStoreManager(block_store_file, create_block_store=True) except Exception as e: block_store.close() logger.error('failed to initialize the block store; %s', str(e)) sys.exit(-1) try: enclave_helper.initialize_enclave(config) enclave = enclave_helper.Enclave.create_new_enclave() except Exception as e: logger.exception('failed to initialize the enclave; %s', str(e)) block_store.close() sys.exit(-1) if enclave.interpreter != interpreter: logger.error( 'contract and enclave expect different interpreters; %s != %s', enclave.interpreter, interpreter) ErrorShutdown() try: enclave.attach_block_store(block_store) except Exception as e: logger.exception('failed to attach block store; %s', str(e)) ErrorShutdown() try: ledger_config = config.get('Sawtooth') if use_ledger: txnid = enclave.register_enclave(ledger_config) logger.info('enclave registration successful') enclave.verify_registration(ledger_config) logger.info('verified enclave registration') else: logger.debug('no ledger config; skipping enclave registration') except Exception as e: logger.exception('failed to register the enclave; %s', str(e)) ErrorShutdown() return [enclave]
sys.exit(-1) contract_creator_keys = keys.ServiceKeys.create_service_keys() contract_creator_id = contract_creator_keys.identity contract_id = crypto.byte_array_to_hex(crypto.random_bit_string(256))[:32] # ----------------------------------------------------------------- # ----------------------------------------------------------------- plogger.setup_loggers({ 'LogLevel': options.loglevel.upper(), 'LogFile': options.logfile }) # ----------------------------------------------------------------- # ----------------------------------------------------------------- enclave_helper.initialize_enclave(config.get('EnclaveModule')) enclave_client = enclave_helper.Enclave.create_new_enclave() # ----------------------------------------------------------------- logger.info('test correct inputs') # ----------------------------------------------------------------- def test_secrets(secret_count): global enclave_client global contract_id global contract_creator_id logger.info('test with secret count %d', secret_count) enclave_keys = enclave_client.enclave_keys