zoukankan      html  css  js  c++  java
  • The certificate that was used has a trust chain that cannot be verified问题

    今天调用wcf程序的时候发现证书有问题。报的错误如下 The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider 查找证书发现是自己的证书没有问题,服务器也是没有问题。 后来发现只要在客户端的代码添加一句话就好了。  ServiceReference1.TransportServiceClient proxy = new WCFTest2.ServiceReference1.TransportServiceClient();

     proxy.ClientCredentials.UserName.UserName = "xxxx";

     proxy.ClientCredentials.UserName.Password = "xxxx";  

    proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;  //重点

    原因是我的证书放的位置不对,X509CertificateValidationMode有以下几种方式  

    None 未执行任何证书验证。  

    PeerTrust 如果证书位于被信任的人的存储区中,则有效。  

    ChainTrust 如果该链在受信任的根存储区生成证书颁发机构,则证书有效。  

    PeerOrChainTrust 如果证书位于被信任的人的存储区或该链在受信任的根存储区生成证书颁发机构,则证书有效。  

    Custom 用户必须插入自定义 X509CertificateValidator 以验证证书。

    那这个配置主要是在服务器端的配置服务器上。

    服务器的web.config配置

    <clientCertificate >

                  <certificate findValue="XuanhunClient"

                                storeLocation="CurrentUser"

                                storeName="My"

                                x509FindType="FindBySubjectName"/>

         <authentication certificateValidationMode="None" trustedStoreLocation="CurrentUser"  />

                </clientCertificate>

    服务器里面是用的none,那么客户端也需要用None.这里需要保持一致。

    但针对https里面加证书了,因为这个证书是在iis的站点增加的。所以不需要增加。

    就只要用  

    ServiceReference1.TransportServiceClient proxy = new WCFTest2.ServiceReference1.TransportServiceClient();  

    proxy.ClientCredentials.UserName.UserName = "xxxx";

     proxy.ClientCredentials.UserName.Password = "xxxx";  

    Util.SetCertificatePolicy();

    就好了。

  • 相关阅读:
    Windows7 64位 安装mysql
    汉诺塔(hanoi)
    大数据时代,Python是最好的语言!
    本地项目上传到github
    函数去抖(debounce)与 函数节流(throttle)
    vue项目出现的错误汇总
    vue-cli + webpack自动生成项目
    webpack和gulp
    前端开发利器之静态服务器
    vue开发知识点汇总
  • 原文地址:https://www.cnblogs.com/BinZeng/p/4123510.html
Copyright © 2011-2022 走看看