[英]Client certificate authentication WCF
所以我完全迷失了證書。 我在網上搜索了有關此問題的解決方案和教程,但沒有任何東西可以真正幫助我。 我想做的是為WCF客戶端-服務器應用程序同時進行服務器和客戶端證書驗證。 該應用程序托管在IIS上。 我希望它在我的開發計算機(服務器是本地主機)上並在測試中(即時消息客戶端和服務器是Windows服務器)。
我現在的配置是:
客戶:
<behaviors>
<endpointBehaviors>
<behavior name="myBehaviorConfig">
<clientCredentials>
<clientCertificate findValue="CN=MyTestClientCertificate"
storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyBindingConfig">
<security mode="TransportWithMessageCredential">
<transport realm=""/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/Service.Calculator.svc"
binding="wsHttpBinding"
bindingConfiguration="MyBindingConfig"
behaviorConfiguration="MyBehaviorConfig"
contract="Service.ICalculator"
name="ICalculatorServiceEndpoint">
<identity>
<servicePrincipalName value="host"/>
</identity>
</endpoint>
</client>
服務器:
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceCredentials>
<serviceCertificate findValue="CN=MyTestRootCA"
storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName"/>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"/>
</clientCertificate>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<unity operationContextEnabled="true"
instanceContextEnabled="true"
contextChannelEnabled="true"
serviceHostBaseEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyBinding">
<security mode="TransportWithMessageCredential">
<transport realm=""/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service.Calculator"
behaviorConfiguration="myBehavior">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="MyBinding"
contract="Service.ICalculator" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"
name="CalculatorServiceMex" />
</service>
</services>
“ CN = MyTestRootCA”是“授權”證書,是“正在創建”證書,我將其放在localComputer以及本地計算機的個人目錄中的受信任的根證書中。 它是客戶端證書“ CN = MyTestClientCertificate”的頒發者。
一些事情..
我知道客戶端證書應該在“ MMC”中的CurretUser目錄中,但是當它存在時,我有一個例外,即應用程序找不到證書。 我嘗試通過“ FindBySubjectDistinguishedName”和“ FindByThumbprint”來定位它,兩次都是相同的例外,“無法以給定的條件找到證書……”,所以我將其放在LocalMachine中,並且很好。 有人知道為什么它不起作用嗎?
我在使用此= \\時遇到了很多問題和異常,當前的問題是:“ X.509證書中未提供私鑰”熟悉此異常並知道如何解決的人嗎?
非常感謝您的回答,我現在坐在這幾天上
您的配置文件未指定clientCertificate storeLocation值,因此客戶端證書必須位於LocalMachine存儲中,這是storeLocation的默認值。
考慮以下來自msdn的示例,該示例設置了客戶端證書存儲位置:
<clientCertificate>
<certificate
findValue="www.cohowinery.com"
storeLocation="CurrentUser"
storeName="TrustedPeople"
x509FindType="FindByIssuerName" />
<authentication …
注意:另一個錯誤“私鑰未在X.509證書中出現”,很可能引發此錯誤,因為您的證書沒有關聯的私鑰,或者您的進程的用戶上下文沒有訪問私鑰的權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.