Inheritance: System.Collections.IEnumerator
Exemplo n.º 1
0
        private void ProcessCertificateExtensions(X509ChainElement element)
        {
            X509ExtensionEnumerator enumerator = element.Certificate.Extensions.GetEnumerator();

            while (enumerator.MoveNext())
            {
                X509Extension current = enumerator.Current;
                if (current.Critical)
                {
                    switch (current.Oid.Value)
                    {
                    case "2.5.29.15":
                    case "2.5.29.19":
                        continue;
                    }
                    element.StatusFlags |= X509ChainStatusFlags.InvalidExtension;
                }
            }
        }
        public override string ToString(bool verbose)
        {
            if (!verbose || this.m_safeCertContext.IsInvalid)
            {
                return(this.ToString());
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("[Version]" + Environment.NewLine + "  ");
            sb.Append("V" + this.Version);
            sb.Append(Environment.NewLine + Environment.NewLine + "[Subject]" + Environment.NewLine + "  ");
            sb.Append(this.SubjectName.Name);
            string nameInfo = this.GetNameInfo(X509NameType.SimpleName, false);

            if (nameInfo.Length > 0)
            {
                sb.Append(Environment.NewLine + "  Simple Name: ");
                sb.Append(nameInfo);
            }
            string str2 = this.GetNameInfo(X509NameType.EmailName, false);

            if (str2.Length > 0)
            {
                sb.Append(Environment.NewLine + "  Email Name: ");
                sb.Append(str2);
            }
            string str3 = this.GetNameInfo(X509NameType.UpnName, false);

            if (str3.Length > 0)
            {
                sb.Append(Environment.NewLine + "  UPN Name: ");
                sb.Append(str3);
            }
            string str4 = this.GetNameInfo(X509NameType.DnsName, false);

            if (str4.Length > 0)
            {
                sb.Append(Environment.NewLine + "  DNS Name: ");
                sb.Append(str4);
            }
            sb.Append(Environment.NewLine + Environment.NewLine + "[Issuer]" + Environment.NewLine + "  ");
            sb.Append(this.IssuerName.Name);
            nameInfo = this.GetNameInfo(X509NameType.SimpleName, true);
            if (nameInfo.Length > 0)
            {
                sb.Append(Environment.NewLine + "  Simple Name: ");
                sb.Append(nameInfo);
            }
            str2 = this.GetNameInfo(X509NameType.EmailName, true);
            if (str2.Length > 0)
            {
                sb.Append(Environment.NewLine + "  Email Name: ");
                sb.Append(str2);
            }
            str3 = this.GetNameInfo(X509NameType.UpnName, true);
            if (str3.Length > 0)
            {
                sb.Append(Environment.NewLine + "  UPN Name: ");
                sb.Append(str3);
            }
            str4 = this.GetNameInfo(X509NameType.DnsName, true);
            if (str4.Length > 0)
            {
                sb.Append(Environment.NewLine + "  DNS Name: ");
                sb.Append(str4);
            }
            sb.Append(Environment.NewLine + Environment.NewLine + "[Serial Number]" + Environment.NewLine + "  ");
            sb.Append(this.SerialNumber);
            sb.Append(Environment.NewLine + Environment.NewLine + "[Not Before]" + Environment.NewLine + "  ");
            sb.Append(X509Certificate.FormatDate(this.NotBefore));
            sb.Append(Environment.NewLine + Environment.NewLine + "[Not After]" + Environment.NewLine + "  ");
            sb.Append(X509Certificate.FormatDate(this.NotAfter));
            sb.Append(Environment.NewLine + Environment.NewLine + "[Thumbprint]" + Environment.NewLine + "  ");
            sb.Append(this.Thumbprint);
            sb.Append(Environment.NewLine + Environment.NewLine + "[Signature Algorithm]" + Environment.NewLine + "  ");
            sb.Append(this.SignatureAlgorithm.FriendlyName + "(" + this.SignatureAlgorithm.Value + ")");
            System.Security.Cryptography.X509Certificates.PublicKey publicKey = this.PublicKey;
            sb.Append(Environment.NewLine + Environment.NewLine + "[Public Key]" + Environment.NewLine + "  Algorithm: ");
            sb.Append(publicKey.Oid.FriendlyName);
            sb.Append(Environment.NewLine + "  Length: ");
            sb.Append(publicKey.Key.KeySize);
            sb.Append(Environment.NewLine + "  Key Blob: ");
            sb.Append(publicKey.EncodedKeyValue.Format(true));
            sb.Append(Environment.NewLine + "  Parameters: ");
            sb.Append(publicKey.EncodedParameters.Format(true));
            this.AppendPrivateKeyInfo(sb);
            X509ExtensionCollection extensions = this.Extensions;

            if (extensions.Count > 0)
            {
                sb.Append(Environment.NewLine + Environment.NewLine + "[Extensions]");
                X509ExtensionEnumerator enumerator = extensions.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    X509Extension current = enumerator.Current;
                    sb.Append(Environment.NewLine + "* " + current.Oid.FriendlyName + "(" + current.Oid.Value + "):" + Environment.NewLine + "  " + current.Format(true));
                }
            }
            sb.Append(Environment.NewLine);
            return(sb.ToString());
        }