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 TestGetDomains() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); if (_joinStatus != Netapi32.NetJoinStatus.NetSetupDomainName) Assert.Ignore(string.Format("{0} is not joined to a domain.", _computerName)); IWindowsDomain[] domains = windowsAuthProviderImpl.GetDomains(); Assert.IsNotNull(domains); Assert.IsTrue(domains.Length > 0); foreach (IWindowsDomain domain in domains) { Console.WriteLine("{0} ({1}, {2})", domain.Fqn, domain.TrustDirectionString, domain.TrustTypeString); try { Console.WriteLine(" Canonical name: {0}", domain.CanonicalName); } catch (Exception ex) { Console.WriteLine(" Error obtaining domain canonical name: {0}", ex.Message); } try { Console.WriteLine("Groups: {0}", domain.Groups.Length); } catch (Exception ex) { Console.WriteLine(" Error enumerating groups: {0}", ex.Message); } } }
public void TestAcceptExistingSecurityToken() { WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl(); byte[] clientToken = System.Convert.FromBase64String("YIIFWgYGKwYBBQUCoIIFTjCCBUqgJDAiBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICCqKCBSAEggUcYIIFGAYJKoZIhvcSAQ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HllEQj7XcCrMEXAt18BhvlM4TdpMr3totyb4wVoSIiTHnyVgt7tG3ub/1oJ2sp+IrdvsGx//y0ANyHuEfk0kjG/iBdcKvs75yEHCpe40Ze91AtjAWYT8rbXvrIwPS24NX+ukoTOhvZY8S6F/18Yp2fv0/MTL32FuoPQ8tqJu8NMWFGACu+d3jAcZerh6k18pCCW6iw0ji/Ijtc3ok9lyZrJNmwDFHRbNOOPdHE5pF5vOHezJ+PUStzkHovtydLc7IGPswYfwrM8T+8Fx+T7zUkoLAoJIN2c4IMKKx6/XYvY3hW7sV1LaietDXJJMPeBvxur+CDykHyDeFQ1JESJv+KVdL7c7uxEgkD4GYloecy3HqMfclUDrevVrq2L6USSeCeYWJDs6rEe1mKkgbswgbigAwIBF6KBsASBrT/Bj9kDPy4erA5ZeCnJmMLY8l3d1WuvZ2E602uS1eQcIPHVzZNJVjq0HaY7BGtL4WcHCRhLUittEX10BHV5NhOApyY7NPQXxekjvoei6Dy5eM47neqYXC7ljtc3vRI+LNqywIHDnja3YJC1vZOhEpk9x0BFhqqFhrGjaLyPvGHftIX8sHpV5UH27kmQYaVlykRK7Rp0kbywCccdK8dI3Ax3B7i1jckjx18a13f/"); IWindowsSecurityContext ctx = provider.AcceptSecurityToken(Guid.NewGuid().ToString(), clientToken, "Negotiate", Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP); Assert.IsTrue(ctx.Continue); }
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 TestAcceptBadSecurityToken() { WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl(); byte[] clientToken = new byte[] { 1, 2, 3 }; Assert.That(() => { IWindowsSecurityContext ctx = provider.AcceptSecurityToken(Guid.NewGuid().ToString(), clientToken, "Negotiate", Secur32.ISC_REQ_CONNECTION, Secur32.SECURITY_NATIVE_DREP); }, Throws.TypeOf<Win32Exception>().With.Property("NativeErrorCode").EqualTo(Secur32.SEC_E_INVALID_TOKEN)); }
public void TestLogonLocalUser() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); IWindowsIdentity account = windowsAuthProviderImpl.LogonUser(_testUser.usri1_name, _testUser.usri1_password); Console.WriteLine("Sid: {0}", account.SidString); Console.WriteLine("Fqn: {0}", account.Fqn); Console.WriteLine("Guest: {0}", account.IsGuest); Assert.AreEqual(account.Fqn.ToLower(), _testUserFqn.ToLower()); Assert.IsTrue(Advapi32.IsValidSid(account.Sid)); Assert.IsFalse(account.IsGuest); Console.WriteLine("Groups: {0}", account.Groups.Length); }
public void TestGetDomain() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); if (_joinStatus != Netapi32.NetJoinStatus.NetSetupDomainName) Assert.Ignore(string.Format("{0} is not joined to a domain.", _computerName)); IWindowsDomain currentDomain = windowsAuthProviderImpl.GetDomain(_memberOf); Assert.IsNotNull(currentDomain); Console.WriteLine("Domain fqn: {0}", currentDomain.Fqn); Console.WriteLine("Domain canonical name: {0}", currentDomain.CanonicalName); Assert.AreEqual(_memberOf, currentDomain.Fqn); Assert.AreEqual(Domain.GetComputerDomain().Name, currentDomain.CanonicalName); Console.WriteLine("Groups: {0}", currentDomain.Groups.Length); }
public void TestImpersonation() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); IWindowsIdentity account = windowsAuthProviderImpl.LogonUser(_testUser.usri1_name, _testUser.usri1_password); IWindowsImpersonationContext impersonationCtx = account.Impersonate(); try { Console.WriteLine(account.SidString); Console.WriteLine(account.Fqn); Assert.AreEqual(account.Fqn, WindowsIdentity.GetCurrent().Name); } finally { impersonationCtx.RevertToSelf(); Assert.AreNotEqual(account.Fqn, WindowsIdentity.GetCurrent().Name); } }
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 TestLookupAccount() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); string username = string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName); Console.WriteLine(username); IWindowsAccount account = windowsAuthProviderImpl.LookupAccount(username); Console.WriteLine(account.SidString); Console.WriteLine(account.Fqn); Assert.AreEqual(username.ToLower(), account.Fqn.ToLower()); }
public void TestLogonUserWithDomain() { Assert.That(() => { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); windowsAuthProviderImpl.LogonDomainUser("Administrator", "domain", "invalid password"); }, Throws.TypeOf<Win32Exception>().With.Property("NativeErrorCode").EqualTo(WIN32_ERROR_LOGON_FAILURE)); }
public void TestLogonUserWithAllOptions() { Assert.That(() => { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); windowsAuthProviderImpl.LogonDomainUserEx("Administrator", "domain", "invalid password", Advapi32.LogonType.LOGON32_LOGON_NETWORK, Advapi32.LogonProvider.LOGON32_PROVIDER_DEFAULT); }, Throws.TypeOf<Win32Exception>().With.Property("NativeErrorCode").EqualTo(WIN32_ERROR_LOGON_FAILURE)); }
public void TestGetLocalGroups() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); IWindowsComputer computer = windowsAuthProviderImpl.GetCurrentComputer(); Console.WriteLine("{0}, {1} ({2})", computer.ComputerName, computer.MemberOf, computer.JoinStatus); Assert.IsTrue(computer.Groups.Length > 0); Console.WriteLine("Groups: {0}", computer.Groups.Length); }
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); }
public void TestLookupAccount() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); Console.WriteLine(_testUserFqn); IWindowsAccount account = windowsAuthProviderImpl.LookupAccount(_testUserFqn); Console.WriteLine(account.SidString); Console.WriteLine(account.Fqn); Assert.AreEqual(_testUserFqn.ToLower(), account.Fqn.ToLower()); }
public void TestLogonUser() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); windowsAuthProviderImpl.LogonUser("Administrator", "invalid password"); }