/// <summary> /// Operations after Negotiate, from Session Setup to Log off. /// </summary> private void PostNegotiateOperations(EnableEncryptionType enableEncryptionType, bool connectEncryptedShare) { BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends SESSION_SETUP request and expects response."); client.SessionSetup( TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, TestConfig.UseServerGssToken); if (enableEncryptionType == EnableEncryptionType.EnableEncryptionPerSession) { // After calling this method, client will send encrypted message after session setup BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client enables global encryption."); client.EnableSessionSigningAndEncryption(enableSigning: false, enableEncryption: true); } string uncSharepath = Smb2Utility.GetUncPath(TestConfig.SutComputerName, connectEncryptedShare ? TestConfig.EncryptedFileShare : TestConfig.BasicFileShare); uint treeId; BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends TREE_CONNECT to share: {0}", uncSharepath); client.TreeConnect( uncSharepath, out treeId, (Packet_Header header, TREE_CONNECT_Response response) => { BaseTestSite.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "TreeConnect should succeed, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status)); if (connectEncryptedShare) { BaseTestSite.Assert.AreEqual( ShareFlags_Values.SHAREFLAG_ENCRYPT_DATA, ShareFlags_Values.SHAREFLAG_ENCRYPT_DATA & response.ShareFlags, "Server should set SMB2_SHAREFLAG_ENCRYPT_DATA for ShareFlags field in TREE_CONNECT response"); } else { BaseTestSite.Assert.AreNotEqual( ShareFlags_Values.SHAREFLAG_ENCRYPT_DATA, ShareFlags_Values.SHAREFLAG_ENCRYPT_DATA & response.ShareFlags, "Server should not set SMB2_SHAREFLAG_ENCRYPT_DATA for ShareFlags field in TREE_CONNECT response"); } }); if (enableEncryptionType == EnableEncryptionType.EnableEncryptionPerShare) { // After calling this method, client will send encrypted message after tree connect. BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client enables per share encryption: TreeId=0x{0:x}", treeId); client.SetTreeEncryption(treeId, true); } FILEID fileId; Smb2CreateContextResponse[] serverCreateContexts; BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends encrypted CREATE request and expects success."); client.Create( treeId, CurrentTestCaseName + "_" + Guid.NewGuid() + ".txt", CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE, out fileId, out serverCreateContexts); string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends encrpyted WRITE request and expects success."); client.Write(treeId, fileId, content); string actualContent; BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends encrypted READ request and expects success."); client.Read(treeId, fileId, 0, (uint)content.Length, out actualContent); BaseTestSite.Assert.IsTrue( content.Equals(actualContent), "File content read should be identical to that has been written."); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF"); client.Close(treeId, fileId); client.TreeDisconnect(treeId); client.LogOff(); }