簡體   English   中英

通過證書具有運輸安全性的WCF

[英]WCF with transport security via certificates

我想使用客戶端證書來保護WCF服務,即僅應允許來自特定根CA的客戶端證書來調用我的服務。

為了進行測試,我先創建了一個沒有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>

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

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

如果我切換到消息安全性(而不是傳輸安全性)並切換到HTTP協議,那么一切似乎都可以正常工作。 所以我想我錯過了一些啟用HTTPS的步驟嗎?! 如何使運輸安全工作?

您的證書配置不正確。請按照以下步驟操作

復制證書的指紋並在提升模式下從命令提示符運行以下命令

   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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM