【问题标题】:Connect to LDAP over ssl from remote machine using "DirectoryEntry" API使用“DirectoryEntry”API 从远程机器通过 ssl 连接到 LDAP
【发布时间】:2015-07-02 12:40:32
【问题描述】:

我需要从远程机器通过 SSL 连接到 LDAP;对此有很多讨论,但其中发布的解决方案仅适用于同一 Windows Server 域机器;相同的代码无法从远程机器成功连接;

我试过的代码:

DirectoryEntry entry = new DirectoryEntry("LDAP://fqdn:636/DC=aa,DC=bb", "username", "password");
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = entry;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectCategory=person)(objectClass=user))";
SearchResultCollection results = searcher.FindAll();

再说一遍,我可以从同一个 WindowsServer 域机器上得到结果;但是当我从远程机器尝试相同的代码时,我得到了异常“服务器无法运行”

我发现这是由于证书验证失败,即 Windows Server 的证书未在远程机器上验证;但我不知道如何覆盖“DirectoryEntry 对象”的证书验证;

  • 这个post 有证书问题的解决方案;但它适用于“LdapConnection”

  • 但我需要 DirectoryEntry API 的解决方案;

仅供参考;这个post 对Java 提出了同样的问题,但没有答案;我的要求是 C#

【问题讨论】:

    标签: c# ssl openldap directoryentry


    【解决方案1】:

    很遗憾,DirectoryEntry 没有可用的证书覆盖。

    您必须使用来自System.DirectoryServices.Protocols 命名空间的较低级别的LdapConnectionLdapDirectoryIdentifier 类。

    转换您的代码应该不会太难,这样做,您将能够处理本地和远程目录资源。不久前我遇到了同样的问题,我写了一篇关于为什么会这样以及如何解决它的详细帖子 - 看看:

    Set callback for System.DirectoryServices.DirectoryEntry to handle self-signed SSL certificate?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 2011-05-16
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      相关资源
      最近更新 更多