/// <summary> /// Creates Aes instance based on specified algorithm. /// </summary> /// <param name="cryptoAlgoId">Algorithm ID.</param> /// <returns>Aes object.</returns> public static Aes CreateAes(CryptoAlgoId_Values cryptoAlgoId) { if (cryptoAlgoId == CryptoAlgoId_Values.NoEncryption) return null; Aes aes = Aes.Create(); aes.Mode = CipherMode.CBC; switch (cryptoAlgoId) { case CryptoAlgoId_Values.AES_128: aes.KeySize = 128; break; case CryptoAlgoId_Values.AES_192: aes.KeySize = 192; break; case CryptoAlgoId_Values.AES_256: aes.KeySize = 256; break; default: throw new NotImplementedException(); } return aes; }
/// <summary> /// Convert CryptoAlgoId_Values parameters to Adapter parameters. /// </summary> /// <param name="cryptoAlgoId">The CryptoAlgoId_Values value.</param> /// <returns>The CryptoAlgoIdValues value.</returns> public static CryptoAlgoIdValues ConvertFromStackCryptoAlgoIdValues(CryptoAlgoId_Values cryptoAlgoId) { CryptoAlgoIdValues crypAlgoId; crypAlgoId = (CryptoAlgoIdValues)cryptoAlgoId; return crypAlgoId; }
/// <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; }
public void Start(int port, CryptoAlgoId_Values cryptoAlgoId, byte[] content, EventQueue eventQueue) { this.cryptoAlgoId = cryptoAlgoId; 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, 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(); }
/// <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> /// Initialize adapter data and create connection. /// </summary> /// <param name="testSite">the test site</param> public override void Initialize(ITestSite testSite) { base.Initialize(ReqConfigurableSite.GetReqConfigurableSite(testSite)); this.Site.DefaultProtocolDocShortName = "MS-PCCRR"; PccrrBothRoleCaptureCode.Initialize(this.Site); this.isDistributedMode = bool.Parse(this.GetProperty("Environment.IsDistributedMode")); if (this.isDistributedMode) { this.isWindows = string.Equals( this.GetProperty("Environment.DistributedSUT.OSVersion"), "win2k8r2", StringComparison.OrdinalIgnoreCase); this.serverName = this.GetProperty("Environment.DistributedSUT.MachineName"); } else { this.isWindows = string.Equals( this.GetProperty("Environment.HostedCacheServer.OSVersion"), "win2k8r2", StringComparison.OrdinalIgnoreCase); this.serverName = this.GetProperty("Environment.HostedCacheServer.MachineName"); } this.cryptoAlgo = (CryptoAlgoId_Values)Enum.Parse(typeof(CryptoAlgoId_Values), this.GetProperty("PCCRR.Protocol.CryptoAlgoId_Value")); this.timeout = int.Parse(this.GetProperty("PCCRR.Protocol.timeout")); this.port = int.Parse(this.GetProperty("PCCRR.Protocol.Http.Port")); this.protoErrorVer.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.ErrorProtocolVersion")); this.protoErrorVer.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.ErrorProtocolVersion")); this.minSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MinorVer")); this.minSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MajorVer")); this.maxSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MaxSupportedProtocolVersion.MinorVer")); this.maxSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MaxSupportedProtocolVersion.MajorVer")); this.protoVer.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MinorVer")); this.protoVer.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MajorVer")); this.pccrrStack = new PccrrClient(this.serverName, this.port, PccrrUri, HttpMethod.POST); }
/// <summary> /// Create a MsgSegList response. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentRanges">Segment ranges.</param> /// <returns>The MsgSegList response.</returns> public PccrrSegListResponsePacket CreateSegListResponse( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, BLOCK_RANGE[] segmentRanges) { var packet = new PccrrSegListResponsePacket(); var msgSegList = new MSG_SEGLIST(); msgSegList.RequestID = requestID; msgSegList.SegmentRangeCount = (uint)segmentRanges.Length; msgSegList.SegmentRanges = segmentRanges; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_SEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 }); packet.MsgSegList = msgSegList; packet.MessageHeader = messageHeader; return(packet); }
/// <summary> /// Create a MsgBlkList response. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="blockRanges">The blockRanges.</param> /// <param name="nextBlockIndex">The nextBlockIndex.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>The MsgBlkList response.</returns> public PccrrBLKLISTResponsePacket CreateMsgBlkListResponse( byte[] segmentId, BLOCK_RANGE[] blockRanges, uint nextBlockIndex, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { if (segmentId == null) { segmentId = new byte[0]; } if (blockRanges == null) { blockRanges = new BLOCK_RANGE[0]; } PccrrBLKLISTResponsePacket packet = new PccrrBLKLISTResponsePacket(); MSG_BLKLIST msgBlkListResp = new MSG_BLKLIST(); byte[] zeroPad = new byte[0] { }; msgBlkListResp.ZeroPad = zeroPad; msgBlkListResp.SizeOfSegmentId = (uint)segmentId.Length; msgBlkListResp.SegmentId = segmentId; msgBlkListResp.BlockRanges = blockRanges; msgBlkListResp.BlockRangeCount = (uint)blockRanges.Length; msgBlkListResp.NextBlockIndex = nextBlockIndex; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgBLKLIST = msgBlkListResp; packet.MessageHeader = messageHeader; return(packet); }
/// <summary> /// Create a MsgGetBlks request. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <param name="blockIndex">The block index.</param> /// <param name="blockCount">The block count.</param> /// <returns>MsgGetBlks request.</returns> public PccrrGETBLKSRequestPacket CreateMsgGetBlksRequest( byte[] segmentId, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues, uint blockIndex, uint blockCount) { if (segmentId == null) { segmentId = new byte[0]; } PccrrGETBLKSRequestPacket packet = new PccrrGETBLKSRequestPacket(); MSG_GETBLKS msgGetBlksReq = new MSG_GETBLKS(); msgGetBlksReq.DataForVrfBlock = null; byte[] zeroPad = new byte[0] { }; BLOCK_RANGE[] reqBlockRanges = new BLOCK_RANGE[1]; reqBlockRanges[0].Index = blockIndex; reqBlockRanges[0].Count = blockCount; msgGetBlksReq.ReqBlockRanges = reqBlockRanges; msgGetBlksReq.ReqBlockRangeCount = (uint)reqBlockRanges.Length; msgGetBlksReq.ZeroPad = zeroPad; msgGetBlksReq.SizeOfSegmentID = (uint)segmentId.Length; msgGetBlksReq.SizeOfDataForVrfBlock = 0; msgGetBlksReq.SegmentID = segmentId; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgGetBLKS = msgGetBlksReq; packet.MessageHeader = messageHeader; return(packet); }
/// <summary> /// Create a MsgGetBlkList request. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="blockRanges">The needed BlockRanges.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>MsgGetBlkList request.</returns> public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest( byte[] segmentId, BLOCK_RANGE[] blockRanges, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { if (segmentId == null) { segmentId = new byte[0]; } if (blockRanges == null) { blockRanges = new BLOCK_RANGE[0]; } PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket(); MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST(); byte[] zeroPad = new byte[0] { }; msgGetBlkListReq.SegmentID = segmentId; msgGetBlkListReq.SizeOfSegmentID = (uint)segmentId.Length; msgGetBlkListReq.NeededBlockRanges = blockRanges; msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length; msgGetBlkListReq.ZeroPad = zeroPad; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgGetBLKLIST = msgGetBlkListReq; packet.MessageHeader = messageHeader; return(packet); }
public void HostedCacheServer_PchcServer_InitialOffer_ContentRereieved() { CheckApplicability(); EventQueue eventQueue = new EventQueue(BaseTestSite); eventQueue.Timeout = testConfig.Timeout; Content_Information_Data_Structure contentInformation = contentInformationUtility.CreateContentInformationV1(); CryptoAlgoId_Values cryptoAlgoId = CryptoAlgoId_Values.AES_128; using (PccrrTestServerV1 pccrrTestServer = new PccrrTestServerV1()) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR server to be ready to serve content to hosted cache server"); pccrrTestServer.Start( testConfig.ClientContentRetrievalListenPort, cryptoAlgoId, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, contentInformation, TestUtility.GenerateRandomArray(ContentInformationUtility.DefaultBlockSize), eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTPS, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPSListenPort, PchcConsts.HttpsUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); BaseTestSite.Log.Add( LogEntryKind.Debug, "Send initial offer message to hosted cache server"); SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage( testConfig.ClientContentRetrievalListenPort, contentInformation, 0); pchcClient.SendSegmentInfoMessage(segmentInfoMessage); BaseTestSite.Log.Add( LogEntryKind.Debug, "Make sure all blocks in segment 0 are retrieved by 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 == contentInformation.segments[0].BlockCount); }, 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); INITIAL_OFFER_MESSAGE initialOfferMessage = pchcClient.CreateInitialOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformation.GetSegmentId(0)); Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pchc.RESPONSE_MESSAGE responseMessage2 = pchcClient.SendInitialOfferMessage(initialOfferMessage); TestClassBase.BaseTestSite.Assert.AreEqual <RESPONSE_CODE>( RESPONSE_CODE.INTERESTED, responseMessage2.ResponseCode, @"The hosted cache MUST specify a response code of 0 if it already has block data and block hash."); } }
public void HostedCacheServer_PccrrClient_MessageHeader_CryptoAlgoIdV2(CryptoAlgoId_Values algoId) { CheckApplicability(); EventQueue eventQueue = new EventQueue(BaseTestSite); eventQueue.Timeout = testConfig.Timeout; byte[] content = TestUtility.GenerateRandomArray(ContentInformationUtility.DefaultBlockSize); Content_Information_Data_Structure_V2 contentInformationV2 = contentInformationUtility.CreateContentInformationV2(); ProtoVersion protoVersion = new ProtoVersion { MajorVersion = 2, MinorVersion = ushort.MaxValue }; BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR server to be ready to serve content to hosted cache server"); using (PccrrTestServerV2 pccrrTestServerV2 = new PccrrTestServerV2()) { pccrrTestServerV2.Start( testConfig.ClientContentRetrievalListenPort, algoId, contentInformationV2, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTP, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort, PchcConsts.HttpUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); var batchedOfferMessage = pchcClient.CreateBatchedOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformationV2); pchcClient.SendBatchedOfferMessage(batchedOfferMessage); BaseTestSite.Log.Add( LogEntryKind.Debug, "Offer content segment 0 of chunk 0 to hosted cache server"); int segmentCount = 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) { segmentCount++; } }); return segmentCount == 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 segment 0 of chunk 0 from hosted cache server", 0); PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest( contentInformationV2.GetSegmentId(0,0), algoId, MsgType_Values.MSG_GETBLKS, (uint)0, 1); pccrrClient.SendPacket( pccrrBlkRequest, testConfig.Timeout); PccrrBLKResponsePacket pccrrBlkResponse = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket(); byte[] data = pccrrBlkResponse.MsgBLK.Block; if (algoId != CryptoAlgoId_Values.NoEncryption) data = PccrrUtitlity.Decrypt(aes, data, contentInformationV2.chunks[0].chunkData[0].SegmentSecret, pccrrBlkResponse.MsgBLK.IVBlock); BaseTestSite.Assert.IsTrue( Enumerable.SequenceEqual(content.Take((int)contentInformationV2.chunks[0].chunkData[0].cbSegment), data), "The retrieved cached data should be the same as server data."); }
/// <summary> /// Create a MsgGetSegList request. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentIDs">Array of segment IDs.</param> /// <param name="extensibleBlob">Extensible blob.</param> /// <returns>MsgGetSegList request.</returns> public PccrrGetSegListRequestPacket CreateMsgGetSegListRequest( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, byte[][] segmentIDs, byte[] extensibleBlob) { var packet = new PccrrGetSegListRequestPacket(); var msgGetSegList = new MSG_GETSEGLIST(); msgGetSegList.RequestID = requestID; msgGetSegList.CountOfSegmentIDs = (uint)segmentIDs.Length; msgGetSegList.SegmentIDs = new SegmentIDStructure[segmentIDs.Length]; for (int i = 0; i < segmentIDs.Length; i++) { msgGetSegList.SegmentIDs[i] = new SegmentIDStructure(segmentIDs[i]); } ///[MS-PCCRR]Section 2.2.4.4 SizeOfExtensibleBlob: Size, in bytes, of the ExtensibleBlob field. Implementations MAY support extensible blobs in MSG_GETSEGLIST ///message.Implementations that do not support extensible blobs in MSG_GETSEGLIST messages MUST set SizeOfExtensibleBlob to zero and omit the ExtensibleBlob field. msgGetSegList.SizeOfExtensibleBlob = (uint)extensibleBlob.Length; msgGetSegList.ExtensibleBlob = extensibleBlob; packet.MsgGetSegList = msgGetSegList; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_GETSEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 }); messageHeader.MsgSize += (uint)TypeMarshal.GetBlockMemorySize(msgGetSegList); packet.MessageHeader = messageHeader; return packet; }
/// <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; }
/// <summary> /// Create a MsgGetBlks request. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>MsgGetBlks request.</returns> public PccrrGETBLKSRequestPacket CreateMsgGetBlksRequest( byte[] segmentId, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { if (segmentId == null) { segmentId = new byte[0]; } PccrrGETBLKSRequestPacket packet = new PccrrGETBLKSRequestPacket(); MSG_GETBLKS msgGetBlksReq = new MSG_GETBLKS(); msgGetBlksReq.DataForVrfBlock = null; byte[] zeroPad = new byte[0] { }; BLOCK_RANGE[] reqBlockRanges = new BLOCK_RANGE[1]; reqBlockRanges[0].Index = 0; reqBlockRanges[0].Count = 1; msgGetBlksReq.ReqBlockRanges = reqBlockRanges; msgGetBlksReq.ReqBlockRangeCount = (uint)reqBlockRanges.Length; msgGetBlksReq.ZeroPad = zeroPad; msgGetBlksReq.SizeOfSegmentID = (uint)segmentId.Length; msgGetBlksReq.SizeOfDataForVrfBlock = 0; msgGetBlksReq.SegmentID = segmentId; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgGetBLKS = msgGetBlksReq; packet.MessageHeader = messageHeader; return packet; }
/// <summary> /// Create a MsgGetSegList request. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentIDs">Array of segment IDs.</param> /// <returns>MsgGetSegList request.</returns> public PccrrGetSegListRequestPacket CreateMsgGetSegListRequest( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, byte[][] segmentIDs) { return CreateMsgGetSegListRequest(cryptoAlgoIdValues, requestID, segmentIDs, new byte[0]); }
public void HostedCacheServer_BVT_CacheOfferingRetrieval_V2() { CheckApplicability(); EventQueue eventQueue = new EventQueue(BaseTestSite); eventQueue.Timeout = testConfig.Timeout; BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve the original content data from content server"); byte[] content = contentInformationUtility.RetrieveContentData(); BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve the content information from content server"); Content_Information_Data_Structure_V2 contentInformation = PccrcUtility.ParseContentInformationV2(contentInformationUtility.RetrieveContentInformation(BranchCacheVersion.V2)); CryptoAlgoId_Values cryptoAlgoId = CryptoAlgoId_Values.AES_128; PccrrClient pccrrClient = new PccrrClient(testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort); BaseTestSite.Log.Add( LogEntryKind.Debug, "Send PCCRR GetSegList request to HostedCacheServer to make sure that this file does not exist in HostedCacheServer."); for (int i = 0; i < contentInformation.chunks.Length; ++i) { var chunk = contentInformation.chunks[i]; for (int j = 0; j < chunk.chunkData.Length; j++) { var pccrrGetSegListRequest = pccrrClient.CreateMsgGetSegListRequest( cryptoAlgoId, Guid.NewGuid(), new byte[][] { contentInformation.GetSegmentId(i, j) }); pccrrClient.SendPacket( pccrrGetSegListRequest, testConfig.Timeout); var pccrrGetSegListResponse = (PccrrSegListResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreEqual <uint>( 0, pccrrGetSegListResponse.MsgSegList.SegmentRangeCount, "The server MUST set the SegmentRangeCount field to zero if it doesn't have the requested segments data."); } } using (PccrrTestServerV2 pccrrTestServer = new PccrrTestServerV2()) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR server to be ready to serve content to hosted cache server"); pccrrTestServer.Start( testConfig.ClientContentRetrievalListenPort, cryptoAlgoId, contentInformation, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTP, testConfig.HostedCacheServerComputerName, testConfig.ContentServerHTTPListenPort, PchcConsts.HttpUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); BaseTestSite.Log.Add( LogEntryKind.Debug, "Offer all content segments to hosted cache server"); var batchedOfferMessage = pchcClient.CreateBatchedOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformation); var responseMessage = pchcClient.SendBatchedOfferMessage(batchedOfferMessage); TestClassBase.BaseTestSite.Assert.AreEqual <RESPONSE_CODE>( RESPONSE_CODE.OK, responseMessage.ResponseCode, @"The hosted cache MUST send a response code of 0 when BATCHED_OFFER_MESSAGE request received"); BaseTestSite.Log.Add( LogEntryKind.Debug, "Make sure all segments are retrieved by hosted cache server"); int totalBlockCount = contentInformation.GetBlockCount(); 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 == totalBlockCount); }, 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); } List <byte> retrievedContent = new List <byte>(); BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR client to retrieve all the content from hosted cache server"); BaseTestSite.Log.Add( LogEntryKind.Debug, "Negotiate PCCRR version"); var pccrrNegotiateRequest = pccrrClient.CreateMsgNegoRequest( ///[MS-PCCRR]Section 2.2.3: ProtVer: Both the Major and Minor version number can express the version range of 0x0000 to 0xFFFF. Currently, the protocol ///version number MUST be set to {major = 1 (0x0001), minor = 0 (0x0000)}. ///Active TDI#69240: Windows server 2012 Standard RTM sets the major version to 2 new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, //MinSupportedProtocolVersion new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, //MaxSupportedProtocolVersion cryptoAlgoId, MsgType_Values.MSG_NEGO_REQ); pccrrClient.SendPacket( pccrrNegotiateRequest, testConfig.Timeout); var pccrrNegotiateResponse = (PccrrNegoResponsePacket)pccrrClient.ExpectPacket(); if (testConfig.SupportBranchCacheV1) { BaseTestSite.Assert.IsTrue( pccrrNegotiateResponse.MsgNegoResp.MinSupporteProtocolVersion.MajorVersion <= 1 && pccrrNegotiateResponse.MsgNegoResp.MaxSupporteProtocolVersion.MajorVersion >= 1, "SupportedProtocolVersion doesn't match configuration"); } Aes aes = PccrrUtitlity.CreateAes(cryptoAlgoId); for (int i = 0; i < contentInformation.chunks.Length; i++) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve all segments in chunk {0}", i); var chunk = contentInformation.chunks[i]; for (int j = 0; j < chunk.chunkData.Length; j++) { // Retrieve segment list var pccrrGetSegListRequest = pccrrClient.CreateMsgGetSegListRequest( cryptoAlgoId, Guid.NewGuid(), new byte[][] { contentInformation.GetSegmentId(i, j) }); pccrrClient.SendPacket( pccrrGetSegListRequest, testConfig.Timeout); var pccrrGetSegListResponse = (PccrrSegListResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreNotEqual <uint>( 0, pccrrGetSegListResponse.MsgSegList.SegmentRangeCount, "The server MUST set the SegmentRangeCount field to a value greater than zero if it has the requested segments data."); BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve segment {0} in chunk {1}", j, i); PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest( contentInformation.GetSegmentId(i, j), cryptoAlgoId, MsgType_Values.MSG_GETBLKS, 0, 1); pccrrClient.SendPacket( pccrrBlkRequest, testConfig.Timeout); PccrrBLKResponsePacket pccrrBlkResponse = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreNotEqual <uint>( 0, pccrrBlkResponse.MsgBLK.SizeOfBlock, "The server MUST set the SizeOfBlock field to a value greater than zero if it has the requested blocks data."); byte[] block = pccrrBlkResponse.MsgBLK.Block; if (cryptoAlgoId != CryptoAlgoId_Values.NoEncryption) { block = PccrrUtitlity.Decrypt(aes, block, contentInformation.chunks[i].chunkData[j].SegmentSecret, pccrrBlkResponse.MsgBLK.IVBlock); } retrievedContent.AddRange(block); } } BaseTestSite.Assert.IsTrue( Enumerable.SequenceEqual(content, retrievedContent), "The retrieved cached data should be the same as server data."); }
/// <summary> /// Create a MsgBlkList response. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="blockRanges">The blockRanges.</param> /// <param name="nextBlockIndex">The nextBlockIndex.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>The MsgBlkList response.</returns> public PccrrBLKLISTResponsePacket CreateMsgBlkListResponse( byte[] segmentId, BLOCK_RANGE[] blockRanges, uint nextBlockIndex, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { if (segmentId == null) { segmentId = new byte[0]; } if (blockRanges == null) { blockRanges = new BLOCK_RANGE[0]; } PccrrBLKLISTResponsePacket packet = new PccrrBLKLISTResponsePacket(); MSG_BLKLIST msgBlkListResp = new MSG_BLKLIST(); byte[] zeroPad = new byte[0] { }; msgBlkListResp.ZeroPad = zeroPad; msgBlkListResp.SizeOfSegmentId = (uint)segmentId.Length; msgBlkListResp.SegmentId = segmentId; msgBlkListResp.BlockRanges = blockRanges; msgBlkListResp.BlockRangeCount = (uint)blockRanges.Length; msgBlkListResp.NextBlockIndex = nextBlockIndex; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgBLKLIST = msgBlkListResp; packet.MessageHeader = messageHeader; return packet; }
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_PccrrClient_MessageHeader_ProtoVerIncompatible() { 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 (PccrrTestIncompatibleProtoVerServer pccrrTestServer = new PccrrTestIncompatibleProtoVerServer()) { 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 incompatible proto version 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); } }
public void StartListen(int port, CryptoAlgoId_Values cryptoAlgoId, Content_Information_Data_Structure_V2 contentInformationV2, byte[] content, EventQueue eventQueue) { this.contentInformationV2 = contentInformationV2; base.Start(port, cryptoAlgoId, content, eventQueue); }
public void Start(int port, CryptoAlgoId_Values cryptoAlgoId, Content_Information_Data_Structure_V2 contentInformationV2, byte[] content, EventQueue eventQueue) { this.contentInformationV2 = contentInformationV2; base.Start(port, cryptoAlgoId, content, eventQueue); }
/// <summary> /// Create a MsgSegList response. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentRanges">Segment ranges.</param> /// <returns>The MsgSegList response.</returns> public PccrrSegListResponsePacket CreateSegListResponse( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, BLOCK_RANGE[] segmentRanges) { var packet = new PccrrSegListResponsePacket(); var msgSegList = new MSG_SEGLIST(); msgSegList.RequestID = requestID; msgSegList.SegmentRangeCount = (uint)segmentRanges.Length; msgSegList.SegmentRanges = segmentRanges; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_SEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 }); packet.MsgSegList = msgSegList; packet.MessageHeader = messageHeader; return packet; }
/// <summary> /// Create a MsgBlk response. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="block">The block.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <param name="isLastBLKAvail">If it is true, the block is the last available block.</param> /// <returns>The MsgBlk response.</returns> public PccrrBLKResponsePacket CreateMsgBlkResponse( byte[] segmentId, byte[] block, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues, bool isLastBLKAvail) { if (segmentId == null) { segmentId = new byte[0]; } if (block == null) { block = new byte[0]; } PccrrBLKResponsePacket packet = new PccrrBLKResponsePacket(); MSG_BLK msgBlkResp = new MSG_BLK(); byte[] zeroPad = new byte[0] { }; byte[] zeroPad_2 = new byte[0] { }; byte[] zeroPad_3 = new byte[0] { }; byte[] iVBlock = new byte[0] { }; msgBlkResp.ZeroPad3 = zeroPad_3; msgBlkResp.ZeroPad2 = zeroPad_2; msgBlkResp.ZeroPad = zeroPad; msgBlkResp.VrfBlock = null; msgBlkResp.SizeOfVrfBlock = 0; msgBlkResp.SizeOfSegmentId = (uint)segmentId.Length; msgBlkResp.SizeOfIVBlock = (uint)iVBlock.Length; msgBlkResp.SizeOfBlock = (uint)block.Length; msgBlkResp.SegmentId = segmentId; msgBlkResp.IVBlock = iVBlock; msgBlkResp.Block = block; msgBlkResp.BlockIndex = 0; if (!isLastBLKAvail) { msgBlkResp.NextBlockIndex = 1; } else { msgBlkResp.NextBlockIndex = 0; } MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgBLK = msgBlkResp; packet.MessageHeader = messageHeader; return packet; }
public void HostedCacheServer_BVT_CacheOfferingRetrieval_V1() { CheckApplicability(); EventQueue eventQueue = new EventQueue(BaseTestSite); eventQueue.Timeout = testConfig.Timeout; BaseTestSite.Log.Add( LogEntryKind.Debug, "Trigger hash generation on content server"); byte[] content = contentInformationUtility.RetrieveContentData(); Content_Information_Data_Structure contentInformation = PccrcUtility.ParseContentInformation(contentInformationUtility.RetrieveContentInformation(BranchCacheVersion.V1)); CryptoAlgoId_Values cryptoAlgoId = CryptoAlgoId_Values.AES_128; PccrrClient pccrrClient = new PccrrClient(testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort); for (int i = 0; i < contentInformation.cSegments; ++i) { var pccrrBlkListRequest = pccrrClient.CreateMsgGetBlkListRequest( contentInformation.GetSegmentId(i), new BLOCK_RANGE[] { new BLOCK_RANGE { Index = 0, Count = contentInformation.segments[i].BlockCount } }, cryptoAlgoId, MsgType_Values.MSG_GETBLKLIST); pccrrClient.SendPacket( pccrrBlkListRequest, testConfig.Timeout); var pccrrBlkListResponse = (PccrrBLKLISTResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreEqual <uint>( 0, pccrrBlkListResponse.MsgBLKLIST.BlockRangeCount, "The server MUST set the BlockRangeCount field to zero if it doesn't have the requested blocks data."); } BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve content information from content server"); using (PccrrTestServerV1 pccrrTestServer = new PccrrTestServerV1()) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR server to be ready to serve content to hosted cache server"); pccrrTestServer.Start( testConfig.ClientContentRetrievalListenPort, cryptoAlgoId, contentInformation, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTPS, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPSListenPort, PchcConsts.HttpsUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); for (int i = 0; i < contentInformation.cSegments; i++) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Offer content segment {0} to hosted cache server", i); INITIAL_OFFER_MESSAGE initialOfferMessage = pchcClient.CreateInitialOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformation.GetSegmentId(i)); Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pchc.RESPONSE_MESSAGE responseMessage = pchcClient.SendInitialOfferMessage(initialOfferMessage); TestClassBase.BaseTestSite.Assert.AreEqual <RESPONSE_CODE>( RESPONSE_CODE.INTERESTED, responseMessage.ResponseCode, @"The hosted cache MUST specify a response code of 1 if its list of block hashes associated with the segment is incomplete."); BaseTestSite.Log.Add( LogEntryKind.Debug, "Supply segment info to hosted cache server"); SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage( testConfig.ClientContentRetrievalListenPort, contentInformation, i); responseMessage = pchcClient.SendSegmentInfoMessage(segmentInfoMessage); TestClassBase.BaseTestSite.Assert.AreEqual <RESPONSE_CODE>( RESPONSE_CODE.OK, responseMessage.ResponseCode, @"The hosted cache MUST send a response code of 0 when SEGMENT_INFO_MESSAGE request received"); BaseTestSite.Log.Add( LogEntryKind.Debug, "Make sure all blocks in segment {0} are retrieved by hosted cache server", i); 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 == contentInformation.segments[i].BlockCount); }, 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); } List <byte> retrievedContent = new List <byte>(); BaseTestSite.Log.Add( LogEntryKind.Debug, "Negotiate PCCRR version"); var pccrrNegotiateRequest = pccrrClient.CreateMsgNegoRequest( new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, new ProtoVersion { MajorVersion = 1, MinorVersion = ushort.MaxValue }, cryptoAlgoId, MsgType_Values.MSG_NEGO_REQ); pccrrClient.SendPacket( pccrrNegotiateRequest, testConfig.Timeout); var pccrrNegotiateResponse = (PccrrNegoResponsePacket)pccrrClient.ExpectPacket(); if (testConfig.SupportBranchCacheV1) { BaseTestSite.Assert.IsTrue( pccrrNegotiateResponse.MsgNegoResp.MinSupporteProtocolVersion.MajorVersion <= 1 && pccrrNegotiateResponse.MsgNegoResp.MaxSupporteProtocolVersion.MajorVersion >= 1, "SupportedProtocolVersion doesn't match configuration"); } if (testConfig.SupportBranchCacheV2) { BaseTestSite.Assert.IsTrue( pccrrNegotiateResponse.MsgNegoResp.MinSupporteProtocolVersion.MajorVersion <= 2 && pccrrNegotiateResponse.MsgNegoResp.MaxSupporteProtocolVersion.MajorVersion >= 2, "SupportedProtocolVersion doesn't match configuration"); } Aes aes = PccrrUtitlity.CreateAes(cryptoAlgoId); for (int i = 0; i < contentInformation.cSegments; i++) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve block list for segment {0}", i); var pccrrBlkListRequest = pccrrClient.CreateMsgGetBlkListRequest( contentInformation.GetSegmentId(i), new BLOCK_RANGE[] { new BLOCK_RANGE { Index = 0, Count = contentInformation.segments[i].BlockCount } }, cryptoAlgoId, MsgType_Values.MSG_GETBLKLIST); pccrrClient.SendPacket( pccrrBlkListRequest, testConfig.Timeout); var pccrrBlkListResponse = (PccrrBLKLISTResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreNotEqual <uint>( 0, pccrrBlkListResponse.MsgBLKLIST.BlockRangeCount, "The server MUST set the BlockRangeCount field to a value greater than zero if it has the requested blocks data."); for (int j = 0; j < contentInformation.segments[i].BlockCount; j++) { BaseTestSite.Log.Add( LogEntryKind.Debug, "Retrieve block {0} for segment {1}", j, i); PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest( contentInformation.GetSegmentId(i), cryptoAlgoId, MsgType_Values.MSG_GETBLKS, (uint)j, 1); pccrrClient.SendPacket( pccrrBlkRequest, testConfig.Timeout); PccrrBLKResponsePacket pccrrBlkResponse = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket(); BaseTestSite.Assert.AreNotEqual <uint>( 0, pccrrBlkResponse.MsgBLK.SizeOfBlock, "The server MUST set the SizeOfBlock field to a value greater than zero if it has the requested blocks data."); byte[] block = pccrrBlkResponse.MsgBLK.Block; if (cryptoAlgoId != CryptoAlgoId_Values.NoEncryption) { block = PccrrUtitlity.Decrypt(aes, block, contentInformation.segments[i].SegmentSecret, pccrrBlkResponse.MsgBLK.IVBlock); } retrievedContent.AddRange(block); } } BaseTestSite.Assert.IsTrue( Enumerable.SequenceEqual(content, retrievedContent), "The retrieved cached data should be the same as server data."); }
/// <summary> /// Create a MsgGetBlkList request. /// </summary> /// <param name="segmentId">The segmentId.</param> /// <param name="blockRanges">The needed BlockRanges.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>MsgGetBlkList request.</returns> public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest( byte[] segmentId, BLOCK_RANGE[] blockRanges, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { if (segmentId == null) { segmentId = new byte[0]; } if (blockRanges == null) { blockRanges = new BLOCK_RANGE[0]; } PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket(); MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST(); byte[] zeroPad = new byte[0] { }; msgGetBlkListReq.SegmentID = segmentId; msgGetBlkListReq.SizeOfSegmentID = (uint)segmentId.Length; msgGetBlkListReq.NeededBlockRanges = blockRanges; msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length; msgGetBlkListReq.ZeroPad = zeroPad; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgGetBLKLIST = msgGetBlkListReq; packet.MessageHeader = messageHeader; return packet; }
public void HostedCacheServer_PccrrClient_MessageHeader_CryptoAlgoIdV2(CryptoAlgoId_Values algoId) { CheckApplicability(); EventQueue eventQueue = new EventQueue(BaseTestSite); eventQueue.Timeout = testConfig.Timeout; byte[] content = TestUtility.GenerateRandomArray(ContentInformationUtility.DefaultBlockSize); Content_Information_Data_Structure_V2 contentInformationV2 = contentInformationUtility.CreateContentInformationV2(); ProtoVersion protoVersion = new ProtoVersion { MajorVersion = 2, MinorVersion = ushort.MaxValue }; BaseTestSite.Log.Add( LogEntryKind.Debug, "Start PCCRR server to be ready to serve content to hosted cache server"); using (PccrrTestServerV2 pccrrTestServerV2 = new PccrrTestServerV2()) { pccrrTestServerV2.Start( testConfig.ClientContentRetrievalListenPort, algoId, contentInformationV2, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTP, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort, PchcConsts.HttpUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); var batchedOfferMessage = pchcClient.CreateBatchedOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformationV2); pchcClient.SendBatchedOfferMessage(batchedOfferMessage); BaseTestSite.Log.Add( LogEntryKind.Debug, "Offer content segment 0 of chunk 0 to hosted cache server"); int segmentCount = 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) { segmentCount++; } }); return(segmentCount == 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 segment 0 of chunk 0 from hosted cache server", 0); PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest( contentInformationV2.GetSegmentId(0, 0), algoId, MsgType_Values.MSG_GETBLKS, (uint)0, 1); pccrrClient.SendPacket( pccrrBlkRequest, testConfig.Timeout); PccrrBLKResponsePacket pccrrBlkResponse = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket(); byte[] data = pccrrBlkResponse.MsgBLK.Block; if (algoId != CryptoAlgoId_Values.NoEncryption) { data = PccrrUtitlity.Decrypt(aes, data, contentInformationV2.chunks[0].chunkData[0].SegmentSecret, pccrrBlkResponse.MsgBLK.IVBlock); } BaseTestSite.Assert.IsTrue( Enumerable.SequenceEqual(content.Take((int)contentInformationV2.chunks[0].chunkData[0].cbSegment), data), "The retrieved cached data should be the same as server data."); }
public void HostedCacheServer_PccrrServer_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(); 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, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, contentInformation, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTPS, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPSListenPort, PchcConsts.HttpsUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); BaseTestSite.Log.Add( LogEntryKind.Debug, "Directly Supply segment info to hosted cache server"); SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage( testConfig.ClientContentRetrievalListenPort, contentInformation, 0); pchcClient.SendSegmentInfoMessage(segmentInfoMessage); BaseTestSite.Log.Add( LogEntryKind.Debug, "Make sure block 0 in segment 0 is retrieved by 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 in segment 0 from hosted cache server"); 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."); }
/// <summary> /// Initialize adapter data and create connection. /// </summary> /// <param name="testSite">the test site</param> public override void Initialize(ITestSite testSite) { base.Initialize(ReqConfigurableSite.GetReqConfigurableSite(testSite)); this.Site.DefaultProtocolDocShortName = "MS-PCCRR"; this.isDistributedMode = bool.Parse(this.GetProperty("Environment.IsDistributedMode")); if (!this.isDistributedMode) { this.isWindows = string.Equals( testSite.Properties["Environment.SecondContentClient.OSVersion"], "win2k8r2", StringComparison.OrdinalIgnoreCase); } else { this.isWindows = string.Equals( testSite.Properties["Environment.DistributedSUT.OSVersion"], "win2k8r2", StringComparison.OrdinalIgnoreCase); } this.cryptoAlgo = (CryptoAlgoId_Values)Enum.Parse(typeof(CryptoAlgoId_Values), this.GetProperty("PCCRR.Protocol.CryptoAlgoId_Value")); this.port = int.Parse(this.GetProperty("PCCRR.Protocol.HttpPort")); PccrrBothRoleCaptureCode.Initialize(this.Site); this.minSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MinSupportedProtocolVersion.MinorVer")); this.minSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MinSupportedProtocolVersion.MajorVer")); this.maxSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MinorVer")); this.maxSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer")); this.minErrorSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.Error.MinSupportedProtocolVersion")); this.minErrorSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer")); this.maxErrorSupV.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.Error.MaxSupportedProtocolVersion")); this.maxErrorSupV.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer")); this.protoVer.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MinorVer")); this.protoVer.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MajorVer")); this.protoErrorVer.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.ErrorProtocolVersion")); this.protoErrorVer.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer")); this.pccrrStackSer = new PccrrServer(this.port, string.Empty, IPAddressType.IPv4); this.pccrrStackSer.MessageArrived += new MessageArrivedEventArgs(this.RetrievalTransport_Receive); this.pccrrStackSer.StartListening(); }
public void HostedCacheServer_PccrrServer_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(); 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, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }, contentInformation, content, eventQueue); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTPS, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPSListenPort, PchcConsts.HttpsUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); BaseTestSite.Log.Add( LogEntryKind.Debug, "Directly Supply segment info to hosted cache server"); SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage( testConfig.ClientContentRetrievalListenPort, contentInformation, 0); pchcClient.SendSegmentInfoMessage(segmentInfoMessage); BaseTestSite.Log.Add( LogEntryKind.Debug, "Make sure block 0 in segment 0 is retrieved by 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 in segment 0 from hosted cache server"); 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."); }