private void CheckCompressionAlgorithmsForWindowsImplementation(CompressionAlgorithm[] compressionAlgorithms) { if (TestConfig.Platform <= Platform.WindowsServerV1909) { bool isExpectedWindowsCompressionContext = client.Smb2Client.CompressionInfo.CompressionIds.Length == 1 && client.Smb2Client.CompressionInfo.CompressionIds[0] == compressionAlgorithms[0]; BaseTestSite.Assert.IsTrue(isExpectedWindowsCompressionContext, "Windows 10 v1903, Windows 10 v1909, Windows Server v1903, and Windows Server v1909 only set CompressionAlgorithms to the first common algorithm supported by the client and server."); } else { var firstSupportedCompressionAlgorithm = Smb2Utility.GetSupportedCompressionAlgorithms(compressionAlgorithms.ToArray()).Take(1); var firstSupportedPatternScanningAlgorithm = Smb2Utility.GetSupportedPatternScanningAlgorithms(compressionAlgorithms.ToArray()).Take(1); var expectedCompressionAlgorithms = firstSupportedCompressionAlgorithm.Concat(firstSupportedPatternScanningAlgorithm); bool isExpectedWindowsCompressionContext = Enumerable.SequenceEqual(client.Smb2Client.CompressionInfo.CompressionIds.OrderBy(compressionAlgorithm => compressionAlgorithm), expectedCompressionAlgorithms.OrderBy(compressionAlgorithm => compressionAlgorithm)); BaseTestSite.Assert.IsTrue(isExpectedWindowsCompressionContext, "Windows 10 v2004 and Windows Server v2004 select a common pattern scanning algorithm and the first common compression algorithm, specified in section 2.2.3.1.3, supported by the client and server."); } }
private void FetchSmb2CompressionInfo(Smb2Info smb2Info) { if (smb2Info.MaxSupportedDialectRevision < DialectRevision.Smb311) { logWriter.AddLog(LogLevel.Information, "SMB dialect less than 3.1.1 does not support compression."); smb2Info.SupportedCompressionAlgorithms = new CompressionAlgorithm[0]; smb2Info.IsChainedCompressionSupported = false; return; } var allCompressionAlogrithms = Enum.GetValues(typeof(CompressionAlgorithm)).Cast <CompressionAlgorithm>().ToArray(); var possibleCompressionAlogrithms = Smb2Utility.GetSupportedPatternScanningAlgorithms(allCompressionAlogrithms).Concat(Smb2Utility.GetSupportedCompressionAlgorithms(allCompressionAlogrithms)); // Iterate all possible compression algorithm for Windows will only return only one supported compression algorithm in response. var result = possibleCompressionAlogrithms.Where(compressionAlgorithm => { using (var client = new Smb2Client(new TimeSpan(0, 0, defaultTimeoutInSeconds))) { client.ConnectOverTCP(SUTIpAddress); DialectRevision selectedDialect; byte[] gssToken; Packet_Header responseHeader; NEGOTIATE_Response responsePayload; uint status = client.Negotiate( 0, 1, Packet_Header_Flags_Values.NONE, 0, new DialectRevision[] { DialectRevision.Smb311 }, SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED, Capabilities_Values.NONE, Guid.NewGuid(), out selectedDialect, out gssToken, out responseHeader, out responsePayload, preauthHashAlgs: new PreauthIntegrityHashID[] { PreauthIntegrityHashID.SHA_512 }, compressionAlgorithms: new CompressionAlgorithm[] { compressionAlgorithm } ); if (status == Smb2Status.STATUS_SUCCESS && client.CompressionInfo.CompressionIds.Length == 1 && client.CompressionInfo.CompressionIds[0] == compressionAlgorithm) { logWriter.AddLog(LogLevel.Information, $"Compression algorithm: {compressionAlgorithm} is supported by SUT."); return(true); } else { logWriter.AddLog(LogLevel.Information, $"Compression algorithm: {compressionAlgorithm} is not supported by SUT."); return(false); } } }); smb2Info.SupportedCompressionAlgorithms = result.ToArray(); // Check for chained compression support using (var client = new Smb2Client(new TimeSpan(0, 0, defaultTimeoutInSeconds))) { client.ConnectOverTCP(SUTIpAddress); DialectRevision selectedDialect; byte[] gssToken; Packet_Header responseHeader; NEGOTIATE_Response responsePayload; uint status = client.Negotiate( 0, 1, Packet_Header_Flags_Values.NONE, 0, new DialectRevision[] { DialectRevision.Smb311 }, SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED, Capabilities_Values.NONE, Guid.NewGuid(), out selectedDialect, out gssToken, out responseHeader, out responsePayload, preauthHashAlgs: new PreauthIntegrityHashID[] { PreauthIntegrityHashID.SHA_512 }, compressionAlgorithms: possibleCompressionAlogrithms.ToArray(), compressionFlags: SMB2_COMPRESSION_CAPABILITIES_Flags.SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED ); if (status == Smb2Status.STATUS_SUCCESS && client.CompressionInfo.SupportChainedCompression) { logWriter.AddLog(LogLevel.Information, "Chained compression is supported by SUT."); smb2Info.IsChainedCompressionSupported = true; } else { logWriter.AddLog(LogLevel.Information, "Chained compression is not supported by SUT."); smb2Info.IsChainedCompressionSupported = false; } } }