c# – WCF证书链,以编程方式验证
我试图以编程方式使用证书,而不是使用商店.我正在使用文件名和密码创建X509Certificate2.
当我手动将根证书添加到受信任人员中的证书存储区时,此工作正常.但是,我宁愿不必在每次部署时都这样做 – 我宁愿以编程方式处理它. 当我从证书存储中删除根证书时,我得到一个例外. 我读过的所有内容似乎都说我必须手动将根证书添加到证书库,否则信任链将无效. 问题:是否有一种编程方式来设置信任链,所以我不必手动完成它? 代码如下: var serverCert = new X509Certificate2("FullPathToMyCertificate.cer","Password"); Client.ClientCredentials.ServiceCertificate.DefaultCertificate = serverCert; 我尝试使用客户端时发生的异常是: System.IdentityModel.Tokens.SecurityTokenValidationException The X.509 certificate CN=notrealcertname,OU=TPA,OU=BMP,OU=Projects,O=Somebody,C=US is not in the trusted people store. The X.509 certificate CN=notrealcertname,C=US chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain could not be built to a trusted root authority. 解决方法
使用的组件默认验证链 – 当无法验证链时,您会得到该异常.
如果你想做所有事情,包括在代码中验证链,那么你需要 implement “custom validation” and integrate that into the WCF Host: Client.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom; Client.ServiceCertificate.Authentication.CustomCertificateValidator = new MyCertificateValidator(); 另一个选择是完全禁用验证(不用于生产!) Client.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 编辑 – 评论后: 为了自己验证链,你应该看一下X509Chain和X509Store – 了解如何实现这样的链验证,看看验证的Mono’s implementation …基本上你使用Find方法搜索X509Certificate2Collection的父等等…具有自定义验证的验证标准取决于您(有效签名,未过期……). MSDN上的一些参考链接: > http://msdn.microsoft.com/en-us/library/system.servicemodel.security.x509servicecertificateauthentication.certificatevalidationmode.aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 打造自己的硬件仿真平台8 - 仿真FLASH并移植一个FAT文件系统
- postgresql – 在ubuntu服务器上从postgres 9.1升级到9.3
- 单元测试 – 角度2 RC4:具有依赖注入的单元测试组件具有自
- PostgreSQL数据库中的常见错误
- ios – Xcode 8.3.3“没有iTunes Connect访问权限”
- 树莓派(raspberry pi)播发flash 远程登录 视频播放
- ruby-on-rails – has_one的after_add回调
- Oracle的substr函数简单用法
- c# – 使用unity xml config注册具有嵌套泛型的接口
- Dojo+MVC 之旅1 HelloWorld