def init_with_bundle(self, info): """ Init the peer with given info dict :param info: Dict including all info, e.g., endpoint, grpc option :return: True or False """ try: self._endpoint = info['url'] self._grpc_options = info['grpcOptions'] self._tls_ca_certs_path = info['tlsCACerts'] if 'clientKey' in info: self._client_key_path = info['clientKey']['path'] if 'clientCert' in info: self._client_cert_path = info['clientCert']['path'] self._ssl_target_name = self._grpc_options[ 'grpc.ssl_target_name_override'] self._channel = create_grpc_channel( self._endpoint, handle_key_type(self._tls_ca_certs_path), self._client_key_path, self._client_cert_path, opts=[(opt, value) for opt, value in self._grpc_options.items()]) self._endorser_client = peer_pb2_grpc.EndorserStub(self._channel) self._discovery_client = protocol_pb2_grpc.DiscoveryStub( self._channel) self._event_client = events_pb2_grpc.DeliverStub(self._channel) except KeyError as e: _logger.error(e) return False return True
def set_tls_client_cert_and_key(self, client_key_file=None, client_cert_file=None): """Set tls client's cert and key for mutual tls :param client_key_file: file path for Private key used for TLS when making client connections, defaults to None :type client_key_file: str :param client_cert_file: file path for X.509 certificate used for TLS when making client connections, defaults to None :type client_cert_file: str :return: set success value :rtype: bool """ try: self._client_key_path = client_key_file self._client_cert_path = client_cert_file self._channel = create_grpc_channel( self._endpoint, handle_key_type(self._tls_ca_certs_path), handle_key_type(self._client_key_path), handle_key_type(self._client_cert_path), opts=[(opt, value) for opt, value in self._grpc_options.items()]) self._endorser_client = peer_pb2_grpc.EndorserStub(self._channel) self._discovery_client = protocol_pb2_grpc.DiscoveryStub( self._channel) self._event_client = events_pb2_grpc.DeliverStub(self._channel) except Exception: return False return True
def __init__(self, name='peer', endpoint=DEFAULT_PEER_ENDPOINT, tls_ca_cert_file=None, client_key_file=None, client_cert_file=None, opts=None): """ :param endpoint: Endpoint of the peer's gRPC service :param tls_ca_cert_file: file path of tls root ca's certificate :param client_key: file path for Private key used for TLS when making client connections :param client_cert: file path for X.509 certificate used for TLS when making client connections :param opts: optional params """ self._name = name self._lock = threading.RLock() self._channels = [] self._endpoint = endpoint if opts: self._grpc_options = {key: value for (key, value) in opts} else: self._grpc_options = dict() self._ssl_target_name = None self._tls_ca_certs_path = tls_ca_cert_file self._client_key_path = client_key_file self._client_cert_path = client_cert_file self._channel = create_grpc_channel(self._endpoint, tls_ca_cert_file, client_key_file, client_cert_file, opts) self._endorser_client = peer_pb2_grpc.EndorserStub(self._channel) self._discovery_client = protocol_pb2_grpc.DiscoveryStub(self._channel) self._event_client = events_pb2_grpc.DeliverStub(self._channel)
def set_tls_client_cert_and_key(self, client_key_file=None, client_cert_file=None): """Set tls client's cert and key for mutual tls Args: client_key (str): file path for Private key used for TLS when making client connections client_cert (str): file path for X.509 certificate used for TLS when making client connections Returns: bool: set success value """ try: self._client_key_path = client_key_file self._client_cert_path = client_cert_file self._channel = create_grpc_channel( self._endpoint, self._tls_ca_certs_path, self._client_key_path, self._client_cert_path, opts=[(opt, value) for opt, value in self._grpc_options.items()]) self._endorser_client = peer_pb2_grpc.EndorserStub(self._channel) self._discovery_client = protocol_pb2_grpc.DiscoveryStub( self._channel) self._event_client = events_pb2_grpc.DeliverStub(self._channel) except Exception: return False return True