/// <summary>
        /// Create MessageHeader.
        /// </summary>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoIdValues.</param>
        /// <param name="msgTypeValues">The msgTypeValues.</param>
        /// <param name="protoVer">The protoVer.</param>
        /// <returns>The MESSAGE_HEADER struct.</returns>
        public static MESSAGE_HEADER CreateMessageHeader(CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues, ProtoVersion protoVer)
        {
            MESSAGE_HEADER messageHeader = new MESSAGE_HEADER();
            messageHeader.CryptoAlgoId = cryptoAlgoIdValues;
            messageHeader.MsgType = msgTypeValues;
            messageHeader.MsgSize = 16;
            messageHeader.ProtVer = protoVer;

            return messageHeader;
        }
        /// <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);
        }
Exemple #3
0
        /// <summary>
        /// Create MessageHeader.
        /// </summary>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoIdValues.</param>
        /// <param name="msgTypeValues">The msgTypeValues.</param>
        /// <param name="protoVer">The protoVer.</param>
        /// <returns>The MESSAGE_HEADER struct.</returns>
        public static MESSAGE_HEADER CreateMessageHeader(CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues, ProtoVersion protoVer)
        {
            MESSAGE_HEADER messageHeader = new MESSAGE_HEADER();

            messageHeader.CryptoAlgoId = cryptoAlgoIdValues;
            messageHeader.MsgType      = msgTypeValues;
            messageHeader.MsgSize      = 16;
            messageHeader.ProtVer      = protoVer;

            return(messageHeader);
        }
        /// <summary>
        /// Create a MsgNego request.
        /// </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>MsgNego request.</returns>
        public PccrrNegoRequestPacket CreateMsgNegoRequest(
            ProtoVersion minSupportedProtocolVer,
            ProtoVersion maxSupportedProtocolVer,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            PccrrNegoRequestPacket packet = new PccrrNegoRequestPacket();

            MSG_NEGO_REQ msgNegoReq = new MSG_NEGO_REQ();
            msgNegoReq.MinSupportedProtocolVersion = minSupportedProtocolVer;
            msgNegoReq.MaxSupportedProtocolVersion = maxSupportedProtocolVer;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgNegoReq = msgNegoReq;
            packet.MessageHeader = messageHeader;

            return packet;
        }
        public void Start(int port, CryptoAlgoId_Values cryptoAlgoId, ProtoVersion protoVersion, byte[] content, EventQueue eventQueue)
        {
            this.cryptoAlgoId = cryptoAlgoId;
            this.protoVersion = protoVersion;
            this.content = content;
            this.eventQueue = eventQueue;
            this.aes = PccrrUtitlity.CreateAes(cryptoAlgoId);
            this.iv = new byte[16];
            for (int i = 0; i < iv.Length; i++)
            {
                this.iv[i] = (byte)i;
            }

            pccrrServer = new PccrrServer(port);

            pccrrServer.MessageArrived += new MessageArrivedEventArgs(pccrrServer_MessageArrived);

            pccrrServer.StartListening();
        }
        public void Start(int port, CryptoAlgoId_Values cryptoAlgoId, ProtoVersion protoVersion, Content_Information_Data_Structure contentInformation, byte[] content, EventQueue eventQueue)
        {
            this.contentInformation = contentInformation;

            base.Start(port, cryptoAlgoId, protoVersion, content, eventQueue);
        }
        public void HostedCacheServer_PccrrServer_MessageHeader_VersionIncompatible()
        {
            CheckApplicability();

            ProtoVersion protoVersion = new ProtoVersion { MajorVersion = 1, MinorVersion = 0 };

            PccrrClient pccrrClient = new PccrrClient(testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort);

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Send negoRequest with incompatible proto version to hosted cache server");

            var negoRequest = pccrrClient.CreateMsgNegoRequest(
                protoVersion,
                protoVersion,
                CryptoAlgoId_Values.AES_128,
                MsgType_Values.MSG_NEGO_REQ);

            var header = negoRequest.MessageHeader;
            header.ProtVer = new ProtoVersion { MajorVersion = 0xFEFE, MinorVersion = 0xFEFE };
            negoRequest.MessageHeader = header;

            bool passed = false;
            try
            {
                pccrrClient.ExpectPacket();
            }
            catch
            {
                passed = true;
            }

            BaseTestSite.Assert.IsTrue(passed, "The pccrr server should silently discard the message with incompatible proto version");
        }
        public void HostedCacheServer_PccrrClient_MessageHeader_CryptoAlgoId(CryptoAlgoId_Values algoId)
        {
            CheckApplicability();

            EventQueue eventQueue = new EventQueue(BaseTestSite);
            eventQueue.Timeout = testConfig.Timeout;

            byte[] content = TestUtility.GenerateRandomArray(ContentInformationUtility.DefaultBlockSize);
            Content_Information_Data_Structure contentInformation = contentInformationUtility.CreateContentInformationV1();

            ProtoVersion protoVersion = new ProtoVersion { MajorVersion = 1, MinorVersion = 0 };

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Start PCCRR server to be ready to serve content to hosted cache server");

            using (PccrrTestServerV1 pccrrTestServer = new PccrrTestServerV1())
            {
                pccrrTestServer.Start(
                    testConfig.ClientContentRetrievalListenPort,
                    algoId,
                    protoVersion,
                    contentInformation,
                    content,
                    eventQueue);

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTPS,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPSListenPort,
                    PchcConsts.HttpsUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage(
                        testConfig.ClientContentRetrievalListenPort,
                        contentInformation,
                        0);
                pchcClient.SendSegmentInfoMessage(segmentInfoMessage);

                BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Offer content block 0 of segment 0 to hosted cache server to hosted cache server");

                int blockCount = 0;
                TestUtility.DoUntilSucceed(delegate()
                {
                    eventQueue.Expect<MessageArrivedEventArgs>(typeof(PccrrServer).GetEvent("MessageArrived"), delegate(System.Net.IPEndPoint sender, PccrrPacket pccrrPacket)
                    {
                        var pccrrGetBlksRequest = pccrrPacket as PccrrGETBLKSRequestPacket;

                        if (pccrrGetBlksRequest != null)
                        {
                            blockCount++;
                        }
                    });
                    return blockCount == 1;
                }, TimeSpan.MaxValue, TimeSpan.Zero);

                BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Wait until cache is available on hosted cache server");

                TestUtility.DoUntilSucceed(() => sutControlAdapter.IsLocalCacheExisted(testConfig.HostedCacheServerComputerFQDNOrNetBiosName), testConfig.Timeout, testConfig.RetryInterval);
            }

            PccrrClient pccrrClient = new PccrrClient(testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort);
            Aes aes = PccrrUtitlity.CreateAes(algoId);

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Retrieve block 0 of segment 0 from hosted cache server",
                0);
            PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest(
                    contentInformation.GetSegmentId(0),
                    algoId,
                    MsgType_Values.MSG_GETBLKS,
                    (uint)0,
                    1);
            pccrrClient.SendPacket(
                pccrrBlkRequest,
                testConfig.Timeout);
            PccrrBLKResponsePacket pccrrBlkResponse
                = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket();

            byte[] block = pccrrBlkResponse.MsgBLK.Block;

            if (algoId != CryptoAlgoId_Values.NoEncryption)
                block = PccrrUtitlity.Decrypt(aes, block, contentInformation.segments[0].SegmentSecret, pccrrBlkResponse.MsgBLK.IVBlock);

            BaseTestSite.Assert.IsTrue(
            Enumerable.SequenceEqual(content, block),
            "The retrieved cached data should be the same as server data.");
        }
        public void HostedCacheServer_PccrrClient_MessageHeader_TypeInvalid()
        {
            CheckApplicability();

            EventQueue eventQueue = new EventQueue(BaseTestSite);
            eventQueue.Timeout = testConfig.Timeout;

            Content_Information_Data_Structure contentInformation = contentInformationUtility.CreateContentInformationV1();

            CryptoAlgoId_Values cryptoAlgoId = CryptoAlgoId_Values.AES_128;
            ProtoVersion protoVersion = new ProtoVersion { MajorVersion = 1, MinorVersion = 0 };

            BaseTestSite.Log.Add(
                    LogEntryKind.Debug,
                    "Start PCCRR server to be ready to serve content to hosted cache server");
            using (PccrrTestInvalidMsgTypeServer pccrrTestServer = new PccrrTestInvalidMsgTypeServer())
            {
                pccrrTestServer.Start(
                    testConfig.ClientContentRetrievalListenPort,
                    cryptoAlgoId,
                    protoVersion,
                    contentInformation,
                    new byte[0],
                    eventQueue);

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTPS,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPSListenPort,
                    PchcConsts.HttpsUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage(
                        testConfig.ClientContentRetrievalListenPort,
                        contentInformation,
                        0);
                pchcClient.SendSegmentInfoMessage(segmentInfoMessage);

                BaseTestSite.Log.Add(
                    LogEntryKind.Debug,
                    "Offer PccrrBLKSResponse with invalid message type to hosted cache server");
                int blockCount = 0;
                TestUtility.DoUntilSucceed(delegate()
                {
                    eventQueue.Expect<MessageArrivedEventArgs>(typeof(PccrrServer).GetEvent("MessageArrived"), delegate(System.Net.IPEndPoint sender, PccrrPacket pccrrPacket)
                    {
                        var pccrrGetBlksRequest = pccrrPacket as PccrrGETBLKSRequestPacket;

                        if (pccrrGetBlksRequest != null)
                        {
                            blockCount++;
                        }
                    });
                    return blockCount == 1;
                }, TimeSpan.MaxValue, TimeSpan.Zero);

                TestUtility.DoUntilSucceed(() => sutControlAdapter.IsLocalCacheExisted(testConfig.HostedCacheServerComputerFQDNOrNetBiosName), testConfig.NegativeTestTimeout, testConfig.RetryInterval);
            }
        }