Пример #1
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="credential">the client credential contains the user information</param>
 /// <param name="contextAttribute">the client Context Attribute</param>
 /// <exception cref="ArgumentNullException">the previousContext must be null</exception>
 public NlmpClientSecurityContext(NlmpClientCredential credential, ClientSecurityContextAttribute contextAttribute)
     : this(credential)
 {
     this.contextAttribute        = contextAttribute;
     this.Context.Integrity       = contextAttribute.HasFlag(ClientSecurityContextAttribute.Integrity);
     this.Context.ReplayDetect    = contextAttribute.HasFlag(ClientSecurityContextAttribute.ReplayDetect);
     this.Context.SequenceDetect  = contextAttribute.HasFlag(ClientSecurityContextAttribute.SequenceDetect);
     this.Context.Confidentiality = contextAttribute.HasFlag(ClientSecurityContextAttribute.Confidentiality);
     this.Context.Datagram        = contextAttribute.HasFlag(ClientSecurityContextAttribute.Datagram);
     this.Context.Identify        = contextAttribute.HasFlag(ClientSecurityContextAttribute.Identify);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="flags">Negotiation flags.</param>
 /// <param name="clientCredential">Client account credential.</param>
 /// <param name="isDomainJoined">Joined in a domain or not</param>
 /// <param name="netbiosDomainName">Netbios domain name.</param>
 /// <param name="netbiosMachineName">Netbios machine name.</param>
 public NlmpServerSecurityConfig(
     NegotiateTypes flags,
     NlmpClientCredential clientCredential,
     bool isDomainJoined,
     string netbiosDomainName,
     string netbiosMachineName)
     : base(SecurityPackageType.Ntlm)
 {
     this.negotiateflags     = flags;
     this.clientCredential   = clientCredential;
     this.isDomainJoined     = isDomainJoined;
     this.netbiosDomainName  = netbiosDomainName;
     this.netbiosMachineName = netbiosMachineName;
     this.targetName         = clientCredential.TargetName;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="flags">Negotiation flags.</param>
 /// <param name="clientCredential">Client account credential.</param>
 /// <param name="isDomainJoined">Joined in a domain or not</param>
 /// <param name="netbiosDomainName">Netbios domain name.</param>
 /// <param name="netbiosMachineName">Netbios machine name.</param>
 public NlmpServerSecurityConfig(
     NegotiateTypes flags,
     NlmpClientCredential clientCredential,
     bool isDomainJoined,
     string netbiosDomainName,
     string netbiosMachineName)
     : base(SecurityPackageType.Ntlm)
 {
     this.negotiateflags = flags;
     this.clientCredential = clientCredential;
     this.isDomainJoined = isDomainJoined;
     this.netbiosDomainName = netbiosDomainName;
     this.netbiosMachineName = netbiosMachineName;
     this.targetName = clientCredential.TargetName;
 }
Пример #4
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="credential">the client credential contains the user information</param>
        /// <exception cref="ArgumentNullException">the previousContext must be null</exception>
        public NlmpClientSecurityContext(NlmpClientCredential credential)
        {
            this.credential = credential;

            // initialize the nlmp client information.
            this.client = new NlmpClient(new NlmpClientConfig(NlmpVersion.v2));
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_NTLM;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_REQUEST_TARGET;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_VERSION;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_128;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_56;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_UNICODE;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLM_NEGOTIATE_OEM;
        }
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="credential">the client credential contains the user information</param>
        /// <exception cref="ArgumentNullException">the previousContext must be null</exception>
        public NlmpClientSecurityContext(NlmpClientCredential credential)
        {
            this.credential = credential;

            // initialize the nlmp client information.
            this.client = new NlmpClient(new NlmpClientConfig(NlmpVersion.v2));
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_NTLM;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_REQUEST_TARGET;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_VERSION;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_128;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_56;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_UNICODE;
            // turn on seal and sign
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_SEAL;
            this.client.Context.ClientConfigFlags |= NegotiateTypes.NTLMSSP_NEGOTIATE_SIGN;
        }
Пример #6
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="flags">the negotiate flags indicates the capabilities of server or client</param>
        /// <param name="clientCredential">
        /// the credential of client. server sdk can not retrieve password from AD/Account Database;<para/>
        /// instead, server sdk get the user credential from this parameter.
        /// </param>
        /// <param name="isDomainJoined">whether the server joined to domain</param>
        /// <param name="netbiosDomainName">the netbios domain name of server</param>
        /// <param name="netbiosMachineName">the netbios machine name of server</param>
        public NlmpServerSecurityContext(
            NegotiateTypes flags,
            NlmpClientCredential clientCredential,
            bool isDomainJoined,
            string netbiosDomainName,
            string netbiosMachineName)
        {
            this.version    = new NlmpVersion();
            this.nlmpServer = new NlmpServer();

            this.nlmpServer.Context.NegFlg           = flags;
            this.nlmpServer.Context.ClientCredential = clientCredential;
            this.nlmpServer.Context.IsDomainJoined   = isDomainJoined;
            this.nlmpServer.Context.NbDomainName     = netbiosDomainName;
            this.nlmpServer.Context.NbMachineName    = netbiosMachineName;

            this.needContinueProcessing = true;
        }
Пример #7
0
        /// <summary>
        /// Initialize the context from a token.
        /// </summary>
        /// <param name="serverToken">the token from server</param>
        public override void Initialize(byte[] serverToken)
        {
            if (serverToken == null)
            {
                this.clientSequenceNumber = 0;
                this.serverSequenceNumber = 0;

                string domainName      = string.Empty;
                string workstationName = string.Empty;

                if (!NlmpUtility.IsVersionRequired(this.Context.ClientConfigFlags))
                {
                    if (NlmpUtility.IsDomainNameSupplied(this.Context.ClientConfigFlags))
                    {
                        domainName = this.Credential.DomainName;
                    }

                    if (NlmpUtility.IsWorkstationSupplied(this.Context.ClientConfigFlags))
                    {
                        workstationName = Environment.MachineName;
                    }
                }

                this.currentActiveCredential = new NlmpClientCredential(
                    workstationName, domainName,
                    this.Credential.AccountName, this.Credential.Password);

                this.token = GetSecurityToken(workstationName);

                this.needContinueProcessing = true;
            }
            else
            {
                this.currentActiveCredential = Credential;

                this.token = GetSecurityToken(serverToken);

                this.needContinueProcessing = false;
            }
        }
        /// <summary>
        /// Initialize the context from a token.
        /// </summary>
        /// <param name="serverToken">the token from server</param>
        public override void Initialize(byte[] serverToken)
        {
            if (serverToken == null)
            {
                this.clientSequenceNumber = 0;
                this.serverSequenceNumber = 0;

                string domainName = string.Empty;
                string workstationName = string.Empty;

                if (!NlmpUtility.IsVersionRequired(this.Context.ClientConfigFlags))
                {
                    if (NlmpUtility.IsDomainNameSupplied(this.Context.ClientConfigFlags))
                    {
                        domainName = this.Credential.DomainName;
                    }

                    if (NlmpUtility.IsWorkstationSupplied(this.Context.ClientConfigFlags))
                    {
                        workstationName = this.Credential.TargetName;
                    }
                }

                this.currentActiveCredential = new NlmpClientCredential(
                    workstationName, domainName,
                    this.Credential.AccountName, this.Credential.Password);

                this.token = GetSecurityToken();

                this.needContinueProcessing = true;
            }
            else
            {
                this.currentActiveCredential = Credential;

                this.token = GetSecurityToken(serverToken);

                this.needContinueProcessing = false;
            }
        }
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="flags">the negotiate flags indicates the capabilities of server or client</param>
        /// <param name="clientCredential">
        /// the credential of client. server sdk can not retrieve password from AD/Account Database;<para/>
        /// instead, server sdk get the user credential from this parameter.
        /// </param>
        /// <param name="isDomainJoined">whether the server joined to domain</param>
        /// <param name="netbiosDomainName">the netbios domain name of server</param>
        /// <param name="netbiosMachineName">the netbios machine name of server</param>
        public NlmpServerSecurityContext(
            NegotiateTypes flags,
            NlmpClientCredential clientCredential,
            bool isDomainJoined,
            string netbiosDomainName,
            string netbiosMachineName)
        {
            this.version = new NlmpVersion();
            this.nlmpServer = new NlmpServer();

            this.nlmpServer.Context.NegFlg = flags;
            this.nlmpServer.Context.ClientCredential = clientCredential;
            this.nlmpServer.Context.IsDomainJoined = isDomainJoined;
            this.nlmpServer.Context.NbDomainName = netbiosDomainName;
            this.nlmpServer.Context.NbMachineName = netbiosMachineName;

            this.needContinueProcessing = true;
        }
        static void Main(string[] args)
        {
            SwnClient client = new SwnClient();
            string serverName = "GeneralFS";
            string serverAddr = "192.168.1.200";
            string resourceName = "GeneralFS";
            string clientName = Guid.NewGuid().ToString();

            int retVar = 0;
            TimeSpan timeOut = new TimeSpan(0, 0, 10);
            AccountCredential accountCredential = new AccountCredential("contoso.com", "Administrator", "Password01!");
            NlmpClientCredential nlmpCredential = new NlmpClientCredential(serverName, "contoso.com", "Administrator", "Password01!");
            ClientSecurityContext securityContext = new NlmpClientSecurityContext(nlmpCredential);

            //Bind to server
            client.SwnBind(serverName, accountCredential, securityContext,
                RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY, timeOut);

            //Get interface list
            WITNESS_INTERFACE_LIST interfaceList;
            try
            {
                retVar = client.WitnessGetInterfaceList(out interfaceList);
                Console.WriteLine("Call WitnessGetInterfaceList: " + retVar);
            }
            catch (TimeoutException)
            {
                client.SwnUnbind(timeOut);
                return;
            }

            string swnServerName = "";

            foreach (var info in interfaceList.InterfaceInfo)
            {
                if ((info.Flags & (uint)SwnNodeFlagsValue.INTERFACE_WITNESS) != 0)
                {
                    if ((info.Flags & (uint)SwnNodeFlagsValue.IPv4) != 0)
                    {
                        swnServerName = (new IPAddress(info.IPV4)).ToString();
                    }
                    else if ((info.Flags & (uint)SwnNodeFlagsValue.IPv6) != 0)
                    {
                        byte[] ipv6 = new byte[16];
                        Buffer.BlockCopy(info.IPV6, 0, ipv6, 0, 16);
                        swnServerName = (new IPAddress(ipv6)).ToString();
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                    break;
                }
            }

            SwnClient client2 = new SwnClient();
            client2.SwnBind(swnServerName, accountCredential, securityContext,
                RpceAuthenticationLevel.RPC_C_AUTHN_LEVEL_PKT_INTEGRITY, timeOut);

            //Registration
            IntPtr pContext;
            retVar = client2.WitnessRegister(SwnVersion.SWN_VERSION_1, resourceName, serverAddr, clientName, out pContext);
            Console.WriteLine("Call WitnessRegister: " + retVar);

            uint callId = 0;
            try
            {
                RESP_ASYNC_NOTIFY respNotify;
                callId = client2.WitnessAsyncNotify(pContext);
                Console.WriteLine("Call WitnessAsyncNotify: " + callId);

                retVar = client2.WitnessAsyncNotifyExpect(callId, out respNotify);
                Console.WriteLine("Call WitnessAsyncNotify: " + retVar);
                Console.WriteLine("NumberOfMessages: " + respNotify.NumberOfMessages);
                Console.WriteLine("Length: " + respNotify.Length);
                PrintNotification(respNotify);

                callId = client2.WitnessAsyncNotify(pContext);
                Console.WriteLine("Call WitnessAsyncNotify: " + callId);

                retVar = client2.WitnessAsyncNotifyExpect(callId, out respNotify);
                Console.WriteLine("Call WitnessAsyncNotify: " + retVar);
                Console.WriteLine("NumberOfMessages: " + respNotify.NumberOfMessages);
                Console.WriteLine("Length: " + respNotify.Length);
                PrintNotification(respNotify);
            }
            catch (TimeoutException)
            {
                Console.WriteLine("Throw a TimeoutException.");
            }

            //UnRegistration
            retVar = client2.WitnessUnRegister(pContext);
            Console.WriteLine("Call WitnessUnRegister: " + retVar);

            client2.SwnUnbind(timeOut);
            client.SwnUnbind(timeOut);

            Console.ReadKey();
        }