The Negotiation Response message is the response message containing the minimum and maximum protocol version supported by the responding server-role peer. The message is sent in response to a Negotiation Request message or to any other request message with a protocol version not supported by the server-role peer.
Esempio n. 1
0
        /// <summary>
        /// Decode MSG_NEGO_RESP message.
        /// </summary>
        /// <param name="data">Data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MSG_NEGO_RESP struct.</returns>
        private MSG_NEGO_RESP DecodeMSG_NEGO_RESP(byte[] data, ref int index)
        {
            MSG_NEGO_RESP ret = new MSG_NEGO_RESP();

            ret.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            return(ret);
        }
        /// <summary>
        /// Decode pack.
        /// </summary>
        /// <param name="rawdata">The rawdata.</param>
        /// <returns>The PccrrPacket.</returns>
        public override PccrrPacket Decode(byte[] rawdata)
        {
            if (rawdata == null)
            {
                throw new ArgumentNullException("rawdata");
            }

            if (rawdata.Length == 0)
            {
                throw new ArgumentException("The raw data should not be empty.");
            }

            PccrrNegoResponsePacket packet = new PccrrNegoResponsePacket();

            int messageLength = 0;

            messageLength = rawdata.Length;

            if (messageLength > 0)
            {
                int index = 0;

                byte[] data = rawdata;

                RESPONSE_MESSAGE ret = new RESPONSE_MESSAGE();
                ret.TRANSPORTRESPONSEHEADER.Size = MarshalHelper.GetUInt32(data, ref index, false);

                MESSAGE_HEADER ret1 = new MESSAGE_HEADER();
                ret1.ProtVer.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.ProtVer.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.MsgType      = (MsgType_Values)MarshalHelper.GetUInt32(data, ref index, false);
                ret1.MsgSize      = MarshalHelper.GetUInt32(data, ref index, false);
                ret1.CryptoAlgoId = (CryptoAlgoId_Values)MarshalHelper.GetUInt32(data, ref index, false);

                MSG_NEGO_RESP ret2 = new MSG_NEGO_RESP();
                ret2.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);

                packet.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                packet.MsgNegoResp             = ret2;
                packet.MessageHeader           = ret1;
            }

            return(packet);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a MsgNego response.
        /// </summary>
        /// <param name="minSupportedProtocolVer">The minSupportedProtocolVersion.</param>
        /// <param name="maxSupportedProtocolVer">The maxSupportedProtocolVersion.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>The MsgNego response.</returns>
        public PccrrNegoResponsePacket CreateMsgNegoResponse(
            ProtoVersion minSupportedProtocolVer,
            ProtoVersion maxSupportedProtocolVer,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            PccrrNegoResponsePacket packet = new PccrrNegoResponsePacket();

            MSG_NEGO_RESP msgNegoResp = new MSG_NEGO_RESP();

            msgNegoResp.MaxSupporteProtocolVersion = maxSupportedProtocolVer;
            msgNegoResp.MinSupporteProtocolVersion = minSupportedProtocolVer;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion {
                MajorVersion = 1, MinorVersion = 0
            });

            packet.MsgNegoResp   = msgNegoResp;
            packet.MessageHeader = messageHeader;

            return(packet);
        }
        /// <summary>
        /// Send message MSG_NEGO_RESP.
        /// </summary>
        /// <param name="isSupportVersion">If it is true, it is support version, if it is false, it is not support version.</param>
        /// <param name="isWellFormed">If it is true, it is well formed, if it is false, it is not well formed.</param>
        public void SendMsgNegoResp(bool isSupportVersion, bool isWellFormed)
        {
            PccrrNegoResponsePacket pccrrNegoResponsePacket;
            if (!isSupportVersion && isWellFormed)
            {
                pccrrNegoResponsePacket = this.pccrrStackSer.CreateMsgNegoResponse(this.minErrorSupV, this.maxErrorSupV, CryptoAlgoId_Values.AES_128, MsgType_Values.MSG_NEGO_RESP, this.protoErrorVer);
            }
            else if (isSupportVersion && isWellFormed)
            {
                pccrrNegoResponsePacket = this.pccrrStackSer.CreateMsgNegoResponse(this.minSupV, this.maxSupV, CryptoAlgoId_Values.AES_128, MsgType_Values.MSG_NEGO_RESP, this.protoVer);
            }
            else
            {
                pccrrNegoResponsePacket = this.pccrrStackSer.CreateMsgNegoResponse(this.minErrorSupV, this.maxErrorSupV, CryptoAlgoId_Values.AES_128, MsgType_Values.MSG_NEGO_RESP, this.protoErrorVer);
                MSG_NEGO_RESP msgNegoResp = new MSG_NEGO_RESP();
                MESSAGE_HEADER messageHeader = new MESSAGE_HEADER();
                messageHeader = pccrrNegoResponsePacket.MessageHeader;
                msgNegoResp.MinSupporteProtocolVersion.MajorVersion = 0;
                msgNegoResp.MinSupporteProtocolVersion.MinorVersion = 0;
                messageHeader.ProtVer.MajorVersion = 1;
                messageHeader.ProtVer.MinorVersion = 0;
                msgNegoResp.MaxSupporteProtocolVersion.MajorVersion = 0;
                msgNegoResp.MaxSupporteProtocolVersion.MinorVersion = 0;

                pccrrNegoResponsePacket.MsgNegoResp = msgNegoResp;
                pccrrNegoResponsePacket.MessageHeader = messageHeader;
            }

            this.pccrrStackSer.SendPacket(pccrrNegoResponsePacket);
        }
