tags:

views:

3463

answers:

5

Hi,

I'm trying to use the library released by Novell (Novell.Directory.Ldap). Version 2.1.10.

What I've done so far:

  • I tested the connection with an application (LdapBrowser) and it's working, so its not a communication problem.

  • It's compiled in Mono, but I'm working with Visual Studio. So created a project with the sources. I also included a reference to Mono.Security, because the project depended on it.

  • I commented a call (freeWriteSemaphore(semId); ) in the error catching part of the connection, because it was throwing more exceptions. I checked what that call did, and its just a error tracing mechanism.

  • I followed the basics steps provided in the documentation by Novell (http://www.novell.com/coolsolutions/feature/11204.html).

    // Creating an LdapConnection instance

    LdapConnection ldapConn= new LdapConnection(); ldapConn.SecureSocketLayer = ldapPort == 636;

    //Connect function will create a socket connection to the server

    ldapConn.Connect(ldapHost,ldapPort);

    //Bind function will Bind the user object Credentials to the Server

    ldapConn.Bind(userDN,userPasswd);

  • Right now it's crashing at the Bind() function. I get the error 91.

So, has someone ever used this library and seen it work? If so, what did you do to make it work, is there some special configuration needed? Is there a way to make it work in .NET environment without Mono (I can have references to Mono dlls, but I don't want it to be installed on the server)?

(UPDATE) The connection is on port 636, thus using SSL. I checked with WireShark the communication and compared with what I get from LDAP Browser. I've seen that the step where the SSL certicate is communicated, is not done by the LDAP library. So, what is the best way to make it do what its supposed to?

(UPDATE) I checked the documentation and it's indicating that it doesn't support SSL. http://www.novell.com/coolsolutions/feature/11204.html

Authenticate to the LDAP server with LdapConnection.Bind(). We support only cleartext authentication. SSL/TLS support is yet to be added.

But the documentation date from 2004, and since then, many updates have been made. And there is a parameter in the library to define if the connection uses SSL. So now I'm confused.

(UPDATE) Found a more up-to-date documentation : http://developer.novell.com/documentation//ldapcsharp/index.html?page=/documentation//ldapcsharp/cnet/data/bqwa5p0.html. The way the SSL connection is made, is by registering the certificate on the server. The problem is that what I'm doing is not bound to a specific Novell server, so the certificate must be obtained dynamically.

+1  A: 

91 is "cannot connect". Try to put the server in "ldap://x.x.x.x" format, check that userDN is set properly (with domain etc).

I am often using WireShark to see what is going on at the network level (it is aware of LDAP protocol).

Dmitry Khalatov
+1  A: 

I think I may have already offered this answer to someone else in a different question.

[OtherQuestion on LDAP][1]

Two issues I think: 1) What kind of bind are you trying to do? SSL? Clear text? Anonymous?

2) How is it configured on the eDirectory side for LDAP binds?

The tool LDAP Browser, are you referring to the one at this link? Free LDAP Browser

On the eDirectory side, they can require TLS for all LDAP communication, and they can disallow Anonymous binds.

Can you ask the folks at the other end to enable LDAP tracing (Using DStrace with the +LDAP option enabled, some links for how to use Dstrace on Novell eDirectory look at: Different types of Dstrace Capturing and understand DS Trace for Identity Manager.)

That usually will show an error message that will enlighten you.

My guess is either Require TLS is enabled, and you might not be doing a successful SSL bind.

If so, try to connect on port 636, with SSL enabled, and a fully qualified DN for the user you are trying to login as.

If you are trying with SSL enabled, and you are not getting a pop up box about accepting the tree CA's trusted root certficate, then perhaps the CA or the SSL certificate taht the eDirectory server is user has expired or is broken. (There are any number of causes for this that can be common, and take but a moment to fix).

Usually in Dstrace you will see an error about the SSL certificate if there is a problem. An example from a Novell Identity Manager perspective of an expired certificate is in this article: Certificate Expired As well as some details on how to fix the certificates.

Next possibility is that the DN you are specifying is not quite correct.

Let me know if you need more help.

