1 package org.bouncycastle.x509.extension; 2 3 import java.io.IOException; 4 import java.security.cert.CertificateParsingException; 5 import java.security.cert.X509Certificate; 6 import java.util.ArrayList; 7 import java.util.Collection; 8 import java.util.Collections; 9 import java.util.Enumeration; 10 import java.util.List; 11 12 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 13 import org.bouncycastle.asn1.ASN1OctetString; 14 import org.bouncycastle.asn1.ASN1Primitive; 15 import org.bouncycastle.asn1.ASN1String; 16 import org.bouncycastle.asn1.DEROctetString; 17 import org.bouncycastle.asn1.DERSequence; 18 import org.bouncycastle.asn1.x500.X500Name; 19 import org.bouncycastle.asn1.x509.Extension; 20 import org.bouncycastle.asn1.x509.GeneralName; 21 import org.bouncycastle.util.Integers; 22 23 24 /** 25 * @deprecated use org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils 26 */ 27 public class X509ExtensionUtil 28 { 29 /** 30 * @deprecated use org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils.parseExtensionValue() 31 */ 32 public static ASN1Primitive fromExtensionValue( 33 byte[] encodedValue) 34 throws IOException 35 { 36 ASN1OctetString octs = (ASN1OctetString)ASN1Primitive.fromByteArray(encodedValue); 37 38 return ASN1Primitive.fromByteArray(octs.getOctets()); 39 } 40 41 /** 42 * @deprecated use org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils.getIssuerAlternativeNames() 43 */ 44 public static Collection getIssuerAlternativeNames(X509Certificate cert) 45 throws CertificateParsingException 46 { 47 byte[] extVal = cert.getExtensionValue(Extension.issuerAlternativeName.getId()); 48 49 return getAlternativeNames(extVal); 50 } 51 52 /** 53 * @deprecated use org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils.getSubjectAlternativeNames() 54 */ 55 public static Collection getSubjectAlternativeNames(X509Certificate cert) 56 throws CertificateParsingException 57 { 58 byte[] extVal = cert.getExtensionValue(Extension.subjectAlternativeName.getId()); 59 60 return getAlternativeNames(extVal); 61 } 62 63 private static Collection getAlternativeNames(byte[] extVal) 64 throws CertificateParsingException 65 { 66 if (extVal == null) 67 { 68 return Collections.EMPTY_LIST; 69 } 70 try 71 { 72 Collection temp = new ArrayList(); 73 Enumeration it = DERSequence.getInstance(fromExtensionValue(extVal)).getObjects(); 74 while (it.hasMoreElements()) 75 { 76 GeneralName genName = GeneralName.getInstance(it.nextElement()); 77 List list = new ArrayList(); 78 list.add(Integers.valueOf(genName.getTagNo())); 79 switch (genName.getTagNo()) 80 { 81 case GeneralName.ediPartyName: 82 case GeneralName.x400Address: 83 case GeneralName.otherName: 84 list.add(genName.getName().toASN1Primitive()); 85 break; 86 case GeneralName.directoryName: 87 list.add(X500Name.getInstance(genName.getName()).toString()); 88 break; 89 case GeneralName.dNSName: 90 case GeneralName.rfc822Name: 91 case GeneralName.uniformResourceIdentifier: 92 list.add(((ASN1String)genName.getName()).getString()); 93 break; 94 case GeneralName.registeredID: 95 list.add(ASN1ObjectIdentifier.getInstance(genName.getName()).getId()); 96 break; 97 case GeneralName.iPAddress: 98 list.add(DEROctetString.getInstance(genName.getName()).getOctets()); 99 break; 100 default: 101 throw new IOException("Bad tag number: " + genName.getTagNo()); 102 } 103 104 temp.add(list); 105 } 106 return Collections.unmodifiableCollection(temp); 107 } 108 catch (Exception e) 109 { 110 throw new CertificateParsingException(e.getMessage()); 111 } 112 } 113 } 114