Exemple #1
0
    def sign_channel_config(self, config, to_string=True):
        """This method uses the client instance's current signing identity to
         sign over the configuration bytes passed in.

        Args:
            config: The configuration update in bytes form.
            to_string: Whether to convert the result to string

        Returns:
            config_signature (common_pb2.ConfigSignature):
            The signature of the current user of the config bytes.

        """

        sign_channel_context = self.tx_context

        proto_signature_header = common_pb2.SignatureHeader()
        proto_signature_header.creator = sign_channel_context.identity
        proto_signature_header.nonce = sign_channel_context.nonce

        proto_signature_header_bytes = \
            proto_signature_header.SerializeToString()

        signing_bytes = proto_signature_header_bytes + config
        signature_bytes = sign_channel_context.sign(signing_bytes)

        proto_config_signature = configtx_pb2.ConfigSignature()
        proto_config_signature.signature_header = proto_signature_header_bytes
        proto_config_signature.signature = signature_bytes

        if to_string:
            return proto_config_signature.SerializeToString()
        else:
            return proto_config_signature
Exemple #2
0
    def _get_latest_block(self, tx_context, orderer):
        """ Get latest block from orderer.

        Args:
            tx_context (object): a tx_context instance
            orderer (object): a orderer instance
        """
        seek_info = ab_pb2.SeekInfo()
        seek_info.start.newest = ab_pb2.SeekNewest()
        seek_info.stop.newest = ab_pb2.SeekNewest()
        seek_info.behavior = \
            ab_pb2.SeekInfo.SeekBehavior.Value('BLOCK_UNTIL_READY')

        seek_info_header = self._build_channel_header(
            common_pb2.HeaderType.Value('DELIVER_SEEK_INFO'), tx_context.tx_id,
            self._name, current_timestamp(), tx_context.epoch)

        signature_header = common_pb2.SignatureHeader()
        signature_header.creator = tx_context.identity
        signature_header.nonce = tx_context.nonce

        seek_payload = common_pb2.Payload()
        seek_payload.header.signature_header = \
            signature_header.SerializeToString()
        seek_payload.header.channel_header = \
            seek_info_header.SerializeToString()
        seek_payload.data = seek_info.SerializeToString()

        envelope = common_pb2.Envelope()
        envelope.signature = tx_context.sign(seek_payload.SerializeToString())
        envelope.payload = seek_payload.SerializeToString()
Exemple #3
0
def decode_signature_header(signature_header_bytes):
    """Decode signature header

    :param signature_header_bytes: signature header bytes
    :return: deserialized signature_header
    """
    signature_header = {}
    proto_signature_header = common_pb2.SignatureHeader()
    proto_signature_header.ParseFromString(signature_header_bytes)
    signature_header['creator'] = \
        decode_identity(proto_signature_header.creator)
    signature_header['nonce'] = \
        binascii.b2a_hex(proto_signature_header.nonce)
    return signature_header
def build_header(creator,
                 nonce,
                 tran_prop_type,
                 chain,
                 prop_type,
                 epoch=0,
                 chaincode_id=None):
    """Build a header for transaction proposal.

    Args:
        prop_type: prop type
        creator: user
        nonce: nonce
        tran_prop_type: transaction proposal type
        chain: chain instance
        epoch: epoch
        chaincode_id: chaincode id

    Returns: common_proto.Header instance

    """
    header = common_pb2.Header()

    signature_header = common_pb2.SignatureHeader()
    signature_header.creator = creator.serialize()
    signature_header.nonce = nonce
    header.signature_header = signature_header.SerializeToString()

    channel_header = common_pb2.ChannelHeader()
    channel_header.type = tran_prop_type
    channel_header.version = 1
    if prop_type != CC_INSTALL:
        channel_header.channel_id = proto_str(chain.name)
    channel_header.tx_id = proto_str(chain.generate_tx_id(nonce, creator))
    channel_header.epoch = epoch
    if chaincode_id:
        header_ext = proposal_pb2.ChaincodeHeaderExtension()
        header_ext.chaincode_id.name = proto_str(chaincode_id)
        channel_header.extension = header_ext.SerializeToString()
    header.channel_header = channel_header.SerializeToString()

    return header
Exemple #5
0
def build_header(creator, channel_header, nonce):
    """This function will build the common header.

    :param creator: Serialized identity of the creator.
    :type creator: protobuf SerializedIdentity
    :param channel_header: ChannelHeader
    :type channel_header: protobuf ChannelHeader
    :param nonce: Nonce that has been used for the tx_id.
    :type nonce: str
    :return: Returns created protobuf common header.
    :rtype: header
    """
    signature_header = common_pb2.SignatureHeader()
    signature_header.creator = creator
    signature_header.nonce = nonce

    header = common_pb2.Header()
    header.signature_header = signature_header.SerializeToString()
    header.channel_header = channel_header.SerializeToString()

    return header
Exemple #6
0
def build_header(creator, channel_header, nonce):
    """This function will build the common header.

    Args:
        creator (protobuf SerializedIdentity):
            Serialized identity of the creator.
        channel_header (protobuf ChannelHeader): ChannelHeader
        nonce (str): Nonce that has been used for the tx_id.

    Returns:
        header: Returns created protobuf common header.

    """
    signature_header = common_pb2.SignatureHeader()
    signature_header.creator = creator
    signature_header.nonce = nonce

    header = common_pb2.Header()
    header.signature_header = signature_header.SerializeToString()
    header.channel_header = channel_header.SerializeToString()

    return header