【问题标题】:Is LdapConnection secure to autenticate user in ActiveDirectory?LdapConnection 对 Active Directory 中的用户进行身份验证是否安全?
【发布时间】:2018-02-28 15:53:02
【问题描述】:

我已经构建了这个函数来验证用户是否在 ActiveDirectory 中启用。

LdapConnection传输的数据是加密的?

这是通过userpassword 传输信息的安全解决方案吗?

try
{
    LdapConnection connection = new LdapConnection(server);

    NetworkCredential credential = new NetworkCredential(user, password);
    connection.Credential = credential;

    connection.Bind();
}
catch (LdapException lexc)
{
   return lexc.Message;
}
catch (Exception exc)
{
   return exc.Message;
}

【问题讨论】:

  • 我希望您的密码是SecureString 类型。顺便说一句,我在任何地方都看不到与在 AD 中启用用户相关的代码!您能否改写您的问题以突出您的确切要求?您在说 LdapConnection 类传输的哪种数据?引用自 MSDN:The LdapConnection class creates a TCP/IP or UDP LDAP connection to Microsoft Active Directory Domain Services or an LDAP server..
  • 用户 e 密码是 SecureString。我问传输的数据是否在 Ldap 通道上加密。 @Am_I_Helpful

标签: c# winforms authentication active-directory ldap


【解决方案1】:

不是默认的,没有。

Active Directory 在多个端口上工作,它们执行相关功能:

  1. 389:LDAP(仅限单域)- 这是默认设置
  2. 636:基于 SSL 的 LDAP
  3. 3268:全局目录(您的 AD 林)
  4. 3269:基于 SSL 的全局目录

附加信息: https://msdn.microsoft.com/en-us/library/cc875824.aspx

所以要让它使用加密连接,你需要告诉它使用端口 636 或 3269,然后告诉它使用 SSL,像这样:

LdapConnection connection = new LdapConnection($"{server}:636");
connection.SessionOptions.SecureSocketLayer=true;

警告:根据我的经验,您在建立此连接时可能会遇到问题,因为默认情况下,域控制器使用自签名证书进行加密,您的客户端计算机可能不信任该证书。如果您遇到该问题,您可以在您的计算机上安装该证书以使其受信任。

但请记住,证书有两个目的:

  1. 加密传输中的数据,并
  2. 确保您正在与之交谈的服务器实际上是您要与之交谈的服务器

1 总是会出现在任何证书上(甚至是自签名证书)。 #2 是证书由不受信任的来源颁发时连接失败的原因。

如果您确信不需要证书用于目的 #2,那么您可以告诉它忽略与不受信任的证书相关的错误,如下所示:

connection.SessionOptions.VerifyServerCertificate =
            new VerifyServerCertificateCallback((con, cer) => true);

【讨论】:

    猜你喜欢
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多