2014-01-22 117 views
0

我想使用客戶端證書來保護我的WCF服務,即只允許來自特定根CA的客戶端證書調用我的服務。通過證書傳輸安全的WCF

出於測試目的,我先創建了一個沒有CA的單個客戶端證書。我在服務器的證書存儲中註冊了客戶證書(在當前用戶 - >可信任人員下)。

在VS2013內我已經在WCF服務項目上啓用了SSL,以便擁有HTTPS端點。我已經適應了以下服務Web.config文件如下:

<serviceCredentials> 
    <clientCertificate> 
    <authentication certificateValidationMode="PeerTrust"/> 
    </clientCertificate> 
    ... 
</serviceCredentials> 

<wsHttpBinding> 
    <binding name="wsHttpEndpointBinding"> 
    <security mode="Transport"> 
    <transport clientCredentialType="Certificate"/> 
    </security> 
    </binding> 
</wsHttpBinding> 

而且我已經適應我的客戶端應用程序的App.config文件如下:

<clientCredentials> 
    <clientCertificate findValue="Client" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople" /> 
    <serviceCertificate> 
    <authentication certificateValidationMode="PeerTrust"/> 
    </serviceCertificate> 
</clientCredentials> 

<wsHttpBinding> 
    <binding name="WSHttpBinding_IService1"> 
    <security mode="Transport"> 
     <transport clientCredentialType="Certificate"/> 
    </security> 
    </binding> 
</wsHttpBinding> 

然而,這不起作用,我收到以下異常消息:

將HTTP請求設置爲https://localhost:44300/Service1.svc時發生錯誤。這可能是由於在HTTPS情況下服務器證書未使用HTTP.SYS正確配置。這也可能是由於客戶端和服務器之間的安全綁定不匹配造成的。

如果我切換到消息安全性(而不是傳輸安全性)並切換到HTTP協議,一切似乎工作得很好。所以我想我錯過了一些啓用HTTPS的步驟?!如何使交通安全工作?下面

回答

0

您的證書沒有被配置properly.Follow步驟

複製證書的指紋及以下命令從命令提示升高模式下運行

netsh http add sslcert [Ipaddress:port] certhash=[thumbprint of certifcate] 
appid={unique id for application.you can use GUID for this] 


[Ipaddress:port] Ipaddress and port 
[thumbprint of certifcate]: thumbprint of certificate without spaces 
appid :unique id you can use guid 

如何從命令提示生成GUID

打開Visual Studio命令提示和下方命令運行

c:> uuidgen

+0

感謝您的信息,如果我使用這個工具,我會得到一個簡單的錯誤「參數不正確」。 Thumprint沒有空格,我使用了一個新的GUID(包括破折號)作爲appId。 –

+0

GUID應該在大括號 –

+0

我有'的netsh HTTP添加的sslcert ipport =本地主機:44300 certhas = 的appid = {22d80ae9-b4f7-4c41-B201-a34e2790b41e}' –