【问题标题】:Contact Active Directory with SSL使用 SSL 联系 Active Directory
【发布时间】:2016-06-18 07:04:49
【问题描述】:

我有一种方法可以根据 Active Directory 验证用户凭据。我想将此方法与 SSL 一起使用,但我无法使用它。

主要的问题是我有一个在我们网络之外的服务器(它叫做 DMZ 吗?)。从那里我想联系我的活动目录,这就是我想使用 SSL 的原因。

在我的本地计算机(不是来自 DMZ)上使用它时,我收到此错误:

System.DirectoryServices.AccountManagement.PrincipalServerDownException:无法联系服务器。 ---> System.DirectoryServices.Protocols.LdapException: LDAP 服务器不可用。
在 System.DirectoryServices.Protocols.LdapConnection.Connect()
在 System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest 请求,Int32 和 messageID)
在 System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest 请求,TimeSpan requestTimeout)
在 System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest 请求)
在 System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties&properties)

--- 内部异常堆栈跟踪结束 ---
在 System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(字符串服务器名称、服务器属性和属性)
在 System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
在 System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType,字符串名称,字符串容器,ContextOptions 选项,字符串用户名,字符串密码)
在 System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType,字符串名称,字符串容器,ContextOptions 选项)
在 Authorization.AuthorizeAD.ValidateCredentials(字符串用户名,字符串密码)

我认为在从我们的服务器尝试之前,最好先从本地使用 SSL。

我的方法:

public bool ValidateCredentials(string username, string password) {
        using (
            var context = new PrincipalContext(ContextType.Domain, ContextName, ContextContainer,
                ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing |
                ContextOptions.SecureSocketLayer)) {
            return context.ValidateCredentials(username, password);
        }
    }

如前所述,没有ContextOptions.SecureSocketLayer 也可以正常工作(如果参数为空,则其他三个默认情况下)

有谁知道我应该如何正确使用PrincipalContext 和 SSL?

【问题讨论】:

    标签: c# ssl active-directory dmz


    【解决方案1】:

    您确定它支持 SSL 并且防火墙已打开以允许该连接吗?

    LDAP 使用端口 389。LDAPS 使用端口 636。

    如果您安装了 telnet 客户端,您可以使用它来检查连接:

    telnet yourdomain.com 636
    

    如果你得到一个空白屏幕,它工作。如果无法连接,它会告诉你。

    如果它已打开但仍无法正常工作,则可能是使用了自签名 SSL 证书。检查 Windows 事件日志中与证书相关的错误。

    我还使用 Chrome 来检查证书。你必须像这样运行 chrome:

    chrome.exe --explicitly-allowed-ports=636
    

    然后浏览到https://yourdomain.com:636,看看它是否给你任何证书错误。然后你就可以真正看到证书了。如果这是问题所在,您或许可以导入证书并明确信任它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多