通过 ldaps 修改 Active Directory 中的属性值

Modify an attribute value in Active Directory via ldaps

我执行了下面的代码,通过ldaps.It修改了Active Directory中的一个属性值properly.In此外,当我通过WireShark分析tcpdump捕获的数据包时,我发现这些数据包是加密的。

using (DirectoryEntry entry = new DirectoryEntry("LDAP://192.168.109.4:636/OU=People,DC=dev,DC=com", "dev\user", "password"))
{
    entry.Properties["description"].Value = "a new description";
    entry.CommitChanges();
    entry.Close();
}

但是,我有一个 question.I 猜测需要下面的语句来通过 ldaps 加密数据包。

entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;

在这种情况下,没有上面的语句也能很好地工作。

有谁知道原因吗?

您看到连接打开时的 SSL 握手了吗?通常,当您使用 IP 地址访问 SSL 时,它甚至无法工作。它还可以使用 Kerberos 进行加密,这将使用 IP 地址在端口 389 上工作,尽管您通常必须为此指定 AuthenticationTypes.Sealing

但是,它知道端口 636 是 LDAPS 端口,所以如果您指定端口 636,它会自动进行 SSL 握手。

也可以排除端口,指定AuthenticationTypes.SecureSocketsLayer,会自动通过636端口连接:

new DirectoryEntry(
    "LDAP://dev.com/OU=People,DC=dev,DC=com",
    "dev\user", "password",
    AuthenticationTypes.Secure | AuthenticationTypes.SecureSocketsLayer
)

AuthenticationType 默认是安全的。

SSL 是服务器端配置,因此 LDAP 服务器管理员必须启用 SSL。