Example #1
0
    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
Example #2
0
    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
Example #3
0
    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)
Example #4
0
    def __init__(self,
                 name='orderer',
                 endpoint=DEFAULT_ORDERER_ENDPOINT,
                 tls_ca_cert_file=None,
                 client_key_file=None,
                 client_cert_file=None,
                 opts=None):
        """Creates an orderer object.

        Args:
            endpoint (str): The grpc endpoint of the orderer.
            tls_ca_cert_file (str): The tls certificate for the given
                orderer as bytes.
            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
            opts (tuple): Additional grpc config options as
                tuple e.g. ((key, val),).

        """
        self._name = name
        self._endpoint = endpoint
        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._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(self._channel)
Example #5
0
 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']['path']
         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,
             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._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(
             self._channel)
     except KeyError as e:
         print(e)
         return False
     return True
Example #6
0
    def __init__(self, name='orderer', endpoint=DEFAULT_ORDERER_ENDPOINT,
                 tls_ca_cert_file=None, client_key_file=None,
                 client_cert_file=None, opts=None):
        """Creates an orderer object.

        :param name: defaults to 'orderer'
        :type name: str
        :param endpoint: The grpc endpoint of the orderer, defaults to DEFAULT_ORDERER_ENDPOINT
        :type endpoint: str
        :param tls_ca_cert_file: The tls certificate for the given orderer as bytes, defaults to None
        :type tls_ca_cert_file: str
        :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
        :param opts: Additional grpc config options as tuple e.g. ((key, val),), defaults to None
        :type opts: tuple
        """

        self._name = name
        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._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(self._channel)
Example #7
0
    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: Boolean
        """

        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._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(
                self._channel)
        except Exception:
            return False
        return True
Example #8
0
    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
Example #9
0
    def __init__(self,
                 name='peer',
                 endpoint=DEFAULT_PEER_ENDPOINT,
                 tls_cacerts=None,
                 opts=None):
        """

        :param endpoint: Endpoint of the peer's gRPC service
        :param tls_cacerts: file path of tls root ca's certificate
        :param opts: optional params
        """
        self._name = name
        self._lock = threading.RLock()
        self._channels = []
        self._endpoint = endpoint
        self._eh_url = None
        self._grpc_options = dict()
        self._tls_ca_certs_path = None
        self._channel = create_grpc_channel(self._endpoint, tls_cacerts, opts)
        self._endorser_client = peer_pb2_grpc.EndorserStub(self._channel)
Example #10
0
 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']['path']
         self._ssl_target_name = self._grpc_options[
             'ssl-target-name-override']
         self._channel = create_grpc_channel(
             self._endpoint,
             self._tls_ca_certs_path,
             opts=(('grpc.ssl_target_name_override',
                    self._ssl_target_name), ))
         self._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(
             self._channel)
     except KeyError:
         return False
     return True
Example #11
0
    def __init__(self, name='orderer', endpoint=DEFAULT_ORDERER_ENDPOINT,
                 tls_ca_cert_file=None, client_key_file=None,
                 client_cert_file=None, opts=None):
        """
        endpoint: 특정한 grpc 채널 주소, default=DEFAULT_ORDERER_ENDPOINT
        opts: grpc 추가설정 튜플((key, val),)
        """
        self._name = name
        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._orderer_client = ab_pb2_grpc.AtomicBroadcastStub(self._channel)
Example #12
0
 def __init__(self, endpoint=DEFAULT_PEER_ENDPOINT, pem=None, opts=None):
     self._lock = threading.RLock()
     self._channels = []
     self._endpoint = endpoint
     self._endorser_client = peer_pb2_grpc.EndorserStub(
         create_grpc_channel(self._endpoint, pem, opts))