我有一个 ASP.net Web 应用程序,我的客户需要使用客户端 v3 证书对我的网站进行身份验证。
我需要检查的是: 1-证书有效 2-“Issued To CN”具有特定值
我在我的 MVC 操作中执行以下操作:
var req = Request.ClientCertificate;
req
有一个名为 IsValid
的属性,它足以满足要求 (1)。现在,这里的问题是我无法检查 CN,因为我认为它存储在 byte[0]
类型的另一个名为 Certificate
的属性中。
我试过像这样阅读证书:
var x509 = new X509Certificate(req.Certificate);
但我有两个异常(exception):
'x509.Issuer' threw an exception of type 'System.Security.Cryptography.CryptographicException'
'x509.Subject' threw an exception of type 'System.Security.Cryptography.CryptographicException'
如何读取证书?
最佳答案
典型的方法是将证书属性(例如主题或 CN)映射到一个或多个用户。这是通过 IIS configuration 完成的.
完成后,所有 MVC 要做的就是 check the current user .
另见 this article .
关于asp.net - 客户端身份验证 - 处理客户端证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39694325/