我想檢查我的WCF服務中的客戶端證書。WCF服務中的自定義證書驗證
我的目標是隻允許具有特定指紋的證書的客戶能夠與我的服務進行通信。
我的WCF服務託管在IIS中,我使用basicHttpBinding和安全模式=「傳輸」憑證類型「證書」。 IIS需要客戶端證書來與服務進行通信。
在此先感謝您的幫助。
UPDATE: 我的配置:
<basicHttpBinding>
<binding
name="testBinding"
maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
行爲:
<serviceBehaviors>
<behavior name="SomeServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="Custom" customCertificateValidatorType="SomeService.CustomCertificateValidator,SomeService" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
服務配置:
<service
behaviorConfiguration="SomeServiceBehavior"
name="SomeService">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="testBinding"
contract="ISomeService">
</endpoint>
</service>
而對於測試的目的,我實現這種方式驗證:
public class CustomCertificateValidator : X509CertificateValidator
{
public override void Validate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate)
{
throw new SecurityTokenValidationException("TEST Certificate was not issued by a trusted issuer TEST");
}
}
而這是行不通的。我可以使用任何有效的證書連接到我的服務。
我試圖在clientCertificate中添加自定義驗證器,但它不起作用。它似乎設計用於驗證服務將在雙工模式下使用的客戶端證書。我需要驗證傳入證書(客戶端發送的證書)。你在這種情況下嘗試過這個選項嗎? – empi 2009-10-13 12:54:22
這可以在客戶端或服務端工作,並用於驗證傳入消息證書。 – Maurice 2009-10-13 12:57:12
確保將其添加到中,以驗證服務中的客戶端是否是您想要的。 僅用於客戶端來驗證服務。 –
Maurice
2009-10-13 13:00:30