当IIS需要客户端证书时,请连接到SharePoint站点

时间:2015-07-23 14:15:17

标签: sharepoint smartcard pki cac

我目前有一个用C#开发的应用程序,它可以帮助我管理Share-point 2013站点的权限。最近,我了解到我们可能正在丢失我们的本地实例并转移到cac强制IIS后面的另一个实例。我已将我的一个测试站点转换为需要证书,并尝试了多种方式将证书发送到IIS服务器但我仍然得到

  

“远程服务器返回并且错误:(403)禁止。

以下是我尝试过的一些事情。

var handler = new WebRequestHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
handler.ClientCertificates.Add(pki.GetClientCertificate());

handler.UseProxy = false;

using (var client = new HttpClient(handler))
{
  context connection code here
}

pki.GetClientCertificate 是一种方法,我在这种情况下返回一个选定的证书我的cac证书。有趣的是,SharePoint设计师连接没有问题或提示。对此事的任何帮助都将不胜感激。

只是添加一些我尝试过的东西

context.Credentials = new SharePointOnlineCredentials(uli.username, uli.password);

uli用户名是转换为用户名的证书我有一个用于转换的类。密码是转换为安全字符串的引脚。即使将凭据添加到上下文中,我也会收到相同的消息。

1 个答案:

答案 0 :(得分:0)

我在这里找到了一个可行但缓慢的解决方案:

http://sharepoint.findincity.net/view/635399286724222582121618/ssl-certificate-error-when-using-client-object-model

唯一的问题是每次我调用上下文时我都要发送证书链。我从这个用户代码改变的一件事是:

static void context_ExecutingWebRequest(object sender, WebRequestEventArgs e)
{
 IntPtr ptr = IntPtr.Zero;
 X509Certificate2 certificate = null;
 X509Certificate t = null;
 var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
 store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);


            // Nothing to do if no cert found.
        HttpWebRequest webReq = e.WebRequestExecutor.WebRequest;
        //webReq.Proxy = new WebProxy("http://[ProxyAddress]"); 
        //Specify a proxy address if you need to 
       // X509Certificate cert = pki.GetClientCertificate();
        foreach (X509Certificate c in store.Certificates)
        {
            webReq.ClientCertificates.Add(c);
        }
    }

我只是将所有证书都转储到请求中,因为每次点击某些内容时我都不想提示。因此,如果有人有更有效的方法,请告诉我。

下面的代码显示了clientcontext的使用以及它如何验证您的证书

using (context = new ClientContext(siteurl))
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                     {
                         bool validationResult = true;
                         return validationResult;
                     };
                context.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(context_ExecutingWebRequest);

//在此行下方添加所有上下文命令  }