【问题标题】:503 error consuming thirdy part Soap webservice using TLS 1.2 and client certificate authentication with WCF使用 TLS 1.2 和使用 WCF 的客户端证书身份验证使用第三方 Soap Web 服务时出现 503 错误
【发布时间】:2017-10-04 07:39:11
【问题描述】:

我在使用需要客户端证书身份验证(相互?)的 Soap Web 服务(w/att.)和 MTOM 时遇到问题。

在编写我已经尝试过的内容之前,我会向您展示我为获得客户证书所做的工作:

  1. 我用openssl command openssl genrssa -out mykey.key 2048 生成了一个RSA 密钥
  2. 有了这个密钥,我生成了一个CSRopenssl req -new -key mykey.key -out mycsr.csr
  3. 我已将此 CSR 发送给 Web 服务所有者以接收 客户端证书,他们给了我一个签名证书:certificate.cer

现在我已经获得了我的客户端证书,我已将其添加到我的证书存储区中的受信任的根证书颁发机构下。

现在是代码:

首先,我在 Visual Studio 中创建了一个测试项目,并使用服务的 WSDL 添加了一个服务引用。

然后我写了几行代码:

' Setting TLS 1.2 protocol '
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ServicePointManager.ServerCertificateValidationCallback = Function(sender1, certificate, chain, sslPolicyErrors)
                                                              Return True
                                                          End Function

'Creating endpoint and binding'
Dim endpoint As EndpointAddress = New EndpointAddress("https://myWebService.it/service-page")
Dim sslBinding As BasicHttpBinding = New BasicHttpBinding(BasicHttpSecurityMode.Transport)

'Setting CredentialType = Certificate'
sslBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate

'Getting the client certificate from the store'
Dim coll = New X509Store(StoreName.My, StoreLocation.CurrentUser)
coll.Open(OpenFlags.ReadOnly)
Dim cert = coll.Certificates.Find(X509FindType.FindByThumbprint, "76DB1454D4B25ACEAF2BAE465C310E3119278792", True)

'Creating the service'
Dim svc As SdITrasmissioneFileClient = New SdITrasmissioneFileClient(sslBinding, endpoint)

'Setting the certificate inside client credentials'
svc.ClientCredentials.ClientCertificate.Certificate = cert(0)

svc.Open()

'Calling the service'
Dim resp As RispostaEsito_Type = svc.Esito(New Esito_Type() With {.IDFile = "4454555"})

svc.Close()

对我来说看起来很简单,但是当我执行我的代码时,我得到了一个

System.ServiceModel.Security.MessageSecurityException: 'HTTP 客户端身份验证方案“匿名”禁止请求。

内部异常:WebException:远程服务器错误:(403)禁止

接下来我使用 Fiddler 和 Wireshark 分析流量,我发现在客户端和服务器之间的 TLS 握手期间,客户端不会将证书发送到服务器。

现在我不明白为什么,即使我将证书添加到客户端凭据,它也没有发送到目的地

【问题讨论】:

    标签: vb.net web-services wcf soap tls1.2


    【解决方案1】:

    经过大量阅读,我发现了我所缺少的:

    • 客户端证书 .cer 不包含私钥!

    我做了什么:

    1. 我使用以下命令将 .cer 文件转换为 PEM 格式:

      openssl x509 -inform der -in ClientCert.cer -out ClientCert.pem

    2. 我用我的私钥创建了一个 .pfx 证书:

      openssl pkcs12 -export -in ClientCert.pem -inkey mykey.key -out ClientCert.pfx

    然后安装 .pfx 证书,一切都很顺利。

    我希望有人觉得它有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 2011-03-07
      • 1970-01-01
      • 2012-04-07
      相关资源
      最近更新 更多