代码之家  ›  专栏  ›  技术社区  ›  Hudgi

根据验证过程,远程证书无效

  •  8
  • Hudgi  · 技术社区  · 15 年前

    我正在开发一个WCF服务(NetTcpBinding),它在没有安全性的情况下可以正常工作。我们从DigiCert购买了一个证书,并将其安装在服务器上,并配置了DigicertUtil.exe. 也安装在测试客户机上。

    打开安全性,我可以从我的开发人员PC连接到它没有问题。

    服务器配置:

       binding.Security.Mode = SecurityMode.Transport;
       binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
       binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
       ServerHost.Credentials.ServiceCertificate.SetCertificate(
                  StoreLocation.LocalMachine,
                  StoreName.My,
                  X509FindType.FindBySubjectName,
                  Properties.Settings.Default.CertificateName);
    

    客户端配置:

     <binding name="EndPointTCP" closeTimeout="00:01:00" openTimeout="00:01:00"
                  receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                  hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="1610612736"
                  maxReceivedMessageSize="1610612736">
                  <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                  <reliableSession ordered="false" inactivityTimeout="00:10:00" enabled="false" />
                  <security mode="Transport">
                    <transport clientCredentialType="Certificate"  protectionLevel="EncryptAndSign"/>
                  </security>
                </binding>
    
        <behaviors>
              <endpointBehaviors>
                <behavior name="behavior_ServerService">
                  <clientCredentials>
                    <clientCertificate findValue="*.domain.com"
                              storeLocation="LocalMachine"
                              storeName="My"
                              x509FindType="FindBySubjectName" />
                  </clientCredentials>
                </behavior>
              </endpointBehaviors>
            </behaviors>
    
    <client>
      <endpoint address="net.tcp://clients.domain.com:10001/Server/ServerService"
        binding="netTcpBinding" bindingConfiguration="EndPointTCP" contract="ServerServiceReference.IServerWS"
        name="EndPointTCP" behaviorConfiguration="behavior_ServerService">
        <identity>
          <dns value="*.domain.com" />
        </identity>
      </endpoint>
    </client>  
    

    从任何其他计算机尝试时,我在客户端上收到以下错误:

    套接字连接已中止。这可能是由于处理消息时出错、远程主机超过接收超时或底层网络资源问题造成的。本地套接字超时为“00:00:59.9840000”。

    远程主机已强制关闭现有连接

    服务器上的跟踪日志显示:

    根据验证过程,远程证书无效。

    这很奇怪,因为我在服务器和客户端上使用相同的证书(更不用说它运行良好的dev pc了……)

    即使我设置了

    ServerHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
    

    ServiceClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
    

    在客户身上。

    谁能告诉我怎么做才对吗?当然,我不想使用诸如验证回调总是返回true或上述未验证模式之类的解决方法。

    任何帮助都将不胜感激。只有解决这个“小”问题才能释放…:(

    提前多谢了!

    1 回复  |  直到 15 年前
        1
  •  10
  •   insipid    15 年前

    您是有意让客户机通过SSL向服务器进行身份验证,还是只是试图建立客户机对证书颁发机构的信任?

        2
  •  1
  •   Kurubaran    6 年前

    如果要忽略自签名或无效证书,请在客户端调用请求之前尝试此代码段。

    ServicePointManager.ServerCertificateValidationCallback = delegate
    (object s, X509Certificate certificate, X509Chain chain,
    SslPolicyErrors sslPolicyErrors) { return true; };