Beispiel #1
0
        //public static void AddCertificate(this CertificateStoreClient client, Certificate cert)
        //{
        //    if (cert == null)
        //    {
        //        throw new ArgumentNullException("cert");  
        //    }
            
        //    client.AddCertificates(new Certificate[] {cert});
        //}

        public static bool Contains(this CertificateStoreClient client, X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            return client.Contains(certificate.ExtractEmailNameOrName(), certificate.Thumbprint);
        }
Beispiel #2
0
        void ResolveIssuers(X509Certificate2 certificate, X509Certificate2Collection issuers, int chainLength)
        {
            //
            // only look at simpleNames because intermediates are always going to be org-level, not email, certs
            //
            string issuerName = certificate.GetNameInfo(X509NameType.SimpleName, true); // true == "for issuer"
            //
            // If the issuer name matches the Cert name, we have a self-signed cert
            //
            if (certificate.MatchName(issuerName))
            {
                return;
            }
            //
            // If the issuer is already known, then we are good
            //
            if (issuers.FindByName(issuerName) != null)
            {
                return;
            }

            if (chainLength == m_maxIssuerChainLength)
            {
                //
                // Chain too long. Ignore...
                //
                return;
            }
            //
            // Retrieve the issuer's certificate
            //
            X509Certificate2Collection issuerCertificates = m_certResolver.SafeGetCertificates(certificate.ExtractEmailNameOrName(true));
            if (CollectionExtensions.IsNullOrEmpty(issuerCertificates))
            {
                return;
            }
            //
            // Recursively fetch the issuers who issued this set of certificates
            //
            foreach (X509Certificate2 issuerCertificate in issuerCertificates)
            {
                if (issuerCertificate.MatchName(issuerName) && !issuers.ContainsThumbprint(issuerCertificate.Thumbprint))
                {
                    //
                    // New issuer
                    //
                    issuers.Add(issuerCertificate);
                    //
                    // And keep working up the chain
                    //
                    this.ResolveIssuers(issuerCertificate, issuers, chainLength + 1);
                }
            }
        }
Beispiel #3
0
 public void TestNameExtraction(X509Certificate2 cert)
 {
     string name = cert.ExtractEmailNameOrName();
     Assert.False(string.IsNullOrEmpty(name));
     Assert.True(cert.MatchEmailNameOrName(name));
 }
Beispiel #4
0
 public void Dump(string[] args)
 {
     string path = args.GetRequiredValue(0);
     
     X509Certificate2 cert = new X509Certificate2(path);
     X509ExtensionCollection extensions = cert.Extensions;
     
     Console.WriteLine(cert.ExtractEmailNameOrName());
     Console.WriteLine("Is CA={0}", cert.IsCertificateAuthority());
     foreach(X509Extension extension in extensions)
     {
         this.WriteExtension(extension);
     }
 }