Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF服务中的自定义证书验证_Wcf_Security_Iis_Certificate - Fatal编程技术网

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

WCF服务中的自定义证书验证,wcf,security,iis,certificate,Wcf,Security,Iis,Certificate,我想检查WCF服务中的客户端证书 我的目标是只允许具有特定指纹证书的客户端能够与我的服务通信 我的WCF服务托管在IIS中,我使用的是带有凭证类型“Certificate”的basicHttpBinding和security mode=“transport”。IIS需要客户端证书才能与服务通信 提前谢谢你的帮助 更新: 我的配置: <basicHttpBinding> <binding name="testBinding" maxR

我想检查WCF服务中的客户端证书

我的目标是只允许具有特定指纹证书的客户端能够与我的服务通信

我的WCF服务托管在IIS中,我使用的是带有凭证类型“Certificate”的basicHttpBinding和security mode=“transport”。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>
<service 
               behaviorConfiguration="SomeServiceBehavior"
               name="SomeService">
        <endpoint 
                  address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="testBinding"
                  contract="ISomeService">
        </endpoint>
      </service>

这不管用。我可以使用任何有效的证书连接到我的服务。

您可以创建一个从X509CertificateValidator派生的类,并使用它对传入的证书进行自定义验证。如果出于某种原因希望验证失败,请抛出SecurityTokenValidationException

将certificateValidationMode设置为Custom,并在配置文件的clientCertificate服务行为部分指定验证器


我认为无论如何都不需要“自定义证书验证”和“传输安全性”。它只适用于“消息安全性”

是的,您可以在安全设置为传输的情况下使用basicHttpBinding,并且需要在IIS中连接到ServiceHost创建-请参阅。 如果您创建自定义配置节来定义验证条件列表,则应该能够验证指纹值、证书或任何其他数据


实现上述所有功能的示例代码可从下载的代码中获得

我试图在clientCertificate中添加自定义验证器,但它不起作用。它似乎是为了验证服务将在双工模式下使用的客户端证书而设计的。我需要验证传入的证书(客户端正在发送的证书)。您在此场景中尝试过此选项吗?它可以在客户端或服务端工作,用于验证传入消息证书。我已添加了配置。您还需要更多信息吗?刚才注意到您使用的是传输,而不是消息级安全。要使其正常工作,您需要使用消息级安全性。您可以使用TransportWithMessageCredential作为安全模式。这使用了HTTPS与消息安全性的组合。不正确。我在传输模式下运行自定义证书验证
<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");
        }
    }