c# - LDAP over SSL 在设置快速并发绑定(bind)时返回 'unwilling to perform' 错误 (PrincipalContext.ValidateCredentials)

标签 c# ssl active-directory ldap directoryservices

最初问题始于 .NET\C# 和 ValidateCredentials方法 - 没有 SSL 它工作,使用 SSL 它返回“服务器无法处理目录请求”。但我缩小了范围并简化为下面发布的 C++ 代码。

MSDN 说 LDAP_OPT_FAST_CONCURRENT_BIND支持多个简单绑定(bind)并且不适用于接下来的 2 个选项:LDAP_OPT_SIGN , LDAP_OPT_ENCRYPT .它还说使用不带 SSL 的简单绑定(bind)是 not good因为当通过网络发送时,您将以明文形式公开您的凭据。

因此,看起来当您在没有签名和加密的情况下通过 SSL 使用 LDAP 时,您可以启用 FCB。但每次我这样做时,我都会收到 0x35(不愿执行)。 Article关于密码身份验证也没有提及 SSL。所以,问题是——我做错了什么?或者,Microsoft 是否应该在其文档中说明 LDAP_OPT_FAST_CONCURRENT_BIND 不支持 SSL?

#include "stdafx.h"
#include <windows.h>
#include <winldap.h>

int main()
{
    PCHAR username = "bla-bla-bla";
    PCHAR password = "bla-bla-bla";
    PCHAR hostName = "bla-bla-bla";
    ULONG lRtn = 0;
    LDAP* pLdapConnection = NULL;

    pLdapConnection = ldap_init(hostName, LDAP_PORT);

    // NOTE: those 2 below - will return 0x35 (Unwilling to perform) during setting LDAP_OPT_FAST_CONCURRENT_BIND option
    //pLdapConnection = ldap_init(hostName, LDAP_SSL_PORT);
    //pLdapConnection = ldap_sslinit(hostName, LDAP_SSL_PORT, 1);

    if (pLdapConnection == NULL)
    {
        printf("ldap_init failed with 0x%x.\n", LdapGetLastError());
        ldap_unbind(pLdapConnection);
        return -1;
    }
    else
        printf("ldap_init succeeded \n");

    lRtn = ldap_connect(pLdapConnection, NULL);
    if (lRtn == LDAP_SUCCESS)
        printf("ldap_connect succeeded \n");
    else
    {
        printf("ldap_connect failed with 0x%lx.\n", lRtn);
        ldap_unbind(pLdapConnection);
        return -1;
    }

    // Enable concurrent binding - returns 0x35 when used with SSL.
    lRtn = ldap_set_option(pLdapConnection, LDAP_OPT_FAST_CONCURRENT_BIND, LDAP_OPT_ON);
    if (lRtn == LDAP_SUCCESS)
        printf("Fast concurrent binding enabled\n");
    else
    {
        printf("SetOption Error:%0lX\n", lRtn);
        ldap_unbind(pLdapConnection);
        return -1;
    }

    lRtn = ldap_simple_bind_s(pLdapConnection, username, password);
    if (lRtn == LDAP_SUCCESS)
    {
        printf("ldap_simple_bind_s succeeded \n");
        password = NULL;         // Remove password pointer
    }
    else
    {
        printf("ldap_bind_s failed with 0x%lx.\n", lRtn);
        ldap_unbind(pLdapConnection);
        return -1;
    }

    ldap_unbind(pLdapConnection);

    return 0;
}

最佳答案

在这里查看我的回复:https://stackoverflow.com/a/49310208/1950304 .

Or, may be Microsoft should state in their documentation that SSL is not supported with LDAP_OPT_FAST_CONCURRENT_BIND?

这不是一般的 SSL,它是相互 SSL。

关于c# - LDAP over SSL 在设置快速并发绑定(bind)时返回 'unwilling to perform' 错误 (PrincipalContext.ValidateCredentials),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44200011/

相关文章:

c# - 将数组发送到 API 并获取空列表

c# - 解析整数时出现 'input string was not in a correct format'

facebook - Facebook Canvas 应用是否需要提供非安全端点?

c# - 我应该使用域名还是域 Controller 名称绑定(bind)到 Active Directory?

c# - 是否有可能以 mvvm 模式在 wpf datagrid 上获取动态列?

c# - 如何调用javascript函数绑定(bind)动态添加的div

java - 如何在 Websphere 8.5.5.9 中为 mSSL 设置客户端证书?

encryption - SSH:登录时,密码是否为明文/可嗅探?

sharepoint-2010 - 如何将事件目录数据填充到共享点列表表单中

reactjs - ReactJS 中的 LDAP 协议(protocol)和连接