gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:00:48 24 4
gpt4 key购买 nike

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

到目前为止我做了什么:

  • 我测试了与应用程序 (LdapBrowser) 的连接,它正在运行,所以这不是通信问题。

  • 它是用 Mono 编译的,但我使用的是 Visual Studio。所以用源代码创建了一个项目。我还包含了对 Mono.Security 的引用,因为该项目依赖于它。

  • 我在连接的错误捕获部分评论了一个调用 (freeWriteSemaphore(semId); ),因为它抛出了更多异常。我检查了那个调用做了什么,它只是一个错误跟踪机制。

  • 我遵循了 Novell (http://www.novell.com/coolsolutions/feature/11204.html) 文档中提供的基本步骤。

    //创建一个 LdapConnection 实例

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

    //Connect 函数将创建到服务器的套接字连接

    ldapConn.Connect(ldapHost,ldapPort);

    //绑定(bind)函数将用户对象凭证绑定(bind)到服务器

    ldapConn.Bind(userDN,userPasswd);

  • 现在它在 Bind() 函数处崩溃。我收到错误 91。

那么,有人使用过这个库并看到它有效吗?如果是这样,你做了什么让它工作,是否需要一些特殊的配置?有没有办法让它在没有 Mono 的 .NET 环境中工作(我可以引用 Mono dll,但我不希望它安装在服务器上)?

(更新)连接在端口 636 上,因此使用 SSL。我用 WireShark 检查了通信,并与我从 LDAP 浏览器获得的内容进行了比较。我已经看到传递 SSL 证书的步骤不是由 LDAP 库完成的。那么,让它发挥应有作用的最佳方法是什么?

(更新)我检查了文档,它表明它不支持 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.

但是文档日期是从 2004 年开始的,从那时起,已经进行了许多更新。并且库中有一个参数来定义连接是否使用 SSL。所以现在我很困惑。

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

最佳答案

我是来寻找类似问题的解决方案的。当使用来自 Novell 网站的相同代码时,我的绑定(bind)命令也会失败。对我有用的解决方案是添加动态证书验证回调。你可以阅读它here .

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

关于c# - Novell LDAP C# - Novell.Directory.Ldap - 有人让它工作了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/386982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com