503错误消耗第三部分SOAP Web服务使用TLS 1.2和客户端证书身份验证与WCF
我有一个问题,消耗Soap Web服务(瓦特/ att。)和MTOM需要客户端证书身份验证(相互?)。503错误消耗第三部分SOAP Web服务使用TLS 1.2和客户端证书身份验证与WCF
之前写的东西我已经试过我告诉你我才能收到客户端证书做:
- 我产生RSA密钥与
openssl command openssl genrssa -out mykey.key 2048
- 有了这个关键的我“已经产生了CSR:
openssl req -new -key mykey.key -out mycsr.csr
- 我才能收到客户端证书发送此CSR到Web服务业主,他们给了我一个签名CERTI ficate: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: 'The HTTP request was forbidden with client authentication scheme 'Anonymous'.'
Internal Exception: WebException: Remote Server Error: (403) Forbidden
下一页我使用招和Wireshark分析交通我发现,在客户端和服务器之间的TLS握手期间,客户端不会将证书发送到服务器。
现在我也不明白为什么,即使我添加的证书到客户端凭证,它不发送到目的地。
很多读数之后,我发现我失踪:
- 客户端证书.CER不包含私钥!
我所做的:
-
我转换.CER文件PEM格式使用下面的命令:
OpenSSL的X509 -inform DER -in ClientCert.cer退房手续ClientCert.pem
-
我创建一个.pfx证书与我的私有密钥:
OpenSSL的PKCS12 -export -in ClientCert.p em -inkey mykey.key -out ClientCert。pfx
然后安装.pfx证书一切就像一个魅力。
我希望有人发现它有用。