gpt4 book ai didi

c# - 将 StartTLS 与 System.DirectoryServices 中的 LDAP 结合使用

转载 作者:太空宇宙 更新时间:2023-11-03 18:41:02 24 4
gpt4 key购买 nike

我正在尝试连接到需要 StartTLS 的 LDAP 服务器,但没有成功 - 每当我使用 SessionOptions.StartTransportLayerSecurity(..) 或将 SessionOptions.SecureSocketLayer 设置为 true 时,我都会遇到异常。

这是我使用的代码:

using (var connection = new LdapConnection(new LdapDirectoryIdentifier(config.LdapServer, config.Port, false, false)))
{
connection.SessionOptions.ProtocolVersion = 3;
connection.Credential = new NetworkCredential(config.BindDN, config.BindPassword);
connection.SessionOptions.VerifyServerCertificate += (conn, cert) => {return true;};
connection.AuthType = AuthType.Basic;
//connection.SessionOptions.SecureSocketLayer = true;
connection.SessionOptions.StartTransportLayerSecurity(null); // throws here, same if done after bind.
connection.Bind();

... do stuff with connection
}

产生的异常是“TlsOperationException:发生未指定的错误”,这在调用 StartTransportLayerSecurity 方法时发生。

我已经针对 OpenLDAP 服务器和 Active Directory 测试了代码,但都不起作用。

有谁知道如何让 StartTLS 与 System.DirectoryServices 一起工作?

最佳答案

过去存在相当多的微妙的 LDAP 堆栈不兼容性,这仍然适用于您的客户可能正在使用的潜在遗留场景。

以下是有关 OpenLDAP 和 Microsoft 的 LDAP 堆栈之间不兼容的最常见问题 (一旦有更多信息可用,我将修改和/或替换这些链接) :

显然,更新 OpenLDAP 和/或 Windows(当然最好同时更新)应该可以解决这些问题,如果它们最终成为问题的罪魁祸首的话。

祝你好运!

关于c# - 将 StartTLS 与 System.DirectoryServices 中的 LDAP 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904832/

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