Ejemplo n.º 1
0
        private void SMB2ChainedCompression_Variant(CompressionTestVariant variant, bool needPatternV1 = false, bool needCompressionAlgorithm = false, bool needEncryption = false)
        {
            CompressionAlgorithm?compressionAlgorithmToCheck = null;

            if (needPatternV1)
            {
                compressionAlgorithmToCheck = CompressionAlgorithm.Pattern_V1;
            }

            CheckCompressionAndEncryptionApplicability(compressionAlgorithmToCheck, needEncryption, true, needCompressionAlgorithm);

            var compressionAlgorithms = new List <CompressionAlgorithm>();

            if (needPatternV1)
            {
                compressionAlgorithms.Add(CompressionAlgorithm.Pattern_V1);
            }

            if (needCompressionAlgorithm)
            {
                compressionAlgorithms.AddRange(Smb2Utility.GetSupportedCompressionAlgorithms(TestConfig.SupportedCompressionAlgorithmList.ToArray()));
            }

            SMB2CompressionTest(compressionAlgorithms.ToArray(), variant, needEncryption, enableChainedCompression: true);
        }
Ejemplo n.º 2
0
        private void CheckCompressionAndEncryptionApplicability(CompressionAlgorithm?compressionAlgorithm = null, bool needEncryption = false, bool needChainedCompression = false, bool needCompressionAlgorithms = false)
        {
            // Check platform
            if (TestConfig.IsWindowsPlatform)
            {
                BaseTestSite.Assume.IsFalse(TestConfig.Platform < Platform.WindowsServerV1903, "Windows 10 v1809 operating system and prior, Windows Server v1809 operating system and prior, and Windows Server 2019 and prior do not support compression.");
            }

            // Check dialect
            BaseTestSite.Assume.IsTrue(TestConfig.MaxSmbVersionSupported >= DialectRevision.Smb311, "The SMB 3.1.1 dialect introduces supporting the compression of messages between client and server.");

            // Check SUT supported compression algorithms
            TestConfig.CheckCompressionAlgorithm(compressionAlgorithm);

            // Check whether SUT supports encryption
            if (needEncryption)
            {
                TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_ENCRYPTION);
            }

            if (needChainedCompression)
            {
                BaseTestSite.Assume.IsTrue(TestConfig.IsChainedCompressionSupported, "In order to run this test case, SUT MUST support chained compression feature.");
            }

            if (needCompressionAlgorithms)
            {
                var supportedCompressionAlgorithms = Smb2Utility.GetSupportedCompressionAlgorithms(TestConfig.SupportedCompressionAlgorithmList.ToArray());

                BaseTestSite.Assume.IsTrue(supportedCompressionAlgorithms.Length > 0, "In order to run this test case, SUT MUST support at least one compression algorithm.");
            }
        }
Ejemplo n.º 3
0
        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.");
            }
        }
Ejemplo n.º 4
0
        private void SMB2CompressionTest(CompressionAlgorithm[] compressionAlgorithms, CompressionTestVariant variant, bool enableEncryption = false, bool enableChainedCompression = false)
        {
            uint   treeId;
            FILEID fileId;

            if (!enableChainedCompression)
            {
                compressionAlgorithms = Smb2Utility.GetSupportedCompressionAlgorithms(compressionAlgorithms);
            }

            CreateTestFile(compressionAlgorithms, enableEncryption, out treeId, out fileId, enableChainedCompression);

            var instances = CompressionTestRunner.Generate(compressionAlgorithms, variant);

            foreach (var instance in instances)
            {
                instance.Run(client, treeId, fileId);
            }

            client.Close(treeId, fileId);
            client.TreeDisconnect(treeId);
            client.LogOff();
        }
Ejemplo n.º 5
0
        private static CompressionAlgorithm GetPreferredCompressionAlgorithm(Smb2CompressionInfo compressionInfo)
        {
            if (compressionInfo.PreferredCompressionAlgorithm == CompressionAlgorithm.NONE)
            {
                var commonSupportedCompressionAlgorithms = Smb2Utility.GetSupportedCompressionAlgorithms(compressionInfo.CompressionIds);

                if (commonSupportedCompressionAlgorithms.Length > 0)
                {
                    return(commonSupportedCompressionAlgorithms.First());
                }
                else
                {
                    return(CompressionAlgorithm.NONE);
                }
            }
            else
            {
                if (!compressionInfo.CompressionIds.Contains(compressionInfo.PreferredCompressionAlgorithm))
                {
                    throw new InvalidOperationException("Specified preferred compression algorithm is not supported by SUT!");
                }
                return(compressionInfo.PreferredCompressionAlgorithm);
            }
        }
Ejemplo n.º 6
0
        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;
                }
            }
        }