geoffc
We can`t change anything on the Novell server, it`s managed by another team and running in a live environment. So we have a connection acces to test the authentication with it, but that's all we have. With the LDAP browser we are able to connect to it, so its a matter of making this DLL work.
ceetheman
Do you have the tree roots certificate in your Keystore? (Not sure what the C# equivalent is called). It is not server specific, per se. It is more tree specific. I.e. One root CA cert per tree will allow access to all servers.
geoffc
A: 

Following my previous post - if you have to use secure connection, try to use ldaps:// as a prefix to server address.

If there is no SSL/TLS support, you can try this - guidelines and .NET wrapper for OpenLDAP library.

One important point - there are settings for TLS security level in OpenLDAP, so if your LDAP server has self-signed certificate you either have to import it on a client side or set TLS to not check the signing authority *that is less secure of course).

Dmitry Khalatov
Adding ldaps:// make the address invalid. The server uses SSL and the certificate is imported on the client-side.
ceetheman
And the OpenLDAP library is made with an Visual Studio and there is no compiled version (its dating from before 2004).
ceetheman
+2  A: 

Hi,

I finally found a way to make this work.

First, theses posts helped me get on the right track : http://directoryprogramming.net/forums/thread/788.aspx

Second, I got a compiled dll of the Novell LDAP Library and used the Mono.Security.Dll.

The solution:

I added this function to the code

// This is the Callback handler - after "Binding" this is called
        public bool MySSLHandler(Syscert.X509Certificate certificate, int[] certificateErrors)
        {

            X509Store store = null;
            X509Stores stores = X509StoreManager.LocalMachine;
            store = stores.TrustedRoot;

            //Import the details of the certificate from the server.

            X509Certificate x509 = null;
            X509CertificateCollection coll = new X509CertificateCollection();
            byte[] data = certificate.GetRawCertData();
            if (data != null)
                x509 = new X509Certificate(data);

            //List the details of the Server

            //if (bindCount == 1)
            //{

            Response.Write("<b><u>CERTIFICATE DETAILS:</b></u> <br>");
            Response.Write("  Self Signed = " + x509.IsSelfSigned + "  X.509  version=" + x509.Version + "<br>");
            Response.Write("  Serial Number: " + CryptoConvert.ToHex(x509.SerialNumber) + "<br>");
            Response.Write("  Issuer Name:   " + x509.IssuerName.ToString() + "<br>");
            Response.Write("  Subject Name:  " + x509.SubjectName.ToString() + "<br>");
            Response.Write("  Valid From:    " + x509.ValidFrom.ToString() + "<br>");
            Response.Write("  Valid Until:   " + x509.ValidUntil.ToString() + "<br>");
            Response.Write("  Unique Hash:   " + CryptoConvert.ToHex(x509.Hash).ToString() + "<br>");
            // }

            bHowToProceed = true;
            if (bHowToProceed == true)
            {
                //Add the certificate to the store. This is \Documents and Settings\program data\.mono. . .
                if (x509 != null)
                    coll.Add(x509);
                store.Import(x509);
                if (bindCount == 1)
                    removeFlag = true;
            }

            if (bHowToProceed == false)
            {
                //Remove the certificate added from the store.

                if (removeFlag == true && bindCount > 1)
                {
                    foreach (X509Certificate xt509 in store.Certificates)
                    {
                        if (CryptoConvert.ToHex(xt509.Hash) == CryptoConvert.ToHex(x509.Hash))
                        {
                            store.Remove(x509);
                        }
                    }
                }
                Response.Write("SSL Bind Failed.");
            }
            return bHowToProceed;
        }

And i used it in the binding process

// Create Connection
                LdapConnection conn = new LdapConnection();
                conn.SecureSocketLayer = true;
                Response.Write("Connecting to:" + ldapHost);

                conn.UserDefinedServerCertValidationDelegate += new
                    CertificateValidationCallback(MySSLHandler);

                if (bHowToProceed == false)
                    conn.Disconnect();
                if (bHowToProceed == true)
                {
                    conn.Connect(ldapHost, ldapPort);
                    conn.Bind(loginDN, password);
                    Response.Write(" SSL Bind Successfull ");

                    conn.Disconnect();
                }
                quit = false;

The key elements are using the SSL Handler to dynamically obtain the Certificate, and using X509StoreManager.LocalMachine so that when the website is running its able to save and fetch the certificates.

Thanks for the help. Hopes this will help someone.

ceetheman
This looks like it might be helpful to me, but I can't tell because I can't find a running Novell server that has the library. Any chance you could email it to me? chrisfant at G mail
Fantius
A: 

This might be a late... but the answer by ceetheman worked out great. THANKS for the help!!