I am unable to connect to Active Directory with TLS 1.2 using the DirectoryService class. I am able to connect using TLS 1.2 via LDP on Windows, Open Source LDAPAdmin on Windows and LdapConnection in a .Net 4.7.2 console application. I have verified the TLS 1.2 connections using WireShark. Here is some sample code:
static void Main(string[] args)
{
LdapConnection conn = new LdapConnection("server.domain.com:636");
var op = conn.SessionOptions;
op.ProtocolVersion = 3;
op.SecureSocketLayer = true;
op.VerifyServerCertificate = (ldapConnection, serverCertificate) =>
{
return true;
};
conn.AuthType = AuthType.Negotiate;
var cred = new NetworkCredential("user@domain.com", "password");
conn.Credential = cred;
conn.Bind(cred);
Console.WriteLine("LdapConnection Success");
// Is not TLS 1.2
var de = new DirectoryEntry("LDAP://server.domain.com", "user@domain.com", "password", AuthenticationTypes.Secure);
try
{
foreach (var child in de.Children)
{
Console.WriteLine(child);
}
Console.WriteLine($"{de.Path} Success");
}
catch (Exception ex)
{
Console.WriteLine($"{de.Path} {ex.Message}");
}
//Does not work
de = new DirectoryEntry("LDAP://server.domain.com:636", "user@domain.com", "password");
try
{
foreach (var child in de.Children)
{
Console.WriteLine(child);
}
Console.WriteLine($"{de.Path} Success");
}
catch (Exception ex)
{
Console.WriteLine($"{de.Path} {ex.Message}");
}
//Does not work
de = new DirectoryEntry("LDAP://server.domain.com", "user@domain.com", "password", AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.Secure);
try
{
foreach (var child in de.Children)
{
Console.WriteLine(child);
}
Console.WriteLine($"{de.Path} Success");
}
catch (Exception ex)
{
Console.WriteLine($"{de.Path} {ex.Message}");
}
//Does not work
de = new DirectoryEntry("LDAP://server.domain.com:636", "user@domain.com", "password", AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.Secure);
try
{
foreach (var child in de.Children)
{
Console.WriteLine(child);
}
Console.WriteLine($"{de.Path} Success");
}
catch (Exception ex)
{
Console.WriteLine($"{de.Path} {ex.Message}");
}
Console.ReadKey();
}
Any Idea's how to connect through the DirectoryService class? I have seem many questions about this topic in StackOverflow which is why I included all of the other answers I read about in the sample code.