【问题标题】:Disabling X.509 certificate validation in .NET with WCF service使用 WCF 服务在 .NET 中禁用 X.509 证书验证
【发布时间】:2014-05-06 05:54:27
【问题描述】:

我正在尝试在 WCF 服务中设置消息安全性并在此过程中禁用 X.509 证书验证。我只想使用用户名和密码验证客户端,根本不验证服务器。至少现在是这样。

这里参考第一个答案:

How do I tell WCF to skip verification of the certificate?

如何在客户端以编程方式实现以下目标?

<behavior name="DisableServiceCertificateValidation">
    <clientCredentials>
        <serviceCertificate>
            <authentication certificateValidationMode="Custom"
            customCertificateValidatorType="MyCertificateValidator, Client"
            revocationMode="NoCheck" />
         </serviceCertificate>
    </clientCredentials>
</behavior>

我有这个:

With myServiceClient.ClientCredentials
    .UserName.UserName = "username"
    .UserName.Password = "password"
    .ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom
    .ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck
End With

我不知道如何设置“customCertificateValidatorType”以及如何将其连接到 MyCertificateValidator 类。

这是否绕过了客户端证书、服务器证书或两者的要求?

这是我的服务器 web.config 文件。

<?xml version="1.0"?>
<configuration>

  <system.web>
    <customErrors mode="Off"/>
    <trust level="Full"/>
    <compilation debug="true"/>
  </system.web>

  <system.serviceModel>

     <services>

      <service name="HelloWorldService.HelloWorldService" behaviorConfiguration="BehaviourMessageSecurity">

        <endpoint address ="" binding="wsHttpBinding" contract="HelloWorld.IHelloWorldService" bindingConfiguration="BindingMessageSecurity"/>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

        <host>
          <baseAddresses>
            <add baseAddress="http://www.example.com/HelloWorldService.svc"/>
          </baseAddresses>
        </host>

      </service>

    </services>

    <behaviors>

      <serviceBehaviors>

        <behavior name="BehaviourMessageSecurity">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
             customUserNamePasswordValidatorType="HelloWorldService.ServiceAuthenticator, HelloWorldService" />
            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName"
                                storeLocation="LocalMachine" storeName="My" />
          </serviceCredentials>
        </behavior>

       </serviceBehaviors>

    </behaviors>

    <bindings>
      <wsHttpBinding>

        <binding name="BindingMessageSecurity">
          <security mode="Message">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>

      </wsHttpBinding>
    </bindings>

  </system.serviceModel>

  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

    标签: c# vb.net wcf


    【解决方案1】:

    Czustom 意味着您编写自己的验证方法。如果您根本不想检查证书,请使用无:

    .ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None
    

    【讨论】:

    • 我在该线程中的“禁用 .NET 中的 X.509 证书验证”标题下尝试了该解决方案以及其他解决方案,但这也不起作用。我不介意我是否提供一个始终返回 true 的重写自定义验证器,或者我是否根本不使用验证。我只是想让这个工作。
    • “不起作用”到底是什么意思?您收到什么错误消息?
    • 例外是“请求的服务,'example.com/HelloWorldService.svc' 无法激活。有关详细信息,请参阅服务器的诊断跟踪日志。”没有内在的例外。该服务运行良好,没有安全性。我唯一更改的是上面的客户端凭据和安全模式(设置为用户名)。绑定和行为标签在客户端和服务器之间匹配。我在我的本地机器上使用服务器和客户端都使用了这个使用“make cert”制作的虚拟证书。
    • 现在我正在尝试部署到远程服务器。我感觉此错误与无法在服务器上找到主题名称为“localhost”(在服务的 web.config 服务证书标签中指定)的证书或证书无效有关。换句话说,它没有绕过证书检查。
    • 您能编辑您的问题并发布您的服务器端 app.config 吗?
    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多