繁体   English   中英

WCF服务中的自定义证书验证

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM