Пример #1
0
        /// <summary>
        /// Verify the received message from client.
        /// </summary>
        /// <param name="remoteAddr">The remote address.</param>
        /// <param name="pccrrPacket">The pccrrPacket.</param>
        private void RetrievalTransport_Receive(IPEndPoint remoteAddr, PccrrPacket pccrrPacket)
        {
            PccrrGETBLKSRequestPacket pccrrGETBLKSRequestPacket = pccrrPacket as PccrrGETBLKSRequestPacket;

            if (pccrrGETBLKSRequestPacket != null)
            {
                MSG_GETBLKS    msgGETBLKS    = pccrrGETBLKSRequestPacket.MsgGetBLKS;
                MESSAGE_HEADER messageHEADER = pccrrGETBLKSRequestPacket.MessageHeader;
                this.sid = msgGETBLKS.SegmentID;
                REQUEST_MESSAGE requestMESSAGE = new REQUEST_MESSAGE();
                requestMESSAGE.MESSAGEBODY   = msgGETBLKS;
                requestMESSAGE.MESSAGEHEADER = messageHEADER;
                this.uiPayload = Marshal.SizeOf(messageHEADER) + Marshal.SizeOf(msgGETBLKS) + 24;

                PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(msgGETBLKS.ReqBlockRanges[0]);
                PccrrBothRoleCaptureCode.CaptureMessageHeaderRequirements(messageHEADER, this.uiPayload);
                this.VerifyGetBlocks(msgGETBLKS);
                this.VerifyRequestMessage(requestMESSAGE);
                PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgGETBLKS.SegmentID);
                PccrrBothRoleCaptureCode.CaptureHttpRequirements();
                PccrrBothRoleCaptureCode.CaptureMessageRequirements();

                this.ReceiveMsgGetBlk(msgGETBLKS.ReqBlockRanges[0].Index);
            }
            else
            {
                PccrrGETBLKLISTRequestPacket pccrrGETBLKLISTRequestPacket = pccrrPacket as PccrrGETBLKLISTRequestPacket;

                if (pccrrGETBLKLISTRequestPacket != null)
                {
                    MSG_GETBLKLIST msgGETBLKLIST = pccrrGETBLKLISTRequestPacket.MsgGetBLKLIST;
                    this.sid = msgGETBLKLIST.SegmentID;

                    this.VerifyGetBlkList(msgGETBLKLIST);
                    PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgGETBLKLIST);
                    _BLOCKRANGE[] blockRanges = ClientHelper.ConvertFromStackBLOCKRANGEArray(msgGETBLKLIST.NeededBlockRanges);

                    this.ReceiveMsgGetBlkList(blockRanges);
                }
                else
                {
                    this.ReceiveMsgNegoReq();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Send message MSG_GETBLKS
        /// </summary>
        /// <param name="sid">segment id.</param>
        /// <param name="blockRang">Block ranges client wants to get</param>
        /// <param name="isVersionSupported">The version in this message is supported in server.</param>
        public void SendMsgGetBlks(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported)
        {
            PccrrGETBLKSRequestPacket packet;

            BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang);

            if (!isVersionSupported)
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoErrorVer);
            }
            else
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoVer);
            }

            for (int i = 0; i < blockRanges.Length; i++)
            {
                if (blockRanges.Length == 1)
                {
                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
                else
                {
                    MSG_GETBLKS msgGETBLKS = packet.MsgGetBLKS;
                    msgGETBLKS.ReqBlockRanges     = new BLOCK_RANGE[blockRanges.Length];
                    msgGETBLKS.ReqBlockRangeCount = (uint)blockRanges.Length;
                    packet.MsgGetBLKS             = msgGETBLKS;

                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
            }

            this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout));

            PccrrPacket respMSG = this.pccrrStack.ExpectPacket();

            if (!isVersionSupported)
            {
                PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket;

                if (pccrrNegoResponsePacket != null)
                {
                    this.ReceiveMsgNegoResp();
                }
            }
            else
            {
                PccrrBLKResponsePacket pccrrBLKResponsePacket = respMSG as PccrrBLKResponsePacket;

                MSG_BLK                   msgBLK         = pccrrBLKResponsePacket.MsgBLK;
                MESSAGE_HEADER            messageHeader  = pccrrBLKResponsePacket.MessageHeader;
                TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKResponsePacket.TransportResponseHeader;
                RESPONSE_MESSAGE          respMessage    = new RESPONSE_MESSAGE();
                respMessage.MESSAGEBODY             = msgBLK;
                respMessage.MESSAGEHEADER           = messageHeader;
                respMessage.TRANSPORTRESPONSEHEADER = transportRespH;

                this.VerifyMsgBlk(msgBLK);
                PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgBLK.SegmentId);
                this.VerifyResponseMessage(respMessage);

                bool isSizeOfBlockZero = false;

                if (msgBLK.SizeOfBlock == 0)
                {
                    isSizeOfBlockZero = true;
                }
                else
                {
                    isSizeOfBlockZero = false;
                }

                bool isBlockEmpty = false;

                if (msgBLK.Block.Length == 0)
                {
                    isBlockEmpty = true;
                }
                else
                {
                    isBlockEmpty = false;
                }

                CryptoAlgoIdValues crypAlgoId = Helper.ConvertFromStackCryptoAlgoIdValues(pccrrBLKResponsePacket.MessageHeader.CryptoAlgoId);
                this.ReceiveMsgBlk(msgBLK.BlockIndex, msgBLK.NextBlockIndex, isSizeOfBlockZero, isBlockEmpty, crypAlgoId);
            }
        }
        /// <summary>
        /// MSG_GETBLKS structure capture
        /// </summary>
        /// <param name="getBlks">MSG_GETBLKS object</param>
        private void VerifyGetBlocks(MSG_GETBLKS getBlks)
        {
            // Verify requirement MS-PCCRR_R61 and MS-PCCRR_R113
            string isR61Implementated = Site.Properties.Get("PCCRR.SHOULDMAY.R61Implementated");
            bool   isR113Satisfied    = getBlks.ReqBlockRanges.Length == 1;

            if (isWindows)
            {
                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R113");

                // Verify MS-PCCRR requirement: MS-PCCRR_R113
                Site.CaptureRequirementIfIsTrue(
                    isR113Satisfied,
                    113,
                    @"[In MESSAGE_HEADER][MsgType (4 bytes)] Since only one block will be returned, a MSG_GETBLKS 
                    message specify only a single range containing only a single block.[In windows]");

                if (null == isR61Implementated)
                {
                    Site.Properties.Add("PCCRR.SHOULDMAY.R61Implementated", Boolean.TrueString);
                    isR61Implementated = Boolean.TrueString;
                }
            }

            if (null != isR61Implementated)
            {
                bool implement   = Boolean.Parse(isR61Implementated);
                bool isSatisfied = isR113Satisfied;

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R61");

                // Verify MS-PCCRR requirement: MS-PCCRR_R61
                Site.CaptureRequirementIfAreEqual <bool>(
                    implement,
                    isSatisfied,
                    61,
                    @"[In MESSAGE_HEADER][MsgType (4 bytes)] Since only one block will be returned, 
                    a MSG_GETBLKS message SHOULD specify only a single range containing only a single block.");
            }

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R101");

            // Verify MS-PCCRR requirement: MS-PCCRR_R101
            Site.CaptureRequirementIfAreEqual <uint>(
                (uint)getBlks.SegmentID.Length,
                getBlks.SizeOfSegmentID,
                101,
                @"[In MSG_GETBLKS]SizeOfSegmentID (4 bytes):  Size in bytes of the subsequent SegmentID field.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R102");

            // Verify MS-PCCRR requirement: MS-PCCRR_R102
            bool isVerifyR102 = getBlks.SizeOfSegmentID >= 0x00000000 && getBlks.SizeOfSegmentID <= 0xFFFFFFFF;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR102,
                102,
                @"[In MSG_GETBLKS][SizeOfSegmentID (4 bytes)]The syntactic range of this field[SegmentID field] 
                is from 0x00000000 to 0xFFFFFFFF.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R105");

            // Verify MS-PCCRR requirement: MS-PCCRR_R105
            Site.CaptureRequirementIfAreEqual <int>(
                32,
                getBlks.SegmentID.Length,
                105,
                @"[In MSG_GETBLKS][SizeOfSegmentID (4 bytes)][Implementations]MUST support content with 32-byte 
                SegmentIDs.<6>");

            if (null != getBlks.ZeroPad)
            {
                bool isAllZero = true;

                // If the length is zero, the flag will remain in true
                // else, the bytes will be checked in foreach statements
                foreach (byte b in getBlks.ZeroPad)
                {
                    if (b != 0)
                    {
                        isAllZero = false;
                        break;
                    }
                }

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R110");

                // Verify MS-PCCRR requirement: MS-PCCRR_R110
                bool isVerifyR110 = getBlks.ZeroPad.Length >= 0 && getBlks.ZeroPad.Length <= 3;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR110,
                    110,
                    @"[In MSG_GETBLKS]This field[ZeroPad (variable)] is 0 to 3 bytes in length, as required.");

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R109");

                // Verify MS-PCCRR requirement: MS-PCCRR_R109
                bool isVerifyR109 = isAllZero;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR109,
                    109,
                    @"[In MSG_GETBLKS][ZeroPad (variable)]The value of each byte MUST be set to zero.");
            }

            // Verify requirement MS-PCCRR_R104 and MS-PCCRR_R111
            string isR104Implementated = Site.Properties.Get("PCCRR.SHOULDMAY.R104Implementated");
            bool   isR111Satisfied     = getBlks.SizeOfSegmentID >= 0x00000000 && getBlks.SizeOfSegmentID <= 0xFFFFFFFF;

            if (isWindows)
            {
                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R111");

                // Verify MS-PCCRR requirement: MS-PCCRR_R111
                Site.CaptureRequirementIfIsTrue(
                    isR111Satisfied,
                    111,
                    @"[In MSG_GETBLKS][SizeOfSegmentID (4 bytes)]Implementations support all allowed 
                    SegmentID lengths.[In windows]");

                if (null == isR104Implementated)
                {
                    Site.Properties.Add("PCCRR.SHOULDMAY.R104Implementated", Boolean.TrueString);
                    isR104Implementated = Boolean.TrueString;
                }
            }

            if (null != isR104Implementated)
            {
                bool implement   = Boolean.Parse(isR104Implementated);
                bool isSatisfied = isR111Satisfied;

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R104");

                // Verify MS-PCCRR requirement: MS-PCCRR_R104
                Site.CaptureRequirementIfAreEqual <bool>(
                    implement,
                    isSatisfied,
                    104,
                    @"[In MSG_GETBLKS][SizeOfSegmentID (4 bytes)]Implementations SHOULD support all 
                    allowed SegmentID lengths");
            }

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R114");

            // Verify MS-PCCRR requirement: MS-PCCRR_R114
            Site.CaptureRequirementIfAreEqual <uint>(
                (uint)getBlks.ReqBlockRanges.Length,
                getBlks.ReqBlockRangeCount,
                114,
                @"[In MSG_GETBLKS]ReqBlockRangeCount (4 bytes):  Number of items in the subsequent block range array.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R115");

            // Verify MS-PCCRR requirement: MS-PCCRR_R115
            bool isVerifyR115 = getBlks.ReqBlockRangeCount >= 0x00000000 &&
                                getBlks.ReqBlockRangeCount <= 0xFFFFFFFF;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR115,
                115,
                @"[In MSG_GETBLKS]The syntactic range of this field[ReqBlockRangeCount (4 bytes)] is 
                from 0x00000000 to 0xFFFFFFFF.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R116");

            // Verify MS-PCCRR requirement: MS-PCCRR_R116
            bool isVerifyR116 = getBlks.ReqBlockRangeCount >= 1 &&
                                getBlks.ReqBlockRangeCount <= 256;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR116,
                116,
                @"[In MSG_GETBLKS][ReqBlockRangeCount (4 bytes)]The effective range of this field MUST be 
                between 1 and 256 inclusive, because there cannot be more than 256 non-overlapping and non-contiguous
                ranges in a maximum segment size of 512 blocks.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R118");

            Site.CaptureRequirement(
                118,
                @"[In MSG_GETBLKS][ReqBlockRanges (variable)]RegBlockRanges MUST specify a block range containing 
                only one block.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R119");

            // Verify MS-PCCRR requirement: MS-PCCRR_R119
            Site.CaptureRequirementIfAreEqual <int>(
                getBlks.DataForVrfBlock.Length,
                (int)getBlks.SizeOfDataForVrfBlock,
                119,
                @"[In MSG_GETBLKS]SizeOfDataForVrfBlock (4 bytes):  Size in bytes of the subsequent 
                DataForVrfBlock field.");

            // Verify requirement MS-PCCRR_R120 and MS-PCCRR_R121
            string isR120Implementated = Site.Properties.Get("PCCRR.SHOULDMAY.R120Implementated");
            bool   isR121Satisfied     = getBlks.SizeOfDataForVrfBlock == 0;

            if (isWindows)
            {
                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R121");

                // Verify MS-PCCRR requirement: MS-PCCRR_R121
                Site.CaptureRequirementIfIsTrue(
                    isR121Satisfied,
                    121,
                    @"[In MSG_GETBLKS]This[SizeOfDataForVrfBlock (4 bytes)] field is zero.[In windows]");

                if (null == isR120Implementated)
                {
                    Site.Properties.Add("PCCRR.SHOULDMAY.R120Implementated", Boolean.TrueString);
                    isR120Implementated = Boolean.TrueString;
                }
            }

            if (null != isR120Implementated)
            {
                bool implement   = Boolean.Parse(isR120Implementated);
                bool isSatisfied = isR121Satisfied;

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R120");

                // Verify MS-PCCRR requirement: MS-PCCRR_R120
                Site.CaptureRequirementIfAreEqual <bool>(
                    implement,
                    isSatisfied,
                    120,
                    @"[In MSG_GETBLKS]This[SizeOfDataForVrfBlock (4 bytes)] field SHOULD be zero.");
            }

            // Verify requirement MS-PCCRR_R123 and MS-PCCRR_R124
            string isR123Implementated = Site.Properties.Get("PCCRR.SHOULDMAY.R123Implementated");
            bool   isR124Satisfied     = getBlks.DataForVrfBlock.Length == 0;

            if (isWindows)
            {
                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R124");

                // Verify MS-PCCRR requirement: MS-PCCRR_R124
                Site.CaptureRequirementIfIsTrue(
                    isR124Satisfied,
                    124,
                    @"[In MSG_GETBLKS][DataForVrfBlock (variable)]This field is empty.[In windows]");

                if (null == isR123Implementated)
                {
                    Site.Properties.Add("PCCRR.SHOULDMAY.R123Implementated", Boolean.TrueString);
                    isR123Implementated = Boolean.TrueString;
                }
            }

            if (null != isR123Implementated)
            {
                bool implement   = Boolean.Parse(isR123Implementated);
                bool isSatisfied = isR124Satisfied;

                //
                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R123");

                // Verify MS-PCCRR requirement: MS-PCCRR_R123
                Site.CaptureRequirementIfAreEqual <bool>(
                    implement,
                    isSatisfied,
                    123,
                    @"[In MSG_GETBLKS][DataForVrfBlock (variable)]This field SHOULD be empty.");
            }

            // Capture directly, because it won't get the packet if the client didn't specify a right server address.
            Site.CaptureRequirement(
                201,
                @"[In MSG_GETBLKS Initiation]To initiate a Retrieval Protocol request for specific block ranges, 
                the higher-layer applications MUST specify a server address.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R202");

            // Verify MS-PCCRR requirement: MS-PCCRR_R202
            bool isVerifyR202 = true;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR202,
                202,
                @"[In MSG_GETBLKS Initiation]To initiate a Retrieval Protocol request for specific block ranges, 
                the higher-layer applications MUST specify a segment ID.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R203");

            // Verify MS-PCCRR requirement: MS-PCCRR_R203
            bool isVerifyR203 = (uint)getBlks.ReqBlockRanges.Length == getBlks.ReqBlockRangeCount && true;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR203,
                203,
                @"[In MSG_GETBLKS Initiation]To initiate a Retrieval Protocol request for specific block ranges, 
                the higher-layer applications MUST specify a set of block ranges with the segment identified 
                by the segment ID.");

            // Capture directly, because it won't send a GetBlocklist message to the server if the client
            // did not construct an instance of the Retrieval Protocol instantiation.
            Site.CaptureRequirement(
                204,
                @"[In MSG_GETBLKS Initiation]The client instance of the Retrieval Protocol MUST construct 
                a GetBlocks message.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R174");

            // Verify MS-PCCRR requirement: MS-PCCRR_R174
            bool isVerifyR174 = getBlks.ReqBlockRanges != null && getBlks.SegmentID != null;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR174,
                174,
                @"[In Protocol Details]Blocks request/response: A client initiates a GetBlocks request 
                (MSG_GETBLKS (section 2.2.4.3)) to a server to retrieve a specific block of a given segment, 
                which is identified by the segment ID and the index of the block in the segment.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R175");

            // Since the request is received, the following requirement can be verified directly
            Site.CaptureRequirement(
                175,
                @"[In Protocol Details][Blocks request/response]It[client] does this by sending 
                a MSG_GETBLKS request.");
        }