我想检查我的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