Esempio n. 5
0
        /// <summary>
        /// Decode response message.
        /// </summary>
        /// <param name="rawdata">The raw data.</param>
        /// <returns>The PccrrPacket.</returns>
        public PccrrPacket DecodeResponseMessage(byte[] rawdata)
        {
            if (rawdata == null)
            {
                throw new ArgumentNullException("rawdata");
            }

            if (rawdata.Length == 0)
            {
                throw new ArgumentException("The raw data should not be empty.");
            }

            int messageLength = 0;

            messageLength = rawdata.Length;

            PccrrPacket packet = null;

            if (messageLength > 0)
            {
                int index = 0;

                RESPONSE_MESSAGE ret = new RESPONSE_MESSAGE();
                ret.TRANSPORTRESPONSEHEADER.Size = MarshalHelper.GetUInt32(rawdata, ref index, false);
                ret.MESSAGEHEADER = this.DecodeMessageHeader(rawdata, ref index);

                switch (ret.MESSAGEHEADER.MsgType)
                {
                case MsgType_Values.MSG_BLKLIST:
                    PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = new PccrrBLKLISTResponsePacket();

                    MSG_BLKLIST msgBLKLIST = this.DecodeMSG_BLKLIST(rawdata, ref index);
                    pccrrBLKLISTResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrBLKLISTResponsePacket.MsgBLKLIST    = msgBLKLIST;
                    pccrrBLKLISTResponsePacket.MessageHeader = ret.MESSAGEHEADER;
                    packet = pccrrBLKLISTResponsePacket;
                    break;

                case MsgType_Values.MSG_BLK:
                    PccrrBLKResponsePacket pccrrBLKResponsePacket = new PccrrBLKResponsePacket();

                    MSG_BLK msgBLK = this.DecodeMSG_BLK(rawdata, ref index);
                    pccrrBLKResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrBLKResponsePacket.MsgBLK        = msgBLK;
                    pccrrBLKResponsePacket.MessageHeader = ret.MESSAGEHEADER;
                    packet = pccrrBLKResponsePacket;
                    break;

                case MsgType_Values.MSG_NEGO_RESP:
                    PccrrNegoResponsePacket pccrrNegoResponsePacket = new PccrrNegoResponsePacket();

                    MSG_NEGO_RESP msgNEGORESP = this.DecodeMSG_NEGO_RESP(rawdata, ref index);
                    pccrrNegoResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrNegoResponsePacket.MsgNegoResp             = msgNEGORESP;
                    pccrrNegoResponsePacket.MessageHeader           = ret.MESSAGEHEADER;
                    packet = pccrrNegoResponsePacket;
                    break;

                case MsgType_Values.MSG_SEGLIST:
                    PccrrSegListResponsePacket pccrrSegListResponsePacket = new PccrrSegListResponsePacket();
                    pccrrSegListResponsePacket.MsgSegList = TypeMarshal.ToStruct <MSG_SEGLIST>(rawdata, ref index);
                    pccrrSegListResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrSegListResponsePacket.MessageHeader           = ret.MESSAGEHEADER;
                    packet = pccrrSegListResponsePacket;
                    break;
                }
            }

            return(packet);
        }
        /// <summary>
        /// Decode pack.
        /// </summary>
        /// <param name="rawdata">The rawdata.</param>
        /// <returns>The PccrrPacket.</returns>
        public override PccrrPacket Decode(byte[] rawdata)
        {
            if (rawdata == null)
            {
                throw new ArgumentNullException("rawdata");
            }

            if (rawdata.Length == 0)
            {
                throw new ArgumentException("The raw data should not be empty.");
            }

            PccrrNegoResponsePacket packet = new PccrrNegoResponsePacket();

            int messageLength = 0;

            messageLength = rawdata.Length;

            if (messageLength > 0)
            {
                int index = 0;

                byte[] data = rawdata;

                RESPONSE_MESSAGE ret = new RESPONSE_MESSAGE();
                ret.TRANSPORTRESPONSEHEADER.Size = MarshalHelper.GetUInt32(data, ref index, false);

                MESSAGE_HEADER ret1 = new MESSAGE_HEADER();
                ret1.ProtVer.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.ProtVer.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.MsgType = (MsgType_Values)MarshalHelper.GetUInt32(data, ref index, false);
                ret1.MsgSize = MarshalHelper.GetUInt32(data, ref index, false);
                ret1.CryptoAlgoId = (CryptoAlgoId_Values)MarshalHelper.GetUInt32(data, ref index, false);

                MSG_NEGO_RESP ret2 = new MSG_NEGO_RESP();
                ret2.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);

                packet.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                packet.MsgNegoResp = ret2;
                packet.MessageHeader = ret1;
            }

            return packet;
        }
 /// <summary>
 /// Decode MSG_NEGO_RESP message.
 /// </summary>
 /// <param name="data">Data to be decoded.</param>
 /// <param name="index">Started index.</param>
 /// <returns>The MSG_NEGO_RESP struct.</returns>
 private MSG_NEGO_RESP DecodeMSG_NEGO_RESP(byte[] data, ref int index)
 {
     MSG_NEGO_RESP ret = new MSG_NEGO_RESP();
     ret.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
     ret.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
     ret.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
     ret.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
     return ret;
 }
        /// <summary>
        /// Create a MsgNego response.
        /// </summary>
        /// <param name="minSupportedProtocolVer">The minSupportedProtocolVersion.</param>
        /// <param name="maxSupportedProtocolVer">The maxSupportedProtocolVersion.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>The MsgNego response.</returns>
        public PccrrNegoResponsePacket CreateMsgNegoResponse(
            ProtoVersion minSupportedProtocolVer,
            ProtoVersion maxSupportedProtocolVer,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            PccrrNegoResponsePacket packet = new PccrrNegoResponsePacket();

            MSG_NEGO_RESP msgNegoResp = new MSG_NEGO_RESP();
            msgNegoResp.MaxSupporteProtocolVersion = maxSupportedProtocolVer;
            msgNegoResp.MinSupporteProtocolVersion = minSupportedProtocolVer;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgNegoResp = msgNegoResp;
            packet.MessageHeader = messageHeader;

            return packet;
        }