【发布时间】:2013-12-10 13:00:21
【问题描述】:
我有自托管的 WCF REST 服务。我想使用 SSL 并从浏览器使用服务。我使用this 博客文章作为初始点。基本上如下步骤:
-
创建和注册证书
makecert.exe -sk RootCA -sky 签名 -pe -n CN=localhost -r -sr LocalMachine -ss Root MyCA.cer
makecert.exe -sk 服务器 -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer
-
将证书绑定到端口
netsh http 添加 urlacl url="https://+:8015/" user=Domain\User
netsh http 添加 sslcert ipport=0.0.0.0:8015 certash=somehash appid={601A2F31-E812-479A-B5EA-1B78A9683EE0}
然后我尝试从 chrome 调用一些方法......但没有任何反应。
这是我的 WCF 配置:
<bindings>
<webHttpBinding>
<binding name="NewBinding0">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Security" name="Microsoft.Samples.BasicHttpService.Service">
<endpoint address="https://localhost:8015" binding="webHttpBinding"
bindingConfiguration="NewBinding0" name="test" contract="Microsoft.Samples.BasicHttpService.IService"
kind="webHttpEndpoint" endpointConfiguration="" />
<endpoint address="https://localhost:8016" binding="mexHttpsBinding"
bindingConfiguration="" name="MEX" contract="IMetadataExchange"
kind="mexEndpoint" endpointConfiguration="mex" />
</service>
</services>
WCF 跟踪日志显示警告:需要客户端证书。在请求中未找到证书。
使用chrome://net-internals/#events 时显示错误:
SSL_CERTIFICATES_RECEIVED
--> certificates =
-----BEGIN CERTIFICATE-----
base64 certificate
-----END CERTIFICATE-----
t=1386677875080 [st= 4] SOCKET_BYTES_SENT
--> byte_count = 59
t=1386677875080 [st= 4] -SSL_CONNECT
... (send/receive part)...
t=1386677875123 [st=47] SSL_CLIENT_CERT_REQUESTED
t=1386677875123 [st=47] SSL_READ_ERROR
--> **net_error = -110 (ERR_SSL_CLIENT_AUTH_CERT_NEEDED)**
...
这是提琴手所说的:
Tunel to localhost:8015 (Standart SSL handshaking)
**Request**
CONNECT localhost:8015 HTTP/1.1
Host: localhost:8015
....
A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.
....
带有服务器证书公共数据的标准响应。
在握手后浏览器发送 GET 请求,根本没有任何关于证书或 SSL 的信息,因此 403 Forbidden。
有趣的是,我第一次这样做时,我可以使用 ClientCertificate 设置 Fiddler 并使用 Fiddler 作为代理一切正常(仍然从没有 Fiddler 的浏览器直接调用不起作用)。现在经过一些操作(删除 sslcert、创建新证书等),我什至打破了 Fiddler 的这种行为,所以没有任何效果——不管有没有 Fiddler...
1) 那么,我错过了哪些步骤?我应该为浏览器创建或导入证书吗?
2)谁负责建立SSL连接,我的意思是谁用服务器证书响应?...我猜是操作系统部分(WinInet.dll)。这绝对不是我的服务,因为我没有为服务或客户端指定任何证书信息。
3) 我应该在 serviceCredentials 中指定 serviceCertificate 还是 clientCertificate?
提前致谢!
【问题讨论】:
标签: wcf https ssl-certificate wcf-security fiddler