【问题标题】:PrincipalContext with smartcard inserted插入智能卡的 PrincipalContext
【发布时间】:2017-11-07 14:50:03
【问题描述】:

一段时间以来,我们一直在使用使用 System.DirectoryServices.AccountManagement 与 Active Directory(域上下文)通信的应用程序。

ContextOptions options = ContextOptions.Negotiate | 
ContextOptions.SecureSocketLayer;
Using(PrincipalContext adContext = new PrincipalContext(ContextType.Domain, "AD.DOMAIN", "DC=AD,DC=intranet", options)) 
{

//Do stuff

}

在我们插入智能卡之前,这一切正常。一旦我们插入带有用户证书的智能卡,它就会在遇到 PrincipalContext 构造函数时提示输入智能卡引脚。取消时,应用程序将崩溃。当输入正确的密码时,它会一遍又一遍地提示。

它似乎与在后台设置的 TLS 会话相关联。当我们不启用加密时,该问题不存在。但加密是强制性的。

以前有人遇到过这个问题吗?资源似乎有限。我能找到的最接近的是:

https://connect.microsoft.com/VisualStudio/feedback/details/3100569/initializing-contextoptions-does-not-work-in-system-directoryservices-accountmanagement-principalcontext-constructor

提前致谢

【问题讨论】:

    标签: c# .net active-directory account-management


    【解决方案1】:

    PrincipalContext 在 LDAP 绑定期间利用内部类 CredentialValidator 进行身份验证。

    private bool BindLdap(NetworkCredential creds, ContextOptions contextOptions)
    {
      LdapConnection current = (LdapConnection) null;
      ...
      current = new LdapConnection(this.directoryIdent);
      ...
      try
      {
        current.SessionOptions.FastConcurrentBind();
    

    FastConcurrentBind 方法会找到证书,并且由于在连接选项中启用了 SSL,它会要求输入 PIN。

    如果不支持快速绑定 Bind 并执行相同操作:

    private void lockedLdapBind(
      LdapConnection current, 
      NetworkCredential creds, 
      ContextOptions contextOptions)
    {
      current.AuthType = 
        (ContextOptions.SimpleBind & contextOptions) > (ContextOptions) 0 
          ? AuthType.Basic 
          : AuthType.Negotiate;
      current.SessionOptions.Signing = 
        (ContextOptions.Signing & contextOptions) > (ContextOptions) 0;
      current.SessionOptions.Sealing = 
        (ContextOptions.Sealing & contextOptions) > (ContextOptions) 0;
    
      if (creds.UserName == null && creds.Password == null)
        current.Bind();
      else
        current.Bind(creds);
    }
    

    为了防止这种情况,必须像这样修改会话选项

    current.SessionOptions.QueryClientCertificate = 
      new QueryClientCertificateCallback((a,b) => null);
    

    问题是这不能从外部对内部类进行。

    这只能在手动构造 LdapConnection 对象时完成。

    【讨论】:

    • 非常感谢。我一直在尝试向 LDAP 添加智能卡身份验证,一旦我回到没有证书的常规 TLS 身份验证,我就遇到了 Windows 不断要求我插入智能卡的问题。这立即修复了它。
    • 我很乐意提供帮助。请您将此标记为答案并投票,然后让其他用户立即看到这是正确的,请
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2015-02-25
    • 2011-11-03
    • 1970-01-01
    相关资源
    最近更新 更多