在使用 Web 服务的客户端应用程序中使用证书

发布于 2024-09-24 04:38:56 字数 747 浏览 5 评论 0原文

我正在实现一个使用 Web 服务的 VB.NET 桌面应用程序。

Web 服务是用 Java 实现的,我目前在本地主机上使用 Tomcat 来托管 Web 服务。

Web 服务需要与客户端进行安全通信,因此我遵循了概述如何使用 Java 的 keytool.exe 创建两个 .jks 密钥库(一个用于客户端,一个用于服务器)的说明,然后创建两个 .cer 证书(一个一个用于客户端,一个用于服务器)

我已将生成的密钥库和证书放入 Web 服务期望它们的目录中(根据说明)

我已将证书安装到 TrustedPeople 中,并尝试通过设置来使用该证书ClientCredentials.ClientCertificates 属性如下:

myServiceProxy.ClientCredentials.ClientCertificate.SetCertificate(storeLocation.CurrentUser, StoreName.TrustedPeople, X509FindType.FindByIssuerName, "name")

当我尝试调用任何方法时,我不断收到以下错误消息:

在处理时发现错误; header

我的问题是我不知道如何在使用 Web 服务的 VB.NET 客户端应用程序中使用它。我这样做可能完全错误。任何有关此主题的指导将不胜感激。

谢谢你,

-弗林尼

I am implementing a VB.NET desktop application which consumes a web service.

The web service implemented in Java and I currently using Tomcat on my localhost to host the web service.

The web service requires secure communication with the client and so I have followed instructions that outlined how to use Java's keytool.exe to create two .jks keystores (one for the client and one for the server) and then create two .cer certificates (one for the client and one for the server)

I have placed the keystores and certificates generate into the directory where the web service is expecting them (according to the instructions)

I have installed the certificates into TrustedPeople and have attempted to use the certificate by setting the ClientCredentials.ClientCertificates property like this:

myServiceProxy.ClientCredentials.ClientCertificate.SetCertificate(storeLocation.CurrentUser, StoreName.TrustedPeople, X509FindType.FindByIssuerName, "name")

I keep getting the following error message when I try to call any method:

An error was discovered processing the <wsse:Security> header

My problem is that I don't know how to use this in the VB.NET client application that is consuming the web service. I could be doing this completely wrong. Any guidance on this topic would be greatly appreciated.

Thank you,

-Frinny

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

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

发布评论

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

评论(2

唯憾梦倾城 2024-10-01 04:38:56

虽然我已经 10 年没有编写 VB 代码了,但这应该可以帮助您入门:http:// /www.example-code.com/vbdotnet/ssl_client_certificate.asp

特别是这看起来像是正在加载包含证书的文件:
certStore.LoadPfxFile("chilkat_secret.pfx","secret")

这会提取证书并将其用于连接:

Dim cert As Chilkat.Cert
cert = certStore.FindCertBySubjectCN("Chilkat Software, Inc.")
If (cert Is Nothing ) Then
    MsgBox(certStore.LastErrorText)
    Exit Sub
End If


socket.SetSslClientCert(cert)

While I haven't coded VB for 10 years, this should get you started: http://www.example-code.com/vbdotnet/ssl_client_certificate.asp

especially this looks like it is loading the file containing the certificate:
certStore.LoadPfxFile("chilkat_secret.pfx","secret")

and this extracts the certificate and uses it for the connection:

Dim cert As Chilkat.Cert
cert = certStore.FindCertBySubjectCN("Chilkat Software, Inc.")
If (cert Is Nothing ) Then
    MsgBox(certStore.LastErrorText)
    Exit Sub
End If


socket.SetSslClientCert(cert)
家住魔仙堡 2024-10-01 04:38:56

当我必须使用证书和 WS 时,我也遇到了很多问题。 使用证书 MMC 并验证:

  • 您是否将证书放置在正确的位置地方。请注意,有一个 CurrentUser 存储、Machine Store 等。请确保根据您的代码将证书放入正确的存储中。
  • 哪个用户正在运行您的应用程序?证书是否位于其存储中?该证书必须对用户可见。
  • 打开证书并确保其受信任(如果不受信任,您将看到警告)。您可能需要将 CA 的证书放入受信任的证书颁发机构存储中。
  • 确保您在每一方使用的算法得到另一方的支持。
  • 请注意,您正在按颁发者名称 X509FindType.FindByIssuerName, "name" 查找证书,打开证书,确保颁发者名称匹配(我猜不是,因为它看起来像是从示例中复制和粘贴)。

如果所有这些都失败,请尝试尝试证书位置(我隐约记得能够使用一个位置的证书而不是另一个位置的证书的一些问题)以及用于搜索证书的属性。

另外,既然你问了有关证书的问题,我就回答了有关证书的问题。最好检查是否存在内部异常并查看 - 这可能是另一个问题。

When I had to work with certificates and WS, I had lots of issues with the them too. Use the certificates MMC and verify:

  • That you placed the certificate in the correct place. Note that there is a CurrentUser store, Machine Store etc. Make sure you put the certificate in the correct one according to your code.
  • Which user is running your application? Is the certificate located in it's store? The certificate must be visible to the user.
  • Open the certificate and make sure it is trusted (you will see a warning if not). You may need to put your CA's certificate in Trusted Certification Authorities store.
  • Make sure that the algorithms you use on each side are supported by the other side.
  • Note that you are looking for the certificate by issuer name X509FindType.FindByIssuerName, "name" open the certificate, make sure the issuer name matches (I guess not since it seems like copy&paste from example).

If all of this fails, try to experiment with the certificate location (I vaguely remember some issue with being able to use certificates from one location and not the other), and with the property you use to search for the certificates.

Plus, since you asked about certificates I answered about certificates. It's a good idea to check if there's an inner exception and see - it may be another problem.

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