如何使用 X509Certificate2 作为 SharePointService 请求的凭据

发布于 2024-11-11 16:32:15 字数 1034 浏览 8 评论 0原文

我有一个 MOSS 2007 服务器场,需要客户端证书才能访问。我编写了几种使用内置 SharePoint 服务从网站检索数据的方法。但是,在我的本地测试环境之外,一切都需要客户端证书才能访问服务。

我检索证书的方法是:

private static X509Certificate2 GetCertCreds()
{
     X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
     try
     {
         store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "SiteIdentityCertificateSerialNumber", true);

         Assert.IsNotNull(certs);

         return certs[0];
     }
     finally
     {
          store.Close();
     }
}

然后在使用中我必须有类似的东西:

using (ListsServiceProxy.Lists service = new ListsServiceProxy.Lists())
{
    service.Crendentials = GetCredentials();
    XmlNode idResultsNode = service.GetListItems(documentLibraryName, null, queryNode, viewNode, "1", optionNode, null);
}

由于类型不匹配,这不会编译。我是否以错误的方式处理这个问题?如果没有,是否有办法使用证书作为服务凭证?我认为最终我想做的是将 X509Certificate2 转换为 ICredentials。任何帮助或建议将不胜感激。

I have a MOSS 2007 farm that requires a client certificate to access. I have written several methods that use the built in SharePoint services to retrieve data from the site. However, outside of my local test environment everything requires a client cert to access the services.

My method for retrieving the cert is:

private static X509Certificate2 GetCertCreds()
{
     X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
     try
     {
         store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "SiteIdentityCertificateSerialNumber", true);

         Assert.IsNotNull(certs);

         return certs[0];
     }
     finally
     {
          store.Close();
     }
}

Then in use I have to have something LIKE:

using (ListsServiceProxy.Lists service = new ListsServiceProxy.Lists())
{
    service.Crendentials = GetCredentials();
    XmlNode idResultsNode = service.GetListItems(documentLibraryName, null, queryNode, viewNode, "1", optionNode, null);
}

This is not compiling because of the type mismatch. Am I going about this the wrong way? If not is there a way to use the certificate as the services credentials? I think in end what I'm trying to do is convert an X509Certificate2 to ICredentials. Any help or advice would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑依然 2024-11-18 16:32:16

事实证明我全都错了。为了正确执行此操作,我将:

service.Credentials = GetCertCreds()

替换为

service.ClientCertificates.Add(GetCretCreds());

只需将证书添加到服务的客户端证书集合中即可。

It turns out I had it all wrong. To correctly do this I replaced:

service.Credentials = GetCertCreds()

with

service.ClientCertificates.Add(GetCretCreds());

Adding the certificate into the service's client certificates collection is all that needed to happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文