c# connecting to Active Directory over ssl give ldap server unavailable

4k views Asked by At

I am trying to connect to active directory over ssl using .net System.DirectoryServices.Protocols namespace api

Here is the snippet that I have written for connecting to active directory

LdapConnection ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("<ipaddress>:<port>"));
ldapConnection.AuthType = AuthType.Basic;

LdapSessionOptions options = ldapConnection.SessionOptions;
options.SecureSocketLayer = true;
options.ProtocolVersion = 3;

X509Certificate cert = new X509Certificate();
cert.Import(@"E:\client.crt");

ldapConnection.ClientCertificates.Add(cert);
ldapConnection.Credential = new NetworkCredential("administrator", "xxxxxxxxxx");

ldapConnection.Bind();
Console.WriteLine("successfully connected");

When I am trying to execute this snippet, I always get LDAP server unavailable error. I've written a JAVA equivalent for the same and it is able to connect to server, so I think there is no issue with the certificate or active directory connection. I am also able to connect to Active directory without ssl, using the same IP address and port 389.

Thanks

1

There are 1 answers

1
Somasundaram Pattabiraman On
LdapConnection ldapConnection = new LdapConnection(server + ":" + port);
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.Credential = new System.Net.NetworkCredential(username,
                                                                  password);
ldapConnection.SessionOptions.ProtocolVersion = 3;
if (sslEnabled)
{
    ldapConnection.SessionOptions.SecureSocketLayer = sslEnabled;
}

This is what I did and I am able to connect to AD over SSL. You said you have Java program connecting to the same server over SSL. Are you running the Java program from the same machine as your c#? if not and in case of a self signed certificate in AD, install that certificate in your client machine and try.