def _GetContractSecret(self, contracttxnid): """ Retrieve or create the secret for a particular contract, returned in raw format """ file_secrets = dict() with open(self.secrets_file_path, "r") as f: for line in f: key, val = line.partition(":")[::2] file_secrets[key.strip()] = val.strip() # If secret already exists, return it, otherwise create, store, and return a new secret if contracttxnid in file_secrets: secret = file_secrets[contracttxnid] logger.debug('Secret for contract %s found', contracttxnid) else: secret = pcrypto.byte_array_to_hex(pcrypto.SKENC_GenerateKey()) file_secrets[contracttxnid] = secret logger.debug('Creating new Secret for contract %s', contracttxnid) with open(self.secrets_file_path, "w") as f: for key in file_secrets: f.write(key + ' : ' + file_secrets[key] + "\n") return secret
def __init__(self, operation, request_originator_keys, contract, **kwargs): if not self.__ops__[operation]: raise ValueError('invalid operation') self.operation = operation self.contract_id = contract.contract_id self.creator_id = contract.creator_id self.enclave_service = kwargs.get('enclave_service') if self.enclave_service == 'random': enclave_id = random.choice(list(contract.enclave_map.keys())) try: #use the eservice database to get the client einfo = eservice_db.get_by_enclave_id(enclave_id) self.enclave_service = einfo.client except Exception as e: raise Exception( 'failed to get enclave client using database: %s', str(e)) self.encrypted_state_encryption_key = contract.get_state_encryption_key( self.enclave_service.enclave_id) self.originator_keys = request_originator_keys self.make_channel_keys() self.session_key = crypto.SKENC_GenerateKey() self.contract_code = contract.contract_code self.contract_state = contract.contract_state self.message = ContractMessage(self.originator_keys, self.channel_id, **kwargs) self.replication_params = contract.replication_params self.request_number = ContractRequest.__request_number__ ContractRequest.__request_number__ += 1
def __init__(self, encryption_key = None, hash_identity = None) : """initialize the key value store encryption_key -- base64 encoded AES encryption key hash_identity -- base64 encoded hash of the root block of the kv store """ if not __block_store_initialized__ : KeyValueInitialize() if encryption_key is None : encryption_key = pcrypto.byte_array_to_base64(pcrypto.SKENC_GenerateKey()) self.encryption_key = encryption_key self.hash_identity = hash_identity self.__handle__ = None
def __init__(self, operation, request_originator_keys, enclave_service, contract, **kwargs) : if not self.__ops__[operation] : raise ValueError('invalid operation') self.operation = operation self.contract_id = contract.contract_id self.creator_id = contract.creator_id self.encrypted_state_encryption_key = contract.get_state_encryption_key(enclave_service.enclave_id) self.enclave_service = enclave_service self.originator_keys = request_originator_keys self.channel_keys = keys.TransactionKeys() self.session_key = crypto.SKENC_GenerateKey() self.contract_code = contract.contract_code self.contract_state = contract.contract_state self.message = ContractMessage(self.originator_keys, self.channel_keys, **kwargs)
def __init__(self, request_originator_keys, contract, **kwargs) : self.contract_id = contract.contract_id self.creator_id = contract.creator_id self.enclave_service = kwargs.get('enclave_service') if self.enclave_service == 'random': enclave_id = random.choice(list(contract.enclave_map.keys())) try: #use the eservice database to get the client einfo = eservice_db.get_by_enclave_id(enclave_id) self.enclave_service = einfo.client except Exception as e: raise Exception('failed to get enclave client using database: %s', str(e)) self.encrypted_state_encryption_key = contract.get_state_encryption_key(self.enclave_service.enclave_id) self.originator_keys = request_originator_keys self.make_channel_keys() self.session_key = crypto.SKENC_GenerateKey() self.replication_params = contract.replication_params self.request_number = ContractRequest.get_request_number()
if (bytearray(plaintext) == bytearray(msg)): logger.debug("Asymmetric encryption/decryption test successful!") else: logger.error("ERROR: Asymmetric encryption/decryption failed.\n") exit(-1) #TEST AES-GCM try: iv = crypto.SKENC_GenerateIV() except Exception as exc: logger.error("ERROR: Symmetric encryption iv generation test failed: ", exc) sys.exit(-1) try: key = crypto.SKENC_GenerateKey() except Exception as exc: logger.error("ERROR: Symmetric encryption key generation test failed: ", exc) sys.exit(-1) try: crypto.SKENC_EncryptMessage(iv, None, msg) logger.error( "ERROR: Symmetric encryption invalid key detection test failed: not detected." ) sys.exit(-1) except Exception as exc: if (type(exc) == ValueError): logger.debug( "Symmetric encryption invalid key detection test successful!")