[英]Custom certificate validation in WCF service
我想在我的WCF服務中檢查客戶端證書。
我的目標是只允許具有特定指紋證書的客戶能夠與我的服務進行通信。
我的WCF服務托管在IIS中,我使用basicHttpBinding和安全模式=“transport”,憑據類型為“Certificate”。 IIS需要客戶端證書才能與服務進行通信。
在此先感謝您的幫助。
更新:我的配置:
<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");
}
}
這不起作用。 我可以使用任何有效證書連接到我的服務。
您可以創建一個派生自X509CertificateValidator的類,並使用它來對傳入證書進行自定義驗證。 如果由於某種原因想要驗證失敗,則拋出SecurityTokenValidationException。
將certificateValidationMode設置為Custom,並在配置文件的clientCertificate服務行為部分中指定驗證器。
我認為無論如何都沒有“自定義證書驗證”和“運輸安全”。 它只適用於'Message Security'。
是的,您可以將basicHttpBinding與安全性設置為Transport,並且您需要掛鈎到IIS中的ServiceHost創建 - 請參閱自定義服務主機 。 如果您創建自定義配置部分以定義驗證標准列表,則應該能夠驗證指紋值,證書或任何其他數據。
在本CodeProject文章的代碼下載中提供了實現上述所有內容的示例代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.