【发布时间】:2012-01-05 02:03:44
【问题描述】:
问题:
我无法在 windows7 上使用 C#.net 连接到启用 TLS 的 Web 服务端点。
Fiddler 请求和响应是:
请求:-
连接我的端点:9443 HTTP/1.1
主机:我的端点:9443
代理连接:保持活动"
这是回复:-
HTTP/1.1 502 连接失败
连接:关闭
时间戳:18:54:29.909
HTTPS 连接失败。
*System.Net.Sockets.SocketException:
无法建立连接,因为目标机器主动拒绝它:9443
在 Fiddler.ServerChatter.CreateConnectedSocket(IPAddress [] arrDestIPs,Int32 iPort,会话 _oSession)*
*在 Fiddler.Session._handleHTTPSConnect()*"
我的客户端是一个 .net 桌面/控制台应用程序。我不确信我已正确完成客户端 TLS/证书设置/配置。我还有一些未回答的问题。
我做了以下事情:
我有一个 Internet Web 服务的“启用 TLS”端点。为了正常沟通,我提供了 4 样东西:
1) ca.cert.pem : CA 的公共证书
2) myname.cert.pem : 我的公共证书
3) myname.key.pem : 我的私钥
4)密码:“我的密码”
我还收到了证书请求 (.csr) 和用于生成我的证书的参数。
在阅读了与 TLS 相关的内容后,我认为这是我需要做的:
step1) 使用 Openssl 将 ca.cert.pem 转换为 .cer 文件,并将其添加/导入到本地计算机的“受信任的根证书颁发机构”,以便从现在开始信任 CA。
step2) 将 myname.cert.pem 和 myname.key.pem 合并到一个 .pkcs12 中
“openssl pkcs12 -export -out keystore.pkcs12 -in myname.cert.pem -inkey myname.key.pem”。这要求我使用“mypassword”的密码。
step3) 将 keystore.pkcs12 添加到“个人”证书(这里它要求输入密码,我提供“mypassword”)
第三步添加的证书指纹为“fef4ab753a11a30a6c4342e63e00f237ef0818c1”
现在,这是我对 app.config 所做的更改:
<bindings>
<wsHttpBinding>
<binding name="My_HTTPS_Endpoint_Binding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://myendpoint:9443/myService"
binding="wsHttpBinding" bindingConfiguration="My_HTTPS_Endpoint_Binding"
contract="MyNs.myClass" name="My_HTTPS_Endpoint" behaviorConfiguration="clientBehaviour" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="clientBehaviour">
<clientCredentials>
<clientCertificate findValue="fef4ab753a11a30a6c4342e63e00f237ef0818c1"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindByThumbprint" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
所以我似乎错过了任何关键步骤?我有一些知识空白:
1)我的理解是我拥有的公钥和私钥组合仅对从服务器到客户端的通信有用。客户端到服务器的消息加密如何工作?我的客户端在哪里从服务器获取需要用于消息加密的公钥?
2) 是否需要在配置中的某处提供密码?只是猜测..
【问题讨论】:
标签: c# wcf certificate wcf-security x509certificate