通常,为了验证证书链,我应该从叶证书中获取数字签名并检查它是否由根证书签名 – 但在.NET中我找不到从X509Certificate2对象中提取签名的方法.
因此,我想到了以下方式使用X509Chain.Build()方法:
void ValidateChain(X509Certificate2Collection collection,X509Certificate2 leaf) { X509Chain x509Chain = new X509Chain(); x509Chain.ChainPolicy.ExtraStore.AddRange(collection); bool isValid = x509Chain.Build(leaf); }
但是我对构建方法有一些疑问:
>据我所知,链也是从我的计算机商店构建的,我想它只是从ExtraStore构建的,我该如何定义这种行为?
>我看到链条建成后它不包含根证书;我的问题是为什么,以及如何验证链是否具有根CA,因为这不是链元素的一部分.
如果有人能向我解释Build()方法是如何工作的,我将非常感激.
解决方法
The X509Chain object has a global error status called ChainStatus that should be used for certificate validation. The rules governing certificate validation are complex,and it is easy to oversimplify the validation logic by ignoring the error status of one or more of the elements involved. The global error status takes into consideration the status of each element in the chain.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。