/// <summary> /// Send ROP request through MAPI over HTTP /// </summary> /// <param name="rgbIn">ROP request buffer.</param> /// <param name="pcbOut">The maximum size of the rgbOut buffer to place response in.</param> /// <param name="rawData">The response payload bytes.</param> /// <returns>0 indicates success, other values indicate failure. </returns> public uint Execute(byte[] rgbIn, uint pcbOut, out byte[] rawData) { uint ret = 0; ExecuteRequestBody executeBody = new ExecuteRequestBody(); // Client requests server to not compress or XOR payload of rgbOut and rgbAuxOut. executeBody.Flags = 0x00000003; executeBody.RopBufferSize = (uint)rgbIn.Length; executeBody.RopBuffer = rgbIn; // Set the max size of the rgbAuxOut executeBody.MaxRopOut = pcbOut; // 0x10008; executeBody.AuxiliaryBufferSize = 0; executeBody.AuxiliaryBuffer = new byte[] { }; HttpWebResponse response = SendMAPIHttpRequest( this.site, this.mailStoreUrl, this.userName, this.domain, this.userPassword, executeBody, "Execute", this.cookies); string responseCode = response.Headers["X-ResponseCode"]; byte[] rawBuffer = ReadHttpResponse(response); response.GetResponseStream().Close(); if (int.Parse(responseCode) == 0) { ChunkedResponse chunkedResponse = ChunkedResponse.ParseChunkedResponse(rawBuffer); ExecuteSuccessResponseBody responseSuccess = ExecuteSuccessResponseBody.Parse(chunkedResponse.ResponseBodyRawData); rawData = responseSuccess.RopBuffer; ret = responseSuccess.ErrorCode; } else { rawData = null; this.site.Assert.Fail("MAPIHTTP call failed, the error code returned from server is: {0}", responseCode); } this.cookies = response.Cookies; return(ret); }
/// <summary> /// Parse the Execute request type success response body. /// </summary> /// <param name="rawData">The raw data which is returned by server.</param> /// <returns>An instance of ExecuteSuccessResponseBody class.</returns> public static ExecuteSuccessResponseBody Parse(byte[] rawData) { ExecuteSuccessResponseBody responseBody = new ExecuteSuccessResponseBody(); int index = 0; responseBody.StatusCode = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.Flags = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.RopBufferSize = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.RopBuffer = new byte[responseBody.RopBufferSize]; Array.Copy(rawData, index, responseBody.RopBuffer, 0, responseBody.RopBufferSize); index += (int)responseBody.RopBufferSize; responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize]; Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize); return responseBody; }
/// <summary> /// Parse the Execute request type success response body. /// </summary> /// <param name="rawData">The raw data which is returned by server.</param> /// <returns>An instance of ExecuteSuccessResponseBody class.</returns> public static ExecuteSuccessResponseBody Parse(byte[] rawData) { ExecuteSuccessResponseBody responseBody = new ExecuteSuccessResponseBody(); int index = 0; responseBody.StatusCode = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.Flags = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.RopBufferSize = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.RopBuffer = new byte[responseBody.RopBufferSize]; Array.Copy(rawData, index, responseBody.RopBuffer, 0, responseBody.RopBufferSize); index += (int)responseBody.RopBufferSize; responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize]; Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize); return(responseBody); }
/// <summary> /// Verify the Execute success response body related requirements. /// </summary> /// <param name="executeSuccessResponseBody">The Execute success response body to be verified.</param> private void VerifyExecuteSuccessResponseBody(ExecuteSuccessResponseBody executeSuccessResponseBody) { // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R250"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R250 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.StatusCode, typeof(uint), 250, @"[In Execute Request Type Success Response Body] StatusCode (4 bytes): An unsigned integer that specifies the status of the request."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1356"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1356 this.Site.CaptureRequirementIfAreEqual<uint>( 0, executeSuccessResponseBody.StatusCode, 1356, @"[In Execute Request Type Success Response Body] [StatusCode] This field MUST be set to 0x00000000."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R251"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R251 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.ErrorCode, typeof(uint), 251, @"[In Execute Request Type Success Response Body] ErrorCode (4 bytes): An unsigned integer that specifies the return status of the operation."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R245"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R245 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.Flags, typeof(uint), 245, @"[In Execute Request Type Success Response Body] The Data type of Field Flags is DWORD."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1358"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1358 this.Site.CaptureRequirementIfAreEqual<uint>( 0, executeSuccessResponseBody.Flags, 1358, @"[In Execute Request Type Success Response Body] [Flags] The server MUST set this field to 0x00000000."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R253"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R253 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.RopBufferSize, typeof(uint), 253, @"[In Execute Request Type Success Response Body] RopBufferSize (4 bytes): An unsigned integer that specifies the size, in bytes, of the RopBuffer field."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R254"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R254 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.RopBuffer, typeof(byte[]), 254, @"[In Execute Request Type Success Response Body] RopBuffer (variable): An array of bytes that constitute the ROP responses payload."); // Add the debug information this.Site.Log.Add( LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1360, the length of RopBuffer is {0}, the value of RopBufferSize is {1}.", executeSuccessResponseBody.RopBuffer.Length, executeSuccessResponseBody.RopBufferSize); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1360 this.Site.CaptureRequirementIfAreEqual<uint>( executeSuccessResponseBody.RopBufferSize, (uint)executeSuccessResponseBody.RopBuffer.Length, 1360, @"[In Execute Request Type Success Response Body] [RopBuffer] The size of this field, in bytes, is specified by the RopBufferSize field."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R255"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R255 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.AuxiliaryBufferSize, typeof(uint), 255, @"[In Execute Request Type Success Response Body] AuxiliaryBufferSize (4 bytes): An unsigned integer that specifies the size, in bytes, of the AuxiliaryBuffer field."); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R256"); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R256 this.Site.CaptureRequirementIfIsInstanceOfType( executeSuccessResponseBody.AuxiliaryBuffer, typeof(byte[]), 256, @"[In Execute Request Type Success Response Body] AuxiliaryBuffer (variable): An array of bytes that constitute the auxiliary payload data returned from the server."); // Add the debug information this.Site.Log.Add( LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1361, the length of AuxiliaryBuffer is {0}, the value of AuxiliaryBufferSize is {1}.", executeSuccessResponseBody.AuxiliaryBuffer.Length, executeSuccessResponseBody.AuxiliaryBufferSize); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1361 this.Site.CaptureRequirementIfAreEqual<uint>( executeSuccessResponseBody.AuxiliaryBufferSize, (uint)executeSuccessResponseBody.AuxiliaryBuffer.Length, 1361, @"[In Execute Request Type Success Response Body] [AuxiliaryBuffer] The size of this field, in bytes, is specified by the AuxiliaryBufferSize field."); }