1

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

vishva
  • 366
  • 5
  • 17
  • Try providing protocol prefix for the connection identifier: "ldaps://192.168.0.101:636". That should force the SSL connection. If that does not help, I think there is some kind of issue with the certificate as that is the most common problem when you get "Can't contact ldap server" or similar over SSL. – Robert Rossmann Sep 01 '13 at 09:57

1 Answers1

0
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.