def test_string_to_signature(self): with open(self.channel_tx, 'rb') as f: channel_tx = f.read() channel_config = utils.extract_channel_config(channel_tx) client = Client() client.state_store = FileKeyValueStore(self.kv_store_path) orderer_org_admin = get_orderer_org_admin(client) orderer_org_admin_tx_context = \ TXContext(orderer_org_admin, Ecies(), {}) client.tx_context = orderer_org_admin_tx_context orderer_org_admin_signature = client.sign_channel_config( channel_config) orderer_org_admin_signature_bytes = \ orderer_org_admin_signature.SerializeToString() proto_signature = utils.string_to_signature( [orderer_org_admin_signature_bytes]) self.assertIsInstance(proto_signature, list) self.assertTrue( 'OrdererMSP' in proto_signature[0].signature_header.__str__())
def test_string_to_signature(self): with open(self.channel_tx, 'rb') as f: channel_tx = f.read() channel_config = utils.extract_channel_config(channel_tx) client = Client('test/fixtures/network.json') orderer_org_admin = get_orderer_org_user( state_store=client.state_store) orderer_org_admin_tx_context = \ TXContext(orderer_org_admin, Ecies(), {}) client.tx_context = orderer_org_admin_tx_context orderer_org_admin_signature = client.sign_channel_config( channel_config) proto_signature = utils.string_to_signature( [orderer_org_admin_signature]) self.assertIsInstance(proto_signature, list) self.assertTrue( 'OrdererMSP' in proto_signature[0].signature_header.__str__())
def _create_or_update_channel_request(self, request, have_envelope): """Inits the create of update channel process. Args: request (dct): A create_update channel request. have_envelope (bool): Signals if the requests contains a finished protobuf envelope. Returns: rx.Observable: An observable for the orderer_response or an error. """ _logger.debug('_create_or_update_channel - start') error_msg = None if 'config' not in request and not have_envelope: error_msg = 'Missing config request parameter containing ' \ 'the configuration of the channel' if 'signatures' not in request and not have_envelope: error_msg = 'Missing signatures request parameter for the ' \ 'new channel' elif 'signatures' in request and \ not isinstance(request['signatures'], list) \ and not have_envelope: error_msg = 'Signatures request parameter must be an array ' \ 'of signatures' if 'tx_id' not in request and not have_envelope: error_msg = 'Missing tx_id request parameter' if 'nonce' not in request and not have_envelope: error_msg = 'Missing nonce request parameter' if 'orderer' not in request: error_msg = 'Missing orderer request parameter' if 'channel_name' not in request: error_msg = 'Missing channel_name request parameter' if error_msg: _logger.error( '_create_or_update_channel error: {}'.format(error_msg)) raise ValueError(error_msg) if have_envelope: _logger.debug('_create_or_update_channel - have envelope') envelope = common_pb2.Envelope() envelope.ParseFromString(request['envelope']) signature = envelope.signature payload = envelope.payload else: _logger.debug('_create_or_update_channel - have config_update') proto_config_update_envelope = configtx_pb2.ConfigUpdateEnvelope() proto_config_update_envelope.config_update = request['config'] # convert signatures to protobuf signature signatures = request['signatures'] proto_signatures = utils.string_to_signature(signatures) proto_config_update_envelope.signatures.extend(proto_signatures) proto_channel_header = utils.build_channel_header( common_pb2.HeaderType.Value('CONFIG_UPDATE'), request['tx_id'], request['channel_name'], utils.current_timestamp()) proto_header = utils.build_header(self.tx_context.identity, proto_channel_header, request['nonce']) proto_payload = common_pb2.Payload() proto_payload.header.CopyFrom(proto_header) proto_payload.data = proto_config_update_envelope \ .SerializeToString() payload_bytes = proto_payload.SerializeToString() signature_bytes = self.tx_context.sign(payload_bytes) signature = signature_bytes payload = payload_bytes # assemble the final envelope out_envelope = common_pb2.Envelope() out_envelope.signature = signature out_envelope.payload = payload orderer = request['orderer'] return orderer.broadcast(out_envelope)