public void NegotiateRequest(ModelDialectRevision maxSmbVersionClientSupported, SigningFlagType signingFlagType, SigningEnabledType signingEnabledType, SigningRequiredType signingRequiredType) { testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClient.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(maxSmbVersionClientSupported)); Packet_Header_Flags_Values headerFlags = (signingFlagType == SigningFlagType.SignedFlagSet) ? Packet_Header_Flags_Values.FLAGS_SIGNED : Packet_Header_Flags_Values.NONE; SigningEnabledType resSigningEnabledType = SigningEnabledType.SigningEnabledNotSet; SigningRequiredType resSigningRequiredType = SigningRequiredType.SigningRequiredNotSet; uint status = testClient.Negotiate( headerFlags, dialects, GetNegotiateSecurityMode(signingEnabledType, signingRequiredType), checker: (header, response) => { resSigningEnabledType = response.SecurityMode.HasFlag(NEGOTIATE_Response_SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED) ? SigningEnabledType.SigningEnabledSet : SigningEnabledType.SigningEnabledNotSet; resSigningRequiredType = response.SecurityMode.HasFlag(NEGOTIATE_Response_SecurityMode_Values.NEGOTIATE_SIGNING_REQUIRED) ? SigningRequiredType.SigningRequiredSet : SigningRequiredType.SigningRequiredNotSet; }); NegotiateResponse((ModelSmb2Status)status, resSigningEnabledType, resSigningRequiredType, signingConfig); }
public void SetupConnection(ModelDialectRevision maxSmbVersionClientSupported, ClientSupportsEncryptionType clientSupportsEncryptionType) { // Set checkEncrypt to false to not check if the response from the server is actually encrypted. testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site, checkEncrypt: false); testClient.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); testClient.Smb2Client.Disconnected += new Action(OnServerDisconnected); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(maxSmbVersionClientSupported)); //Set capabilities according to isClientSupportsEncryption Capabilities_Values commonCapability = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES; Capabilities_Values encryptionCapability = (clientSupportsEncryptionType == ClientSupportsEncryptionType.ClientSupportsEncryption) ? (commonCapability | Capabilities_Values.GLOBAL_CAP_ENCRYPTION) : commonCapability; uint status; DialectRevision selectedDialect; NEGOTIATE_Response?negotiateResponse = null; status = testClient.Negotiate( dialects, testConfig.IsSMB1NegotiateEnabled, capabilityValue: encryptionCapability, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); negotiateResponse = response; }, ifHandleRejectUnencryptedAccessSeparately: true, ifAddGLOBAL_CAP_ENCRYPTION: false, addDefaultEncryption: true ); selectedDialect = negotiateResponse.Value.DialectRevision; if ((selectedDialect == DialectRevision.Smb30 || selectedDialect == DialectRevision.Smb302) && clientSupportsEncryptionType == ClientSupportsEncryptionType.ClientSupportsEncryption) { /// TD section 3.3.5.4 /// SMB2_GLOBAL_CAP_ENCRYPTION if Connection.Dialect is "3.0" or "3.0.2", the server supports encryption, /// and SMB2_GLOBAL_CAP_ENCRYPTION is set in the Capabilities field of the request Site.Assert.IsTrue( negotiateResponse.Value.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_ENCRYPTION), "SMB2_GLOBAL_CAP_ENCRYPTION should be set in the negotiate response."); } else { Site.Assert.IsFalse( negotiateResponse.Value.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_ENCRYPTION), "SMB2_GLOBAL_CAP_ENCRYPTION should not be set in the negotiate response."); } }
/// <summary> /// Negotiate, SessionSetup and TreeConnect /// </summary> public void SetupConnection(ModelDialectRevision dialect, ModelCapabilities capabilities, SecurityMode_Values securityMode) { #region Connect to server testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClient.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); #endregion // It MUST be a GUID generated by the client, if the Dialects field contains a value other than 0x0202. Otherwise, the client MUST set this to 0. Guid clientGuid = (dialect == ModelDialectRevision.Smb2002) ? Guid.Empty : Guid.NewGuid(); #region negotiate testClient.Negotiate( Packet_Header_Flags_Values.NONE, Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)), securityMode, (Capabilities_Values)capabilities, clientGuid, (header, response) => { Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); negotiateResponse = response; }); #endregion #region session setup testClient.SessionSetup( testConfig.DefaultSecurityPackage, testConfig.SutComputerName, testConfig.AccountCredential, testConfig.UseServerGssToken, (SESSION_SETUP_Request_SecurityMode_Values)securityMode); #endregion #region treeconnect testClient.TreeConnect( Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare), out treeId); #endregion Connection_Dialect = ModelUtility.GetModelDialectRevision(negotiateResponse.DialectRevision); Connection_ClientCapabilities = (Capabilities_Values)capabilities; if (dialect >= ModelDialectRevision.Smb30) // GLOBAL_CAP_ENCRYPTION will be added in Functional client when dialect >= SMB30 { Connection_ClientCapabilities |= Capabilities_Values.GLOBAL_CAP_ENCRYPTION; } Connection_ClientSecurityMode = securityMode; Connection_ClientGuid = clientGuid; }
private void ConnectToShare(ModelDialectRevision dialect, Smb2FunctionalClient client, Guid guid, string share, out uint treeId) { #region Connect to server client.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); #endregion client.Negotiate( Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)), testConfig.IsSMB1NegotiateEnabled, clientGuid: guid); client.SessionSetup( testConfig.DefaultSecurityPackage, testConfig.SutComputerName, testConfig.AccountCredential, testConfig.UseServerGssToken); client.TreeConnect(Smb2Utility.GetUncPath(testConfig.SutComputerName, share), out treeId); }
public void SetupConnection(ModelDialectRevision dialect) { testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClient.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); testClient.Negotiate(Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)), testConfig.IsSMB1NegotiateEnabled); testClient.SessionSetup( testConfig.DefaultSecurityPackage, testConfig.SutComputerName, testConfig.AccountCredential, testConfig.UseServerGssToken); string share = testConfig.BasicFileShare; testClient.TreeConnect( Smb2Utility.GetUncPath(testConfig.SutComputerName, share), out treeId); }
public void OpenRequest( ModelDialectRevision clientMaxDialect, PersistentBitType persistentBit, CAShareType connectToCAShare, OplockLeaseType oplockLeaseType, DurableV1RequestContext durableV1RequestContext, DurableV2RequestContext durableV2RequestContext, DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext) { requestDialect = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL; if (persistentBit == PersistentBitType.PersistentBitSet) { clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES; } clientGuid = Guid.NewGuid(); requestedContext = oplockLeaseType; isCAShare = (connectToCAShare == CAShareType.CAShare); IPAddress targetIPAddress; string targetServer; #region Connect to Common Share or CA Share if (!isCAShare) { sharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare); fileName = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt"; targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; } else { sharePath = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName); fileName = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt"; targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; } testClientBeforeDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientBeforeDisconnection.CreditGoal = 20; testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); testClientBeforeDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, clientGuid: clientGuid, checker: (header, response) => { if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) && handleConfig.IsPersistentHandleSupported && persistentBit == PersistentBitType.PersistentBitSet) { Site.Assert.IsTrue( response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES), "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " + "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " + "Actual capabilities are {0}", response.Capabilities); } }); testClientBeforeDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection, delegate(Packet_Header responseHeader, TREE_CONNECT_Response response) { if (isCAShare) { if (!response.Capabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY)) { // skip test case for CA share is invalid Site.Assert.Inconclusive("This test case is applicable only when CA share is valid."); } } }); #endregion #region Construct Create Contexts Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext( durableV1RequestContext, durableV2RequestContext, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, false, false); #endregion #region Send Create request according to different context combination RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.NoOplockOrLease: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; case OplockLeaseType.BatchOplock: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.LeaseV1: case OplockLeaseType.LeaseV2: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; } FILEID fileId; Smb2CreateContextResponse[] serverCreateContexts; uint status = OpenCreate( testClientBeforeDisconnection, treeIdBeforeDisconnection, fileName, out fileId, out serverCreateContexts, requestedOplockLevel, smb2CreateContextRequest); #endregion DurableHandleResponseContext durableHandleResponse; LeaseResponseContext leaseResponse; CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse); OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig); testClientBeforeDisconnection.TreeDisconnect(treeIdAfterDisconnection, (header, response) => { }); testClientBeforeDisconnection.LogOff(); }
public void PrepareOpen( ModelDialectRevision clientMaxDialect, PersistentBitType persistentBit, CAShareType connectToCAShare, ModelHandleType modelHandleType, OplockLeaseType oplockLeaseType) { // Lease V2 cases only apply on the server implements SMB 3.x family. if (oplockLeaseType == OplockLeaseType.LeaseV2) { testConfig.CheckDialect(DialectRevision.Smb30); } // Lease V1 cases only apply on the server implements SMB 2.1 and 3.x family. if (oplockLeaseType == OplockLeaseType.LeaseV1) { testConfig.CheckDialect(DialectRevision.Smb21); } if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2) && !testConfig.IsLeasingSupported) { Site.Assert.Inconclusive("Test case is applicable in servers that support leasing."); } requestDialect = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL; if (persistentBit == PersistentBitType.PersistentBitSet) { clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES; } clientGuid = Guid.NewGuid(); requestedContext = oplockLeaseType; isCAShare = (connectToCAShare == CAShareType.CAShare); IPAddress targetIPAddress; string targetServer; #region Connect to Common Share or CA Share if (!isCAShare) { sharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare); fileName = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt"; targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; } else { sharePath = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName); fileName = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt"; targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; } testClientBeforeDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientBeforeDisconnection.CreditGoal = 20; testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); testClientBeforeDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, clientGuid: clientGuid, checker: (header, response) => { if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) && handleConfig.IsPersistentHandleSupported && persistentBit == PersistentBitType.PersistentBitSet) { Site.Assert.IsTrue( response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES), "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " + "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " + "Actual capabilities are {0}", response.Capabilities); } }); testClientBeforeDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection); #endregion #region Create operation according to the handle type and context Smb2CreateContextRequest[] prepareRequestContext = null; Smb2CreateContextResponse[] serverCreateContexts = null; RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.LeaseV1: { testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE); prepareRequestContext = GetPrepareOpenCreateContext(modelHandleType, oplockLeaseType); requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; case OplockLeaseType.LeaseV2: { testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2); prepareRequestContext = GetPrepareOpenCreateContext(modelHandleType, oplockLeaseType); requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; case OplockLeaseType.BatchOplock: { prepareRequestContext = GetPrepareOpenHandleContext(modelHandleType); requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.NoOplockOrLease: { prepareRequestContext = GetPrepareOpenHandleContext(modelHandleType); requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; } PrepareOpenCreate( testClientBeforeDisconnection, treeIdBeforeDisconnection, fileName, out fileIdBeforDisconnection, out serverCreateContexts, requestedOplockLevel, prepareRequestContext); #endregion }
/// <summary> /// Send ValidateNegotiateInfoRequest to Server, fill in the fields according to params. /// Verify the response. /// </summary> public void ValidateNegotiateInfoRequest(DialectType dialectType, CapabilitiesType capabilitiesType, SecurityModeType securityModeType, ClientGuidType clientGuidType) { Capabilities_Values capbilities = Connection_ClientCapabilities; if (capabilitiesType == CapabilitiesType.CapabilitiesDifferentFromNegotiate) { capbilities ^= Capabilities_Values.GLOBAL_CAP_DFS; } SecurityMode_Values securityMode = Connection_ClientSecurityMode; if (securityModeType == SecurityModeType.SecurityModeDifferentFromNegotiate) { securityMode ^= SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED; } Guid guid = clientGuidType == ClientGuidType.ClientGuidSameWithNegotiate ? Connection_ClientGuid : Guid.NewGuid(); DialectRevision[] dialects = null; if (DialectType.None != dialectType) { ModelDialectRevision dialect = Connection_Dialect; if (DialectType.DialectDifferentFromNegotiate == dialectType) { dialect = ModelDialectRevision.Smb30 == Connection_Dialect ? ModelDialectRevision.Smb21 : ModelDialectRevision.Smb30; } dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)); } else { dialects = new DialectRevision[] { 0 } }; VALIDATE_NEGOTIATE_INFO_Request validateNegotiateInfoRequest; validateNegotiateInfoRequest.Dialects = dialects; validateNegotiateInfoRequest.DialectCount = (ushort)dialects.Length; validateNegotiateInfoRequest.Capabilities = capbilities; validateNegotiateInfoRequest.SecurityMode = securityMode; validateNegotiateInfoRequest.Guid = guid; Site.Log.Add( LogEntryKind.Debug, "Dialects in ValidateNegotiateInfoRequest: {0}", Smb2Utility.GetArrayString(validateNegotiateInfoRequest.Dialects)); Site.Log.Add( LogEntryKind.Debug, "DialectCount in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.DialectCount); Site.Log.Add( LogEntryKind.Debug, "Capabilities in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Capabilities); Site.Log.Add( LogEntryKind.Debug, "SecurityMode in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.SecurityMode); Site.Log.Add( LogEntryKind.Debug, "Guid in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Guid); byte[] inputBuffer = TypeMarshal.ToBytes <VALIDATE_NEGOTIATE_INFO_Request>(validateNegotiateInfoRequest); byte[] outputBuffer; try { uint status = testClient.ValidateNegotiateInfo(treeId, inputBuffer, out outputBuffer, checker: CheckIoCtlResponse); if (Smb2Status.STATUS_SUCCESS == status) { VALIDATE_NEGOTIATE_INFO_Response validateNegotiateInfoResponse = TypeMarshal.ToStruct <VALIDATE_NEGOTIATE_INFO_Response>(outputBuffer); Site.Assert.AreEqual(negotiateResponse.DialectRevision, validateNegotiateInfoResponse.Dialect, "Dialect in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.DialectRevision.ToString(), validateNegotiateInfoResponse.Dialect.ToString()); Site.Assert.AreEqual((uint)negotiateResponse.Capabilities, (uint)validateNegotiateInfoResponse.Capabilities, "Capabilities in Negotiate response({0}) and ValidateNegotiateResponse({1}) should be the same", negotiateResponse.Capabilities.ToString(), validateNegotiateInfoResponse.Capabilities.ToString()); Site.Assert.AreEqual((ushort)negotiateResponse.SecurityMode, (ushort)validateNegotiateInfoResponse.SecurityMode, "SecurityMode in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.SecurityMode.ToString(), validateNegotiateInfoResponse.SecurityMode.ToString()); Site.Assert.AreEqual(negotiateResponse.ServerGuid, validateNegotiateInfoResponse.Guid, "ClientGuid in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.ServerGuid.ToString(), validateNegotiateInfoResponse.Guid.ToString()); } testClient.TreeDisconnect(treeId); testClient.LogOff(); testClient.Disconnect(); this.ValidateNegotiateInfoResponse((ModelSmb2Status)status, validateNegotiateInfoConfig); return; } catch { } Site.Assert.IsTrue(testClient.Smb2Client.IsServerDisconnected, "ValidateNegotiationInfo failure should be caused by transport connection termination"); TerminateConnection(); }
private void InitializeMainChannel( ModelDialectRevision maxSmbVersionClientSupported, Guid clientGuid, ReplayModelShareType shareType, out uint treeId, bool isReconnect = false, bool isClientSupportPersistent = true) { Site.Assume.IsNull(smb2ClientMainChannel, "Expect smb2ClientMainChannel is NULL."); smb2ClientMainChannel = new Smb2FunctionalClient(testConfig.Timeout, testConfig, Site); smb2ClientMainChannel.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(OnLeaseBreakNotificationReceived); smb2ClientMainChannel.Smb2Client.OplockBreakNotificationReceived += new Action <Packet_Header, OPLOCK_BREAK_Notification_Packet>(OnOplockBreakNotificationReceived); serverIpMainChannel = (shareType == ReplayModelShareType.CAShare ? testConfig.CAShareServerIP : testConfig.SutIPAddress); serverNameMainChannel = (shareType == ReplayModelShareType.CAShare) ? testConfig.CAShareServerName : testConfig.SutComputerName; smb2ClientMainChannel.ConnectToServer(testConfig.UnderlyingTransport, serverNameMainChannel, serverIpMainChannel); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(maxSmbVersionClientSupported)); uint status; #region Negotiate Capabilities_Values capability = isClientSupportPersistent ? Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES | Capabilities_Values.GLOBAL_CAP_ENCRYPTION : Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_ENCRYPTION; NEGOTIATE_Response?negotiateResponse = null; clientCapabilitiesMainChannel = ModelUtility.IsSmb3xFamily(maxSmbVersionClientSupported)? capability : Capabilities_Values.NONE; status = smb2ClientMainChannel.Negotiate( dialects, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilitiesMainChannel, clientGuid: maxSmbVersionClientSupported == ModelDialectRevision.Smb2002 ? Guid.Empty : clientGuid, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); negotiateResponse = response; }); dialectMainChannel = negotiateResponse.Value.DialectRevision; #endregion #region SESSION_SETUP principleNameMainChannel = (shareType == ReplayModelShareType.CAShare ? testConfig.CAShareServerName : testConfig.SutComputerName); if (isReconnect) { status = smb2ClientMainChannel.ReconnectSessionSetup( sessionIdMainChannel, testConfig.DefaultSecurityPackage, principleNameMainChannel, testConfig.AccountCredential, testConfig.UseServerGssToken); sessionIdMainChannel = smb2ClientMainChannel.SessionId; sessionKeyMainChannel = smb2ClientMainChannel.SessionKey; } else { status = smb2ClientMainChannel.SessionSetup( testConfig.DefaultSecurityPackage, principleNameMainChannel, testConfig.AccountCredential, testConfig.UseServerGssToken); sessionIdMainChannel = smb2ClientMainChannel.SessionId; sessionKeyMainChannel = smb2ClientMainChannel.SessionKey; } Site.Log.Add( LogEntryKind.Debug, "Global encryption disabled"); #endregion #region TREE_CONNECT to share sharePathMainChannel = (shareType == ReplayModelShareType.CAShare ? Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName) : Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare)); status = smb2ClientMainChannel.TreeConnect( sharePathMainChannel, out treeId); Site.Log.Add( LogEntryKind.Debug, "Establish main channel to connect share {0}", sharePathMainChannel); smb2ClientMainChannel.SetTreeEncryption(treeId, false); #endregion }
public void SetupConnection(ModelDialectRevision clientMaxDialect) { testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClient.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); testClient.RequestSent += new Action <Packet_Header>(PrintSequenceWindow); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); uint status; NEGOTIATE_Response?negotiateResponse = null; status = testClient.Negotiate( dialects, testConfig.IsSMB1NegotiateEnabled, capabilityValue: Capabilities_Values.GLOBAL_CAP_LARGE_MTU, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); // The server MUST grant the client at least 1 credit when responding to SMB2 NEGOTIATE. Site.Assert.IsTrue( header.CreditRequestResponse >= 1, "The server MUST grant the client at least 1 credit when responding to SMB2 NEGOTIATE"); negotiateResponse = response; }); Site.Log.Add( LogEntryKind.Debug, "The maximum size, in bytes, of Length in READ/WRITE that server will accept on the connection is {0}", testClient.MaxBufferSize); Site.Assert.AreEqual( ModelUtility.GetDialectRevision(clientMaxDialect), negotiateResponse.Value.DialectRevision, "DialectRevision {0} is expected", ModelUtility.GetDialectRevision(clientMaxDialect)); negotiateDialect = negotiateResponse.Value.DialectRevision; if ((negotiateDialect == DialectRevision.Smb21 || ModelUtility.IsSmb3xFamily(negotiateDialect)) // In case server does not support multicredit even implement Smb21 or Smb30 && testConfig.IsMultiCreditSupported) { isMultiCreditSupportedOnConnection = true; } else { isMultiCreditSupportedOnConnection = false; } status = testClient.SessionSetup( testConfig.DefaultSecurityPackage, testConfig.SutComputerName, testConfig.AccountCredential, testConfig.UseServerGssToken); status = testClient.TreeConnect( uncSharePath, out treeId); Smb2CreateContextResponse[] serverCreateContexts; fileName = GetTestFileName(uncSharePath); status = testClient.Create( treeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileId, out serverCreateContexts); }
private void CreateFile(string uncShare, string fileName, int lengthInByte) { Site.Log.Add( LogEntryKind.Debug, "Create file {0} in share {1}", fileName, uncShare); Smb2FunctionalClient client = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); client.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress); client.CreditGoal = 32; client.Negotiate( new DialectRevision[] { ModelUtility.GetDialectRevision(config.MaxSmbVersionSupported) }, testConfig.IsSMB1NegotiateEnabled, capabilityValue: Capabilities_Values.GLOBAL_CAP_LARGE_MTU); client.SessionSetup( testConfig.DefaultSecurityPackage, testConfig.SutComputerName, testConfig.AccountCredential, testConfig.UseServerGssToken); uint tId; client.TreeConnect( uncShare, out tId); Smb2CreateContextResponse[] serverCreateContexts; FILEID fId; client.Create( tId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fId, out serverCreateContexts); string content; if (isMultiCreditSupportedOnConnection) { content = Smb2Utility.CreateRandomStringInByte(lengthInByte); client.Write(tId, fId, content); } else { // Write several times if server does not support multi credit int writeTimes = lengthInByte / (64 * 1024); int rest = lengthInByte % (64 * 1024); ulong offset = 0; for (int time = 0; time < writeTimes; time++) { content = Smb2Utility.CreateRandomString(64); client.Write(tId, fId, content, offset); offset += 64 * 1024; } if (rest != 0) { content = Smb2Utility.CreateRandomStringInByte(rest); client.Write(tId, fId, content, offset); } } client.Close(tId, fId); client.TreeDisconnect(tId); client.LogOff(); client.Disconnect(); Site.Log.Add( LogEntryKind.Debug, "Create file {0} in share {1}", fileName, uncShare); }
public void SetupConnection(ModelDialectRevision maxSmbVersionClientSupported, ModelShareFlag shareFlag, ModelShareType shareType) { IPAddress ip; if (shareType == ModelShareType.STYPE_CLUSTER_SOFS) { server = testConfig.ScaleOutFileServerName; ip = Dns.GetHostEntry(server).AddressList[0]; if (shareFlag == ModelShareFlag.SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK) { uncSharePath = Smb2Utility.GetUncPath(testConfig.ScaleOutFileServerName, testConfig.ShareWithForceLevel2AndSOFS); } else { uncSharePath = Smb2Utility.GetUncPath(testConfig.ScaleOutFileServerName, testConfig.ShareWithoutForceLevel2WithSOFS); } } else { server = testConfig.SutComputerName; ip = testConfig.SutIPAddress; if (shareFlag == ModelShareFlag.SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK) { uncSharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.ShareWithForceLevel2WithoutSOFS); } else { uncSharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.ShareWithoutForceLevel2OrSOFS); } } testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClient.Smb2Client.OplockBreakNotificationReceived += new Action <Packet_Header, OPLOCK_BREAK_Notification_Packet>(OnOplockBreakNotificationReceived); testClient.ConnectToServer(testConfig.UnderlyingTransport, server, ip, testConfig.ClientNic1IPAddress); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(maxSmbVersionClientSupported)); NEGOTIATE_Response?negotiateResponse = null; testClient.Negotiate( dialects, testConfig.IsSMB1NegotiateEnabled, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); negotiateResponse = response; }); negotiatedDialect = negotiateResponse.Value.DialectRevision; testClient.SessionSetup( testConfig.DefaultSecurityPackage, server, testConfig.AccountCredential, testConfig.UseServerGssToken); testClient.TreeConnect( uncSharePath, out treeId, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); Site.Assert.AreEqual( shareFlag == ModelShareFlag.SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK, response.ShareFlags.HasFlag(ShareFlags_Values.SHAREFLAG_FORCE_LEVELII_OPLOCK), "SHAREFLAG_FORCE_LEVELII_OPLOCK is{0}expected to be set", shareFlag == ModelShareFlag.SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK ? " " : " not "); if (ModelUtility.IsSmb3xFamily(negotiateResponse.Value.DialectRevision)) { Site.Assert.AreEqual( shareType == ModelShareType.STYPE_CLUSTER_SOFS, response.Capabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_SCALEOUT), "SHARE_CAP_SCALEOUT is{0}expected to be set", shareType == ModelShareType.STYPE_CLUSTER_SOFS ? " " : " not "); } }); }
public void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle) { prepareOpenClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); clientGuid = Guid.NewGuid(); DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); // Connect to Share ConnectToShare( Site, testConfig, prepareOpenClient, dialects, clientGuid, testConfig.AccountCredential, out dialect, out treeId); Site.Assert.AreEqual( ModelUtility.GetDialectRevision(clientMaxDialect), dialect, "DialectRevision {0} is expected", ModelUtility.GetDialectRevision(clientMaxDialect)); // SMB2 Create RequestedOplockLevel_Values opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; Smb2CreateContextRequest[] createContextRequests = new Smb2CreateContextRequest[0]; createGuid = Guid.Empty; if (durableHandle == DurableHandle.DurableHandle) {// durable handle request context with batch opLock opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; createGuid = Guid.NewGuid(); testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST); createContextRequests = new Smb2CreateContextRequest[] { new Smb2CreateDurableHandleRequest { DurableRequest = createGuid } }; } // create Smb2CreateContextResponse[] createContextResponse; prepareOpenClient.Create( treeId, GetTestFileName(Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare)), CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileId, out createContextResponse, requestedOplockLevel_Values: opLockLevel, createContexts: createContextRequests, checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); if (durableHandle == DurableHandle.DurableHandle) { Site.Assert.AreEqual <OplockLevel_Values>( OplockLevel_Values.OPLOCK_LEVEL_BATCH, response.OplockLevel, "OplockLevel should be OPLOCK_LEVEL_BATCH if Durable Handle"); } } ); if (durableHandle == DurableHandle.DurableHandle) { // check whether response contain Durable Context Site.Assert.IsTrue( ContainDurableHandleResponse(createContextResponse), "Durable Handle Response should be in the Create response."); } }
public void SetupConnection(ModelConnectionId connectionId, ModelDialectRevision clientMaxDialect) { connectionList.Add(connectionId, new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site)); if (connectionId == ModelConnectionId.MainConnection) { connectionList[connectionId].ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress, testConfig.ClientNic1IPAddress); } else { connectionList[connectionId].ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress, testConfig.ClientNic2IPAddress); } DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); uint status; NEGOTIATE_Response?negotiateResponse = null; status = connectionList[connectionId].Negotiate( dialects, testConfig.IsSMB1NegotiateEnabled, capabilityValue: Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL, clientGuid: GetClientGuid(connectionId, dialects), checker: (header, response) => { Site.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command); negotiateResponse = response; }); DialectRevision expectedDialect; if (clientMaxDialect < sessionMgmtConfig.MaxSmbVersionSupported) { expectedDialect = ModelUtility.GetDialectRevision(clientMaxDialect); } else { expectedDialect = ModelUtility.GetDialectRevision(sessionMgmtConfig.MaxSmbVersionSupported); } Site.Assert.AreEqual( expectedDialect, negotiateResponse.Value.DialectRevision, "DialectRevision {0} is expected", expectedDialect); if (ModelUtility.IsSmb3xFamily(negotiateResponse.Value.DialectRevision) && sessionMgmtConfig.IsMultiChannelCapable) { // SMB2_GLOBAL_CAP_MULTI_CHANNEL if Connection.Dialect belongs to the SMB 3.x dialect family, // IsMultiChannelCapable is TRUE, and SMB2_GLOBAL_CAP_MULTI_CHANNEL is set in the Capabilities field of the request. Site.Assert.AreEqual( Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL, Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL & (Capabilities_Values)negotiateResponse.Value.Capabilities, ""); } else { Site.Assert.AreNotEqual( Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL, Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL & (Capabilities_Values)negotiateResponse.Value.Capabilities, ""); } }