
当我手动将根证书添加到受信任人员中的证书存储区时,此工作正常.但是,我宁愿不必在每次部署时都这样做 – 我宁愿以编程方式处理它.
当我从证书存储中删除根证书时,我得到一个例外.
我读过的所有内容似乎都说我必须手动将根证书添加到证书库,否则信任链将无效.
问题:是否有一种编程方式来设置信任链,所以我不必手动完成它?
代码如下:
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
> http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.x509certificatevalidator.aspx
> http://msdn.microsoft.com/en-us/library/ms733806.aspx
以上是内存溢出为你收集整理的c# – WCF证书链,以编程方式验证全部内容,希望文章能够帮你解决c# – WCF证书链,以编程方式验证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)