The certificate that was used has a trust chain that cannot be verified问题

解决WCF证书验证问题
本文介绍了在调用WCF服务时遇到证书验证错误的具体解决方案。通过调整客户端代码中的证书验证模式为None,并确保服务器端配置一致,可以解决证书无法验证的问题。此外,对于使用HTTPS的场景,文中也给出了相应的配置建议。

今天调用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();

就好了。

 

转载于:https://www.cnblogs.com/BinZeng/p/4123510.html

Here is one possible implementation of the `make_joint` function in Python: ```python def make_joint(withdraw_fn, password, new_password): # Define a counter to keep track of the number of incorrect password attempts incorrect_passwords = [0] # Define a helper function to check the password and call the original withdraw function def withdraw(amount, entered_password): if entered_password not in [password, new_password]: incorrect_passwords[0] += 1 if incorrect_passwords[0] >= 3: withdraw_fn('LOCKED') return 'INCORRECT PASSWORD' else: return withdraw_fn(amount, password) # Call the original withdraw function with the correct password to ensure it is valid if withdraw(0, password) == 'INCORRECT PASSWORD': return 'INVALID PASSWORD' # Return the new withdraw function that can be used with either password return withdraw ``` The `make_joint` function takes in a withdraw function, a password, and a new password, and it returns a new withdraw function that can be used with either password. The function keeps track of the number of incorrect password attempts using a list with one value, `incorrect_passwords`, which is initialized to `[0]`. If the incorrect password is entered three times, the account is locked by calling the original withdraw function with the `'LOCKED'` argument. The `withdraw` helper function checks the entered password against the original password and the new password. If the entered password is incorrect, it increments the `incorrect_passwords` counter and returns `'INCORRECT PASSWORD'`. If the counter reaches 3, the function locks the account by calling the original withdraw function with the `'LOCKED'` argument. Otherwise, the function calls the original withdraw function with the requested amount and the original password. Finally, the function calls the original withdraw function with 0 and the original password to ensure that the provided password is valid. If it is not, the function returns `'INVALID PASSWORD'`. Otherwise, it returns the `withdraw` helper function that can be used with either password.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值