コード例 #1
0
        private static Asn1Sequence FromCertificate(
            X509Certificate certificate)
        {
            try
            {
                GeneralName genName = new GeneralName(
                    PrincipalUtilities.GetIssuerX509Principal(certificate));

                if (certificate.Version == 3)
                {
                    Asn1OctetString ext = certificate.GetExtensionValue(X509Extensions.SubjectKeyIdentifier);

                    if (ext != null)
                    {
                        Asn1OctetString str = (Asn1OctetString)X509ExtensionUtilities.FromExtensionValue(ext);

                        return((Asn1Sequence) new AuthorityKeyIdentifier(
                                   str.GetOctets(), new GeneralNames(genName), certificate.SerialNumber).ToAsn1Object());
                    }
                }

                SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(
                    certificate.GetPublicKey());

                return((Asn1Sequence) new AuthorityKeyIdentifier(
                           info, new GeneralNames(genName), certificate.SerialNumber).ToAsn1Object());
            }
            catch (Exception e)
            {
                throw new CertificateParsingException("Exception extracting certificate details", e);
            }
        }
コード例 #2
0
        private static ICollection GetAlternativeName(Asn1OctetString extVal)
        {
            IList list = Platform.CreateArrayList();

            if (extVal != null)
            {
                try
                {
                    Asn1Sequence instance = Asn1Sequence.GetInstance(X509ExtensionUtilities.FromExtensionValue(extVal));
                    foreach (GeneralName generalName in instance)
                    {
                        IList list2 = Platform.CreateArrayList();
                        list2.Add(generalName.TagNo);
                        switch (generalName.TagNo)
                        {
                        case 0:
                        case 3:
                        case 5:
                            list2.Add(generalName.Name.ToAsn1Object());
                            break;

                        case 1:
                        case 2:
                        case 6:
                            list2.Add(((IAsn1String)generalName.Name).GetString());
                            break;

                        case 4:
                            list2.Add(X509Name.GetInstance(generalName.Name).ToString());
                            break;

                        case 7:
                            list2.Add(Asn1OctetString.GetInstance(generalName.Name).GetOctets());
                            break;

                        case 8:
                            list2.Add(DerObjectIdentifier.GetInstance(generalName.Name).Id);
                            break;

                        default:
                            throw new IOException("Bad tag number: " + generalName.TagNo);
                        }
                        list.Add(list2);
                    }
                }
                catch (Exception ex)
                {
                    throw new CertificateParsingException(ex.Message);
                }
            }
            return(list);
        }
コード例 #3
0
//		private AuthorityKeyIdentifier authKeyID;

        /**
         * Constructor which will take the byte[] returned from getExtensionValue()
         *
         * @param encodedValue a DER octet encoded string with the extension structure in it.
         * @throws IOException on parsing errors.
         */
        public SubjectKeyIdentifierStructure(
            Asn1OctetString encodedValue)
            : base((Asn1OctetString)X509ExtensionUtilities.FromExtensionValue(encodedValue))
        {
        }
コード例 #4
0
 /**
  * Constructor which will take the byte[] returned from getExtensionValue()
  *
  * @param encodedValue a DER octet encoded string with the extension structure in it.
  * @throws IOException on parsing errors.
  */
 // TODO Add a functional constructor from byte[]?
 public AuthorityKeyIdentifierStructure(
     Asn1OctetString encodedValue)
     : base((Asn1Sequence)X509ExtensionUtilities.FromExtensionValue(encodedValue))
 {
 }
コード例 #5
0
        public static ICollection GetSubjectAlternativeNames(X509Certificate cert)
        {
            Asn1OctetString extensionValue = cert.GetExtensionValue(X509Extensions.SubjectAlternativeName);

            return(X509ExtensionUtilities.GetAlternativeName(extensionValue));
        }