首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >插入智能卡的PrincipalContext

插入智能卡的PrincipalContext
EN

Stack Overflow用户
提问于 2017-11-07 14:50:03
回答 1查看 774关注 0票数 0

我们已经使用了一段时间的应用程序,它使用System.DirectoryServices.AccountManagement与活动目录(域上下文)通信。

代码语言:javascript
复制
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

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2018-05-03 13:53:51

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

代码语言:javascript
复制
private bool BindLdap(NetworkCredential creds, ContextOptions contextOptions)
{
  LdapConnection current = (LdapConnection) null;
  ...
  current = new LdapConnection(this.directoryIdent);
  ...
  try
  {
    current.SessionOptions.FastConcurrentBind();

FastConcurrentBind方法查找证书,并在它请求PIN的连接选项中启用SSL。

如果不支持快速绑定,则调用Bind并执行相同的操作:

代码语言:javascript
复制
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);
}

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

代码语言:javascript
复制
current.SessionOptions.QueryClientCertificate = 
  new QueryClientCertificateCallback((a,b) => null);

问题是,不能从外部对内部类执行此操作。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47160786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档