首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Novell C# -- Novell.Directory.Ldap --有人让它工作了吗?

Novell C# -- Novell.Directory.Ldap --有人让它工作了吗?
EN

Stack Overflow用户
提问于 2008-12-22 18:36:10
回答 8查看 29.8K关注 0票数 14

我正在尝试使用Novell (Novell.Directory.Ldap)发布的库。版本2.1.10。

我到目前为止所做的事:

  • 我测试了与一个应用程序(LdapBrowser)的连接,它正在工作,所以它不是一个通信问题。
  • 它是用Mono编译的,但我正在使用Visual。所以用资源创建了一个项目。我还包括了对Mono.Security的引用,因为项目依赖于它。
  • 我在捕获连接部分的错误中注释了一个调用(freeWriteSemaphore(semId);),因为它抛出了更多的异常。我检查了那个调用做了什么,它只是一个错误跟踪机制。
  • 我遵循了Novell (http://www.novell.com/coolsolutions/feature/11204.html)文档中提供的基本步骤。 //创建LdapConnection实例 LdapConnection ldapConn=新LdapConnection();ldapConn.SecureSocketLayer = ldapPort == 636; //Connect函数将创建到服务器的套接字连接 ldapConn.Connect(ldapHost,ldapPort); //Bind函数将用户对象凭据绑定到服务器 ldapConn.Bind(userDN,userPasswd);
  • 现在,它正在崩溃Bind()函数。我得到了错误91。

有人用过这个图书馆看过吗?如果是这样的话,你做了什么使它工作,有什么特殊的配置需要吗?有没有一种方法可以让它在没有Mono的.NET环境中工作(我可以引用Mono,但我不希望它安装在服务器上)?

(更新)连接位于端口636,因此使用SSL。我与WireShark检查了通信,并将其与从LDAP浏览器获得的信息进行了比较。我已经看到,SSL证书传递的步骤不是由LDAP库完成的。那么,做它应该做的事情的最好方法是什么呢?

(更新)我检查了文档,它表明它不支持SSL。http://www.novell.com/coolsolutions/feature/11204.html

使用LdapConnection.Bind()对LDAP服务器进行身份验证。我们只支持明文认证。SSL/TLS支持还有待增加。

但是文档从2004年开始,从那以后,已经做了许多更新。库中有一个参数来定义连接是否使用SSL。所以我现在很困惑。

(更新)找到了更最新的文档:http://developer.novell.com/documentation//ldapcsharp/index.html?page=/documentation//ldapcsharp/cnet/data/bqwa5p0.html。SSL连接的方式是在服务器上注册证书。问题是,我所做的并不是绑定到特定的Novell服务器,因此必须动态获取证书。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2009-01-13 21:54:48

我终于找到了让这件事成功的方法。

首先,这些帖子帮助我走上了正确的轨道:http://directoryprogramming.net/forums/thread/788.aspx

其次,我获得了Novell库的编译dll,并使用了Mono.Security.Dll。

解决办法:

我将这个函数添加到代码中

代码语言:javascript
复制
// 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;
        }

我在绑定过程中使用了它

代码语言:javascript
复制
// 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;

关键元素是使用SSL动态获取证书,并使用X509StoreManager.LocalMachine,以便在网站运行时能够保存和获取证书。

票数 4
EN

Stack Overflow用户

发布于 2012-12-06 14:38:46

我来找一个类似问题的解决方案。使用Novell网站的相同代码时,我的bind命令也会失败。对我有效的解决方案是添加一个动态证书验证回调。你可以读到它,这里

代码语言:javascript
复制
        // Creating an LdapConnection instance 
        LdapConnection ldapConn = new LdapConnection();

        ldapConn.SecureSocketLayer = true;

        ldapConn.UserDefinedServerCertValidationDelegate += new
                CertificateValidationCallback(MySSLHandler);


        //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);

        // Searches in the Marketing container and return all child entries just below this
        //container i.e. Single level search
        LdapSearchResults lsc = ldapConn.Search("ou=users,o=uga",
                           LdapConnection.SCOPE_SUB,
                           "objectClass=*",
                           null,
                           false);

        while (lsc.hasMore())
        {
            LdapEntry nextEntry = null;
            try
            {
                nextEntry = lsc.next();
            }
            catch (LdapException e)
            {
                Console.WriteLine("Error: " + e.LdapErrorMessage);
                // Exception is thrown, go for next entry
                continue;
            }
            Console.WriteLine("\n" + nextEntry.DN);
            LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
            System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
            while (ienum.MoveNext())
            {
                LdapAttribute attribute = (LdapAttribute)ienum.Current;
                string attributeName = attribute.Name;
                string attributeVal = attribute.StringValue;
                Console.WriteLine(attributeName + "value:" + attributeVal);
            }
        }
        ldapConn.Disconnect();
        Console.ReadKey();
    }

public static bool MySSLHandler(Syscert.X509Certificate certificate,
            int[] certificateErrors)
        {

            X509Store store = null;
            X509Stores stores = X509StoreManager.CurrentUser;
            //string input;
            store = stores.TrustedRoot;

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

            return true;
        }
票数 7
EN

Stack Overflow用户

发布于 2021-06-03 09:25:40

UserDefinedServerCertValidationDelegate已经过时,因此如果存在无效的ssl证书问题,可以以这种方式跳过证书证书:

代码语言:javascript
复制
        LdapConnectionOptions options = new LdapConnectionOptions()
            .ConfigureRemoteCertificateValidationCallback(new CertCallback((a, b, c, d) => true))
            .UseSsl();

        LdapConnection connection = new LdapConnection(options);

        connection.Connect(...);

但是,如果忽略证书是应用程序的安全解决方案,则应进行检查。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/386982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档