public void TestDigest()
        {
            WindowsAuthIdentity identity = new WindowsAuthIdentity();
            identity.Username = _testUser.usri1_name;
            identity.Domain = _computerName;
            identity.Password = _testUser.usri1_password;

            string package = "WDigest";
            WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
            WindowsSecurityContext initContext = WindowsSecurityContext.Get(package,
                "http://localhost", identity, 0, 0);
            IWindowsSecurityContext continueContext = initContext;
            IWindowsSecurityContext responseContext = null;
            string connectionId = Guid.NewGuid().ToString();
            do
            {
                responseContext = provider.AcceptSecurityToken(connectionId, continueContext.Token, package, 0, 0);
                if (responseContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(responseContext.Token));
                    Console.WriteLine("  Continue: {0}", responseContext.Continue);
                }
                continueContext = new WindowsSecurityContext(initContext, responseContext.Token, 0, 0);
            } while (responseContext.Continue);

            Assert.IsFalse(responseContext.Continue);
            Console.WriteLine(responseContext.Identity.Fqn);
        }
Example #2
0
        public void TestDigest()
        {
            WindowsAuthIdentity identity = new WindowsAuthIdentity();

            identity.Username = _testUser.usri1_name;
            identity.Domain   = _computerName;
            identity.Password = _testUser.usri1_password;

            string package = "WDigest";
            WindowsAuthProviderImpl provider    = new WindowsAuthProviderImpl();
            WindowsSecurityContext  initContext = WindowsSecurityContext.Get(package,
                                                                             "http://localhost", identity, 0, 0);
            IWindowsSecurityContext continueContext = initContext;
            IWindowsSecurityContext responseContext = null;
            string connectionId = Guid.NewGuid().ToString();

            do
            {
                responseContext = provider.AcceptSecurityToken(connectionId, continueContext.Token, package, 0, 0);
                if (responseContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(responseContext.Token));
                    Console.WriteLine("  Continue: {0}", responseContext.Continue);
                }
                continueContext = new WindowsSecurityContext(initContext, responseContext.Token, 0, 0);
            } while (responseContext.Continue);

            Assert.IsFalse(responseContext.Continue);
            Console.WriteLine(responseContext.Identity.Fqn);
        }
        public void TestNegotiate()
        {
            string package = "Negotiate";
            WindowsAuthProviderImpl provider    = new WindowsAuthProviderImpl();
            WindowsSecurityContext  initContext = WindowsSecurityContext.GetCurrent(package,
                                                                                    WindowsIdentity.GetCurrent().Name, Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            IWindowsSecurityContext continueContext = initContext;
            IWindowsSecurityContext responseContext = null;
            string connectionId = Guid.NewGuid().ToString();

            do
            {
                responseContext = provider.AcceptSecurityToken(connectionId, continueContext.Token, package,
                                                               Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
                if (responseContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(responseContext.Token));
                    Console.WriteLine("  Continue: {0}", responseContext.Continue);
                }
                continueContext = new WindowsSecurityContext(initContext, responseContext.Token,
                                                             Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            } while (responseContext.Continue);

            Assert.IsFalse(responseContext.Continue);
            Console.WriteLine(responseContext.Identity.Fqn);
        }
Example #4
0
        public void TestNegotiate()
        {
            string package = "Negotiate";
            WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
            WindowsSecurityContext clientContext = WindowsSecurityContext.GetCurrent(package,
                WindowsIdentity.GetCurrent().Name.ToLower(), Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            IWindowsSecurityContext serverContext = null;
            string connectionId = Guid.NewGuid().ToString();
            while(true)
            {
                serverContext = provider.AcceptSecurityToken(connectionId, clientContext.Token, package,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);

                if (serverContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(serverContext.Token));
                    Console.WriteLine("  Continue: {0}", serverContext.Continue);
                }

                if (!serverContext.Continue)
                {
                    break;
                }

                clientContext = new WindowsSecurityContext(clientContext, serverContext.Token,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            }

            Assert.IsFalse(serverContext.Continue);
            Console.WriteLine(serverContext.Identity.Fqn);
        }
Example #5
0
 /// <summary>
 /// Sql Server constructor to use the windows credentials of the specified user to connect.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Constructor to connect using windows authentication.
 /// </para>
 /// </remarks>
 public DatabaseSecurityContext(string userName, string domain, string password)
 {
     _useWindowsAuthentication   = true;
     _securityContext            = new WindowsSecurityContext();
     _securityContext.UserName   = userName;
     _securityContext.DomainName = domain;
     _securityContext.Password   = password;
 }
Example #6
0
 public void TestAcceptCurrentSecurityToken()
 {
     var package = "Negotiate";
     var result = WindowsSecurityContext.GetCurrent(package, WindowsIdentity.GetCurrent().Name, Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
     var provider = new WindowsAuthProviderImpl();
     var ctx = provider.AcceptSecurityToken(Guid.NewGuid().ToString(), result.Token, package, Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
     Assert.IsTrue(ctx.Continue);
 }
 public void TestGetCurrentInvalidPackage()
 {
     using (WindowsSecurityContext context = WindowsSecurityContext.GetCurrent(Guid.NewGuid().ToString(),
                                                                               WindowsIdentity.GetCurrent().Name, 0, 0))
     {
         Assert.AreNotEqual(context.Context, Secur32.SecHandle.Zero);
         Assert.IsNotNull(context.Token);
         Assert.IsNotEmpty(context.Token);
         Console.WriteLine(Convert.ToBase64String(context.Token));
     }
 }
 public void TestGetCurrentNTLM()
 {
     using (WindowsSecurityContext context = WindowsSecurityContext.GetCurrent("NTLM",
                                                                               WindowsIdentity.GetCurrent().Name, Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP))
     {
         Assert.AreNotEqual(context.Context, Secur32.SecHandle.Zero);
         Assert.IsNotNull(context.Token);
         Assert.IsNotEmpty(context.Token);
         Console.WriteLine(Convert.ToBase64String(context.Token));
     }
 }
Example #9
0
 public void TestGetCurrentInvalidPackage()
 {
     Assert.Throws(Is.TypeOf <Win32Exception>().And.Message.EqualTo("The requested security package does not exist"),
                   delegate {
         using (WindowsSecurityContext context = WindowsSecurityContext.GetCurrent(Guid.NewGuid().ToString(),
                                                                                   WindowsIdentity.GetCurrent().Name, 0, 0))
         {
             Assert.AreNotEqual(context.Context, Secur32.SecHandle.Zero);
             Assert.IsNotNull(context.Token);
             Assert.IsNotEmpty(context.Token);
             Console.WriteLine(Convert.ToBase64String(context.Token));
         }
     }
                   );
 }
 public void TestNegotiate()
 {
     string package = "Negotiate";
     using (WindowsCredentialsHandle credentialsHandle = new WindowsCredentialsHandle(
         string.Empty, Secur32.SECPKG_CRED_OUTBOUND, package))
     {
         using (WindowsSecurityContext context = new WindowsSecurityContext(
             WindowsIdentity.GetCurrent().Name,
             credentialsHandle,
             package,
             Secur32.ISC_REQ_CONNECTION,
             Secur32.SECURITY_NATIVE_DREP))
         {
             Assert.AreNotEqual(context.Context, Secur32.SecHandle.Zero);
             Assert.IsNotNull(context.Token);
             Assert.IsNotEmpty(context.Token);
             Console.WriteLine(Convert.ToBase64String(context.Token));
         }
     }
 }
        public void TestNegotiate()
        {
            string package = "Negotiate";

            using (WindowsCredentialsHandle credentialsHandle = new WindowsCredentialsHandle(
                       string.Empty, Secur32.SECPKG_CRED_OUTBOUND, package))
            {
                using (WindowsSecurityContext context = new WindowsSecurityContext(
                           WindowsIdentity.GetCurrent().Name,
                           credentialsHandle,
                           package,
                           Secur32.ISC_REQ_CONNECTION,
                           Secur32.SECURITY_NATIVE_DREP))
                {
                    Assert.AreNotEqual(context.Context, Secur32.SecHandle.Zero);
                    Assert.IsNotNull(context.Token);
                    Assert.IsNotEmpty(context.Token);
                    Console.WriteLine(Convert.ToBase64String(context.Token));
                }
            }
        }
Example #12
0
 /// <summary>
 /// Sql Server constructor to use the windows credentials of the currently logged on user to connect.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Constructor to connect to a Sql Server using windows authentication. The currently logged on user is used to logon.
 /// </para>
 /// </remarks>
 public DatabaseSecurityContext(WindowsSecurityContext securityContext)
 {
     _useWindowsAuthentication = true;
     _securityContext          = securityContext;
 }
        public void TestNegotiate()
        {
            string package = "Negotiate";
            WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
            WindowsSecurityContext clientContext = WindowsSecurityContext.GetCurrent(package,
                WindowsIdentity.GetCurrent().Name.ToLower(), Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            IWindowsSecurityContext serverContext = null;
            string connectionId = Guid.NewGuid().ToString();
            while(true)
            {
                serverContext = provider.AcceptSecurityToken(connectionId, clientContext.Token, package,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);

                if (serverContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(serverContext.Token));
                    Console.WriteLine("  Continue: {0}", serverContext.Continue);
                }

                if (!serverContext.Continue)
                {
                    break;
                }

                clientContext = new WindowsSecurityContext(clientContext, serverContext.Token,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            }

            Assert.IsFalse(serverContext.Continue);
            Console.WriteLine(serverContext.Identity.Fqn);
        }
        public void TestNegotiate()
        {
            string package = "Negotiate";
            WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
            WindowsSecurityContext initContext = WindowsSecurityContext.GetCurrent(package,
                WindowsIdentity.GetCurrent().Name, Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            IWindowsSecurityContext continueContext = initContext;
            IWindowsSecurityContext responseContext = null;
            string connectionId = Guid.NewGuid().ToString();
            do
            {
                responseContext = provider.AcceptSecurityToken(connectionId, continueContext.Token, package,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
                if (responseContext.Token != null)
                {
                    Console.WriteLine("  Token: {0}", Convert.ToBase64String(responseContext.Token));
                    Console.WriteLine("  Continue: {0}", responseContext.Continue);
                }
                continueContext = new WindowsSecurityContext(initContext, responseContext.Token,
                    Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP);
            } while (responseContext.Continue);

            Assert.IsFalse(responseContext.Continue);
            Console.WriteLine(responseContext.Identity.Fqn);
        }