简体   繁体   English

如何检查X509证书颁发者是否为Microsoft

[英]How to check if x509 certificate issuer is microsoft

So for a school project I need to find out if a provided X509Certificate is issued by microsoft. 因此,对于一个学校项目,我需要确定是否由Microsoft发行了提供的X509Certificate。 If it is I have to return true, else I have to return false. 如果它是我必须返回true,否则我必须返回false。

This is what i've got at the moment 这就是我目前所拥有的

private bool IsAcceptedCertificate(X509Certificate cert)
        {               
            try
            {
                //if microsoft
                if (cert.Issuer.Equals("Microsoft")) {
                    return true;
                }
            }
            catch (CryptographicException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            //if not microsoft
            return false;
        }

Edit 1: Is this the correct way to tackle this problem. 编辑1:这是解决此问题的正确方法。 I can't test it out because the teacher can't provide me a certificate to test it. 我无法对其进行测试,因为老师无法向我提供证书来进行测试。 Yet I still need this thing to work correctly. 但是我仍然需要这个东西才能正常工作。

Something like this should be sufficient: 像这样的东西就足够了:

private  bool IsAcceptedCertificate(X509Certificate2 cert)
{
    try
    {
        if(cert.Verify() && cert.Issuer.StartsWith("CN=Microsoft"))

        {
            return true;
        }
    }
    catch (CryptographicException ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
    }

    //if not microsoft
    return false;
}

It checks that the certificate is valid, and that its issued by "some" Microsoft CA. 它检查证书是否有效,以及由“某些” Microsoft CA颁发的证书。 To be more specific you can check against all Microsoft CAs, instead of CN=Microsoft* 更具体地说,您可以检查所有Microsoft CA,而不是CN = Microsoft *

Edit: In the Trusted Root Certificaton Authorities store on Windows 10 machines, there are 4 trusted Micorosft root certificates. 编辑:在Windows 10计算机上的受信任的根证书颁发机构存储中,有4个受信任的Micorosft根证书。 "CN = Microsoft Root Authority","CN = Microsoft Root Certificate Authority", "CN = Microsoft Root Certificate Authority 2010" and "CN = Microsoft Root Certificate Authority 2011" “ CN = Microsoft根证书颁发机构”,“ CN = Microsoft根证书颁发机构”,“ CN = Microsoft根证书颁发机构2010”和“ CN = Microsoft根证书颁发机构2011”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM