1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1.x509; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport java.io.IOException; 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.Enumeration; 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.Hashtable; 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.Vector; 7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 8c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1Encodable; 9c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1EncodableVector; 10c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1Object; 11c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1Sequence; 12c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1Set; 13c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1TaggedObject; 14c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DEREncodable; 15c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERObject; 16c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERObjectIdentifier; 17c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERSequence; 18c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERSet; 19c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERString; 20c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.DERUniversalString; 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 226e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport org.bouncycastle.asn1.x500.X500Name; 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.util.Strings; 24c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.util.encoders.Hex; 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/** 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <pre> 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * AttributeTypeAndValue ::= SEQUENCE { 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * type OBJECT IDENTIFIER, 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * value ANY } 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * </pre> 366e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom * @deprecated use org.bouncycastle.asn1.x500.X500Name. 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class X509Name 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam extends ASN1Encodable 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * country code - StringType(SIZE(2)) 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier C = new DERObjectIdentifier("2.5.4.6"); 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * organization - StringType(SIZE(1..64)) 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier O = new DERObjectIdentifier("2.5.4.10"); 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * organizational unit name - StringType(SIZE(1..64)) 53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier OU = new DERObjectIdentifier("2.5.4.11"); 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Title 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier T = new DERObjectIdentifier("2.5.4.12"); 60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * common name - StringType(SIZE(1..64)) 63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier CN = new DERObjectIdentifier("2.5.4.3"); 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * device serial number name - StringType(SIZE(1..64)) 68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier SN = new DERObjectIdentifier("2.5.4.5"); 70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * street - StringType(SIZE(1..64)) 73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier STREET = new DERObjectIdentifier("2.5.4.9"); 75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * device serial number name - StringType(SIZE(1..64)) 78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier SERIALNUMBER = SN; 80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 82b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * locality name - StringType(SIZE(1..64)) 83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 84b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier L = new DERObjectIdentifier("2.5.4.7"); 85b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * state, or province name - StringType(SIZE(1..64)) 88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier ST = new DERObjectIdentifier("2.5.4.8"); 90b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 92b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Naming attributes of type X520name 93b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 94b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier SURNAME = new DERObjectIdentifier("2.5.4.4"); 95b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier GIVENNAME = new DERObjectIdentifier("2.5.4.42"); 96b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier INITIALS = new DERObjectIdentifier("2.5.4.43"); 97b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier GENERATION = new DERObjectIdentifier("2.5.4.44"); 98b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier UNIQUE_IDENTIFIER = new DERObjectIdentifier("2.5.4.45"); 99b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 100b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * businessCategory - DirectoryString(SIZE(1..128) 102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 103b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier BUSINESS_CATEGORY = new DERObjectIdentifier( 104b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "2.5.4.15"); 105b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 106b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 107b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * postalCode - DirectoryString(SIZE(1..40) 108b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 109b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier POSTAL_CODE = new DERObjectIdentifier( 110b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "2.5.4.17"); 111b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 112b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 113b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * dnQualifier - DirectoryString(SIZE(1..64) 114b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 115b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier DN_QUALIFIER = new DERObjectIdentifier( 116b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "2.5.4.46"); 117b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 118b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 119b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 Pseudonym - DirectoryString(SIZE(1..64) 120b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 121b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier PSEUDONYM = new DERObjectIdentifier( 122b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "2.5.4.65"); 123b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 124b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 125b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 126b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 DateOfBirth - GeneralizedTime - YYYYMMDD000000Z 127b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 128b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier DATE_OF_BIRTH = new DERObjectIdentifier( 129b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "1.3.6.1.5.5.7.9.1"); 130b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 131b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 132b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 PlaceOfBirth - DirectoryString(SIZE(1..128) 133b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 134b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier PLACE_OF_BIRTH = new DERObjectIdentifier( 135b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "1.3.6.1.5.5.7.9.2"); 136b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 137b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 138b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 Gender - PrintableString (SIZE(1)) -- "M", "F", "m" or "f" 139b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 140b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier GENDER = new DERObjectIdentifier( 141b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "1.3.6.1.5.5.7.9.3"); 142b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 143b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 144b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 CountryOfCitizenship - PrintableString (SIZE (2)) -- ISO 3166 145b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * codes only 146b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 147b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier COUNTRY_OF_CITIZENSHIP = new DERObjectIdentifier( 148b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "1.3.6.1.5.5.7.9.4"); 149b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 150b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 151b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 CountryOfResidence - PrintableString (SIZE (2)) -- ISO 3166 152b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * codes only 153b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 154b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier COUNTRY_OF_RESIDENCE = new DERObjectIdentifier( 155b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam "1.3.6.1.5.5.7.9.5"); 156b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 157b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 158b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 159b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * ISIS-MTT NameAtBirth - DirectoryString(SIZE(1..64) 160b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 161b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier NAME_AT_BIRTH = new DERObjectIdentifier("1.3.36.8.3.14"); 162b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 163b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 164b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC 3039 PostalAddress - SEQUENCE SIZE (1..6) OF 165b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * DirectoryString(SIZE(1..30)) 166b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 167c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final DERObjectIdentifier POSTAL_ADDRESS = new DERObjectIdentifier("2.5.4.16"); 168c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 169c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 170c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * RFC 2256 dmdName 171c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 172c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final DERObjectIdentifier DMD_NAME = new DERObjectIdentifier("2.5.4.54"); 173c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 174c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 175c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * id-at-telephoneNumber 176c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 177c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final DERObjectIdentifier TELEPHONE_NUMBER = X509ObjectIdentifiers.id_at_telephoneNumber; 178c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 179c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 180c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * id-at-name 181c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 182c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final DERObjectIdentifier NAME = X509ObjectIdentifiers.id_at_name; 183b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 184b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 185b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Email address (RSA PKCS#9 extension) - IA5String. 186b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p>Note: if you're trying to be ultra orthodox, don't use this! It shouldn't be in here. 187b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 188b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier EmailAddress = PKCSObjectIdentifiers.pkcs_9_at_emailAddress; 189b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 190b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 191b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * more from PKCS#9 192b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 193b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier UnstructuredName = PKCSObjectIdentifiers.pkcs_9_at_unstructuredName; 194b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier UnstructuredAddress = PKCSObjectIdentifiers.pkcs_9_at_unstructuredAddress; 195b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 196b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 197b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * email address in Verisign certificates 198b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 199b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier E = EmailAddress; 200b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 201b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /* 202b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * others... 203b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 204b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier DC = new DERObjectIdentifier("0.9.2342.19200300.100.1.25"); 205b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 206b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 207b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * LDAP User id. 208b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 209b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static final DERObjectIdentifier UID = new DERObjectIdentifier("0.9.2342.19200300.100.1.1"); 210b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 211b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 212b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * determines whether or not strings should be processed and printed 213b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * from back to front. 214b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 215b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static boolean DefaultReverse = false; 216b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 217b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 218b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * default look up table translating OID values into their common symbols following 219b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * the convention in RFC 2253 with a few extras 220b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 221c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable DefaultSymbols = new Hashtable(); 222b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 223b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 224b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * look up table translating OID values into their common symbols following the convention in RFC 2253 225b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 226b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 227c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable RFC2253Symbols = new Hashtable(); 228b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 229b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 230b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * look up table translating OID values into their common symbols following the convention in RFC 1779 231b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 232b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 233c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable RFC1779Symbols = new Hashtable(); 234b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 235b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 236c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * look up table translating common symbols into their OIDS. 237b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 238c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable DefaultLookUp = new Hashtable(); 239b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 240b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 241c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * look up table translating OID values into their common symbols 242c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @deprecated use DefaultSymbols 243b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 244c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable OIDLookUp = DefaultSymbols; 245c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 246c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 247c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * look up table translating string values into their OIDS - 248c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @deprecated use DefaultLookUp 249c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 250c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public static final Hashtable SymbolLookUp = DefaultLookUp; 251b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 252db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom // BEGIN android-changed 253db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom private static final Boolean TRUE = Boolean.TRUE; 254db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom private static final Boolean FALSE = Boolean.FALSE; 255db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom // END android-changed 256b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 257b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam static 258b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 259b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(C, "C"); 260b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(O, "O"); 261b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(T, "T"); 262b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(OU, "OU"); 263b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(CN, "CN"); 264b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(L, "L"); 265b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(ST, "ST"); 266c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DefaultSymbols.put(SN, "SERIALNUMBER"); 267b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(EmailAddress, "E"); 268b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(DC, "DC"); 269b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(UID, "UID"); 270b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(STREET, "STREET"); 271b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(SURNAME, "SURNAME"); 272b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(GIVENNAME, "GIVENNAME"); 273b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(INITIALS, "INITIALS"); 274b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(GENERATION, "GENERATION"); 275b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(UnstructuredAddress, "unstructuredAddress"); 276b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(UnstructuredName, "unstructuredName"); 277b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(UNIQUE_IDENTIFIER, "UniqueIdentifier"); 278b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(DN_QUALIFIER, "DN"); 279b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(PSEUDONYM, "Pseudonym"); 280b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(POSTAL_ADDRESS, "PostalAddress"); 281b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(NAME_AT_BIRTH, "NameAtBirth"); 282b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(COUNTRY_OF_CITIZENSHIP, "CountryOfCitizenship"); 283b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(COUNTRY_OF_RESIDENCE, "CountryOfResidence"); 284b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(GENDER, "Gender"); 285b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(PLACE_OF_BIRTH, "PlaceOfBirth"); 286b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(DATE_OF_BIRTH, "DateOfBirth"); 287b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(POSTAL_CODE, "PostalCode"); 288b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultSymbols.put(BUSINESS_CATEGORY, "BusinessCategory"); 289c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DefaultSymbols.put(TELEPHONE_NUMBER, "TelephoneNumber"); 290c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DefaultSymbols.put(NAME, "Name"); 291b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 292b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(C, "C"); 293b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(O, "O"); 294b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(OU, "OU"); 295b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(CN, "CN"); 296b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(L, "L"); 297b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(ST, "ST"); 298b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(STREET, "STREET"); 299b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(DC, "DC"); 300b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC2253Symbols.put(UID, "UID"); 301b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 302b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(C, "C"); 303b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(O, "O"); 304b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(OU, "OU"); 305b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(CN, "CN"); 306b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(L, "L"); 307b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(ST, "ST"); 308b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam RFC1779Symbols.put(STREET, "STREET"); 309b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 310b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("c", C); 311b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("o", O); 312b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("t", T); 313b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("ou", OU); 314b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("cn", CN); 315b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("l", L); 316b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("st", ST); 317b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("sn", SN); 318b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("serialnumber", SN); 319b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("street", STREET); 320b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("emailaddress", E); 321b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("dc", DC); 322b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("e", E); 323b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("uid", UID); 324b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("surname", SURNAME); 325b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("givenname", GIVENNAME); 326b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("initials", INITIALS); 327b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("generation", GENERATION); 328b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("unstructuredaddress", UnstructuredAddress); 329b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("unstructuredname", UnstructuredName); 330b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("uniqueidentifier", UNIQUE_IDENTIFIER); 331b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("dn", DN_QUALIFIER); 332b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("pseudonym", PSEUDONYM); 333b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("postaladdress", POSTAL_ADDRESS); 334b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("nameofbirth", NAME_AT_BIRTH); 335b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("countryofcitizenship", COUNTRY_OF_CITIZENSHIP); 336b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("countryofresidence", COUNTRY_OF_RESIDENCE); 337b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("gender", GENDER); 338b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("placeofbirth", PLACE_OF_BIRTH); 339b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("dateofbirth", DATE_OF_BIRTH); 340b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("postalcode", POSTAL_CODE); 341b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DefaultLookUp.put("businesscategory", BUSINESS_CATEGORY); 342c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DefaultLookUp.put("telephonenumber", TELEPHONE_NUMBER); 343c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DefaultLookUp.put("name", NAME); 344b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 345b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 346b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private X509NameEntryConverter converter = null; 347db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom private Vector ordering = new Vector(); 348db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom private Vector values = new Vector(); 349db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom private Vector added = new Vector(); 350c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 351b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private ASN1Sequence seq; 352b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 353c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private boolean isHashCodeCalculated; 354c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private int hashCodeValue; 355c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 356b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 357b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Return a X509Name based on the passed in tagged object. 358b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 359b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param obj tag object holding name. 360b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param explicit true if explicitly tagged false otherwise. 361b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the X509Name 362b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 363b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static X509Name getInstance( 364b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1TaggedObject obj, 365b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean explicit) 366b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 367b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return getInstance(ASN1Sequence.getInstance(obj, explicit)); 368b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 369b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 370b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static X509Name getInstance( 371b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Object obj) 372b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 373b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj == null || obj instanceof X509Name) 374b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 375b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return (X509Name)obj; 376b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 3776e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom else if (obj instanceof X500Name) 378b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 3796e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom return new X509Name(ASN1Sequence.getInstance(((X500Name)obj).getDERObject())); 3806e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom } 3816e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom else if (obj != null) 3826e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom { 3836e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom return new X509Name(ASN1Sequence.getInstance(obj)); 384b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 385b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3866e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom return null; 387b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 388b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3896e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom protected X509Name() 3906e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom { 3916e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom // constructure use by new X500 Name class 3926e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom } 393b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 394b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Constructor from ASN1Sequence 395b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 396b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * the principal will be a list of constructed sets, each containing an (OID, String) pair. 397b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 398b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 399b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1Sequence seq) 400b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 401b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.seq = seq; 402b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 403b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Enumeration e = seq.getObjects(); 404b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 405b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam while (e.hasMoreElements()) 406b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 4076e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom ASN1Set set = ASN1Set.getInstance(((DEREncodable)e.nextElement()).getDERObject()); 408b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 409b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i < set.size(); i++) 410b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 411c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i)); 412c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 413c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (s.size() != 2) 414c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 415c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throw new IllegalArgumentException("badly sized pair"); 416c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 417c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 418db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom ordering.addElement(DERObjectIdentifier.getInstance(s.getObjectAt(0))); 419b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 420b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DEREncodable value = s.getObjectAt(1); 421c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (value instanceof DERString && !(value instanceof DERUniversalString)) 422b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 423c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String v = ((DERString)value).getString(); 424c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (v.length() > 0 && v.charAt(0) == '#') 425c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 426db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom values.addElement("\\" + v); 427c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 428c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 429c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 430db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom values.addElement(v); 431c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 432b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 433b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 434b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 435db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded()))); 436b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 437db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom // BEGIN android-changed 438db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom added.addElement(Boolean.valueOf(i != 0)); 439b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // END android-changed 440b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 441b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 442b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 443b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 444b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 445b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * constructor from a table of attributes. 446b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 447b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * it's is assumed the table contains OID/String pairs, and the contents 448b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * of the table are copied into an internal table as part of the 449b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * construction process. 450b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 451b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <b>Note:</b> if the name you are trying to generate should be 452b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * following a specific ordering, you should use the constructor 453b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * with the ordering specified below. 454c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @deprecated use an ordered constructor! The hashtable ordering is rarely correct 455b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 456b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 457b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable attributes) 458b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 459b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(null, attributes); 460b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 461b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 462b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 463b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Constructor from a table of attributes with ordering. 464b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 465b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * it's is assumed the table contains OID/String pairs, and the contents 466b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * of the table are copied into an internal table as part of the 467b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * construction process. The ordering vector should contain the OIDs 468b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in the order they are meant to be encoded or printed in toString. 469b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 470b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 471b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector ordering, 472b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable attributes) 473b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 474b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(ordering, attributes, new X509DefaultEntryConverter()); 475b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 476b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 477b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 478b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Constructor from a table of attributes with ordering. 479b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 480b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * it's is assumed the table contains OID/String pairs, and the contents 481b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * of the table are copied into an internal table as part of the 482b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * construction process. The ordering vector should contain the OIDs 483b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in the order they are meant to be encoded or printed in toString. 484b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 485b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * The passed in converter will be used to convert the strings into their 486b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * ASN.1 counterparts. 487b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 488b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 489c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom Vector ordering, 490c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom Hashtable attributes, 491c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom X509NameEntryConverter converter) 492b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 493b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.converter = converter; 494b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 495b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (ordering != null) 496b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 497b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i != ordering.size(); i++) 498b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 499db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(ordering.elementAt(i)); 500db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(FALSE); 501b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 502b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 503b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 504b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 505b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Enumeration e = attributes.keys(); 506b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 507b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam while (e.hasMoreElements()) 508b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 509db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(e.nextElement()); 510db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(FALSE); 511b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 512b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 513b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 514db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != this.ordering.size(); i++) 515b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 516db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oid = (DERObjectIdentifier)this.ordering.elementAt(i); 517db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom 518db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (attributes.get(oid) == null) 519db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom { 520db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom throw new IllegalArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name"); 521db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom } 522db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom 523db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values.addElement(attributes.get(oid)); // copy the hash table 524b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 525b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 526b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 527b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 528b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes two vectors one of the oids and the other of the values. 529b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 530b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 531b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector oids, 532b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector values) 533b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 534b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(oids, values, new X509DefaultEntryConverter()); 535b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 536b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 537b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 538b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes two vectors one of the oids and the other of the values. 539b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 540b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * The passed in converter will be used to convert the strings into their 541b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * ASN.1 counterparts. 542b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 543b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 544b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector oids, 545b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector values, 546b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameEntryConverter converter) 547b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 548b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.converter = converter; 549b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 550b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (oids.size() != values.size()) 551b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 552b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("oids vector must be same length as values."); 553b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 554b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 555b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i < oids.size(); i++) 556b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 557db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(oids.elementAt(i)); 558db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values.addElement(values.elementAt(i)); 559db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(FALSE); 560b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 561b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 562b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 563c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// private Boolean isEncoded(String s) 564c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// { 565c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// if (s.charAt(0) == '#') 566c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// { 567c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// return TRUE; 568c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// } 569c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// 570c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// return FALSE; 571c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom// } 572c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 573b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 574b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 575b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes. 576b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 577b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 578b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName) 579b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 580b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(DefaultReverse, DefaultLookUp, dirName); 581b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 582b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 583b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 584b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 585b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes with each 586b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * string value being converted to its associated ASN.1 type using the passed 587b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in converter. 588b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 589b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 590b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName, 591b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameEntryConverter converter) 592b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 593b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(DefaultReverse, DefaultLookUp, dirName, converter); 594b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 595b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 596b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 597b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 598b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes. If reverse 599b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * is true, create the encoded version of the sequence starting from the 600b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * last element in the string. 601b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 602b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 603b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean reverse, 604b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName) 605b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 606b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(reverse, DefaultLookUp, dirName); 607b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 608b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 609b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 610b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 611b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes with each 612b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * string value being converted to its associated ASN.1 type using the passed 613b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in converter. If reverse is true the ASN.1 sequence representing the DN will 614b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * be built by starting at the end of the string, rather than the start. 615b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 616b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 617b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean reverse, 618b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName, 619b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameEntryConverter converter) 620b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 621b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(reverse, DefaultLookUp, dirName, converter); 622b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 623b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 624b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 625b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 626b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes. lookUp 627b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * should provide a table of lookups, indexed by lowercase only strings and 628b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * yielding a DERObjectIdentifier, other than that OID. and numeric oids 629b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * will be processed automatically. 630b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <br> 631b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * If reverse is true, create the encoded version of the sequence 632b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * starting from the last element in the string. 633b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param reverse true if we should start scanning from the end (RFC 2553). 634b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param lookUp table of names and their oids. 635b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param dirName the X.500 string to be parsed. 636b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 637b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 638b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean reverse, 639b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable lookUp, 640b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName) 641b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 642b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this(reverse, lookUp, dirName, new X509DefaultEntryConverter()); 643b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 644b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 645b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private DERObjectIdentifier decodeOID( 646b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String name, 647b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable lookUp) 648b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 649b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (Strings.toUpperCase(name).startsWith("OID.")) 650b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 651b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new DERObjectIdentifier(name.substring(4)); 652b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 653b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else if (name.charAt(0) >= '0' && name.charAt(0) <= '9') 654b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 655b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new DERObjectIdentifier(name); 656b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 657b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 658b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERObjectIdentifier oid = (DERObjectIdentifier)lookUp.get(Strings.toLowerCase(name)); 659b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (oid == null) 660b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 661b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name"); 662b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 663b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 664b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return oid; 665b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 666b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 667b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 668b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or 669b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * some such, converting it into an ordered set of name attributes. lookUp 670b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * should provide a table of lookups, indexed by lowercase only strings and 671b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * yielding a DERObjectIdentifier, other than that OID. and numeric oids 672b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * will be processed automatically. The passed in converter is used to convert the 673b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * string values to the right of each equals sign to their ASN.1 counterparts. 674b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <br> 675b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param reverse true if we should start scanning from the end, false otherwise. 676b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param lookUp table of names and oids. 677b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param dirName the string dirName 678b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param converter the converter to convert string values into their ASN.1 equivalents 679b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 680b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public X509Name( 681b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean reverse, 682b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable lookUp, 683b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String dirName, 684b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameEntryConverter converter) 685b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 686b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.converter = converter; 687b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameTokenizer nTok = new X509NameTokenizer(dirName); 688b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 689b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam while (nTok.hasMoreTokens()) 690b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 691b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String token = nTok.nextToken(); 692b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam int index = token.indexOf('='); 693b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 694b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (index == -1) 695b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 696db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom // BEGIN android-changed 697b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("badly formatted directory string"); 698db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom // END android-changed 699b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 700b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 701b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String name = token.substring(0, index); 702b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String value = token.substring(index + 1); 703b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERObjectIdentifier oid = decodeOID(name, lookUp); 704b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 705b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (value.indexOf('+') > 0) 706b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 707b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam X509NameTokenizer vTok = new X509NameTokenizer(value, '+'); 708c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String v = vTok.nextToken(); 709b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 710db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(oid); 711db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values.addElement(v); 712db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(FALSE); 713b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 714b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam while (vTok.hasMoreTokens()) 715b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 716b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String sv = vTok.nextToken(); 717b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam int ndx = sv.indexOf('='); 718b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 719b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String nm = sv.substring(0, ndx); 720b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String vl = sv.substring(ndx + 1); 721db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(decodeOID(nm, lookUp)); 722db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values.addElement(vl); 723db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(TRUE); 724b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 725b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 726b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 727b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 728db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering.addElement(oid); 729db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values.addElement(value); 730db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added.addElement(FALSE); 731b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 732b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 733b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 734b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (reverse) 735b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 736db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom Vector o = new Vector(); 737db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom Vector v = new Vector(); 738db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom Vector a = new Vector(); 739db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom 740db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom int count = 1; 741db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom 742db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i < this.ordering.size(); i++) 743db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom { 744db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (((Boolean)this.added.elementAt(i)).booleanValue()) 745db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom { 746db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom o.insertElementAt(this.ordering.elementAt(i), count); 747db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom v.insertElementAt(this.values.elementAt(i), count); 748db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom a.insertElementAt(this.added.elementAt(i), count); 749db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom count++; 750db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom } 751db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom else 752db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom { 753db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom o.insertElementAt(this.ordering.elementAt(i), 0); 754db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom v.insertElementAt(this.values.elementAt(i), 0); 755db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom a.insertElementAt(this.added.elementAt(i), 0); 756db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom count = 1; 757db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom } 758db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom } 759db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom 760db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.ordering = o; 761db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.values = v; 762db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom this.added = a; 763b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 764b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 765b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 766b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 767b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * return a vector of the oids in the name, in the order they were found. 768b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 769b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public Vector getOIDs() 770b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 771b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector v = new Vector(); 772b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 773db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != ordering.size(); i++) 774b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 775db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom v.addElement(ordering.elementAt(i)); 776b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 777b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 778b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return v; 779b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 780b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 781b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 782b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * return a vector of the values found in the name, in the order they 783b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * were found. 784b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 785b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public Vector getValues() 786b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 787b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Vector v = new Vector(); 788b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 789db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != values.size(); i++) 790b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 791db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom v.addElement(values.elementAt(i)); 792b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 793b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 794b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return v; 795c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 796c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 797c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 798c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return a vector of the values found in the name, in the order they 799c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * were found, with the DN label corresponding to passed in oid. 800c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 801c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public Vector getValues( 802c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DERObjectIdentifier oid) 803c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 804c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom Vector v = new Vector(); 805c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 806db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != values.size(); i++) 807c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 808db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (ordering.elementAt(i).equals(oid)) 809c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 810db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String val = (String)values.elementAt(i); 811c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 812c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (val.length() > 2 && val.charAt(0) == '\\' && val.charAt(1) == '#') 813c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 814c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom v.addElement(val.substring(1)); 815c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 816c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 817c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 818c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom v.addElement(val); 819c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 820c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 821c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 822c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 823c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return v; 824b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 825b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 826b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERObject toASN1Object() 827b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 828b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (seq == null) 829b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 830b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1EncodableVector vec = new ASN1EncodableVector(); 831b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1EncodableVector sVec = new ASN1EncodableVector(); 832b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERObjectIdentifier lstOid = null; 833b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 834db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != ordering.size(); i++) 835b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 836b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1EncodableVector v = new ASN1EncodableVector(); 837db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i); 838b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 839b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(oid); 840b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 841db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String str = (String)values.elementAt(i); 842b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 843b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(converter.getConvertedValue(oid, str)); 844c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 845c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (lstOid == null 846db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom || ((Boolean)this.added.elementAt(i)).booleanValue()) 847b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 848b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam sVec.add(new DERSequence(v)); 849b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 850b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 851b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 852b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam vec.add(new DERSet(sVec)); 853b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam sVec = new ASN1EncodableVector(); 854b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 855b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam sVec.add(new DERSequence(v)); 856b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 857b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 858b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam lstOid = oid; 859b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 860b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 861b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam vec.add(new DERSet(sVec)); 862b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 863b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam seq = new DERSequence(vec); 864b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 865b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 866b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return seq; 867b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 868b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 869b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 870b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param inOrder if true the order of both X509 names must be the same, 871b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * as well as the values associated with each element. 872b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 873c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public boolean equals(Object obj, boolean inOrder) 874b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 875c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!inOrder) 876c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 877c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return this.equals(obj); 878c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 879c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 880c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (obj == this) 881b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 882b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return true; 883b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 884b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 885c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) 886b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 887c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return false; 888b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 889b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 890c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DERObject derO = ((DEREncodable)obj).getDERObject(); 891c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 892c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (this.getDERObject().equals(derO)) 893c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 894c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return true; 895c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 896c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 897c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom X509Name other; 898c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 899c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom try 900c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 901c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom other = X509Name.getInstance(obj); 902c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 903c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom catch (IllegalArgumentException e) 904b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 905b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 906b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 907c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 908db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom int orderingSize = ordering.size(); 909b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 910db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (orderingSize != other.ordering.size()) 911b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 912b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 913b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 914c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 915c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom for (int i = 0; i < orderingSize; i++) 916b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 917db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i); 918db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oOid = (DERObjectIdentifier)other.ordering.elementAt(i); 919b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 920c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (oid.equals(oOid)) 921b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 922db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String value = (String)values.elementAt(i); 923db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String oValue = (String)other.values.elementAt(i); 924b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 925c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!equivalentStrings(value, oValue)) 926c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 927c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return false; 928b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 929b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 930b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 931b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 932b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 933b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 934b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 935b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 936b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return true; 937b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 938b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 939c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int hashCode() 940c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 941c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (isHashCodeCalculated) 942c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 943c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return hashCodeValue; 944c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 945c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 946c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom isHashCodeCalculated = true; 947c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 948c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom // this needs to be order independent, like equals 949db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i != ordering.size(); i += 1) 950c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 951db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String value = (String)values.elementAt(i); 952c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 953c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom value = canonicalize(value); 954c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom value = stripInternalSpaces(value); 955c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 956db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom hashCodeValue ^= ordering.elementAt(i).hashCode(); 957c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom hashCodeValue ^= value.hashCode(); 958c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 959c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 960c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return hashCodeValue; 961c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 962c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 963b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 964b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * test for equality - note: case is ignored. 965b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 966c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public boolean equals(Object obj) 967b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 968c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (obj == this) 969b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 970b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return true; 971b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 972b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 973c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) 974b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 975b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 976b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 977b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 978c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DERObject derO = ((DEREncodable)obj).getDERObject(); 979b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 980b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (this.getDERObject().equals(derO)) 981b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 982b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return true; 983b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 984c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 985c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom X509Name other; 986c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 987c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom try 988b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 989c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom other = X509Name.getInstance(obj); 990c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 991c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom catch (IllegalArgumentException e) 992c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 993b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 994b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 995b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 996db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom int orderingSize = ordering.size(); 997b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 998db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (orderingSize != other.ordering.size()) 999b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1000b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 1001b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1002b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1003c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom boolean[] indexes = new boolean[orderingSize]; 1004c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom int start, end, delta; 1005b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1006db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (ordering.elementAt(0).equals(other.ordering.elementAt(0))) // guess forward 1007b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1008c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom start = 0; 1009c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom end = orderingSize; 1010c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom delta = 1; 1011c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1012c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else // guess reversed - most common problem 1013c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1014c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom start = orderingSize - 1; 1015c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom end = -1; 1016c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom delta = -1; 1017c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1018c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1019c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom for (int i = start; i != end; i += delta) 1020c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1021c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom boolean found = false; 1022db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oid = (DERObjectIdentifier)ordering.elementAt(i); 1023db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String value = (String)values.elementAt(i); 1024c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1025c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom for (int j = 0; j < orderingSize; j++) 1026b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1027c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (indexes[j]) 1028b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1029b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam continue; 1030b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1031b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1032db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom DERObjectIdentifier oOid = (DERObjectIdentifier)other.ordering.elementAt(j); 1033b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1034c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (oid.equals(oOid)) 1035b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1036db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom String oValue = (String)other.values.elementAt(j); 1037c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1038c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (equivalentStrings(value, oValue)) 1039b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1040c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom indexes[j] = true; 1041c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom found = true; 1042b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam break; 1043b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1044b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1045b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1046b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1047c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!found) 1048b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1049b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 1050b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1051b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1052b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1053b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return true; 1054b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1055c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1056c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private boolean equivalentStrings(String s1, String s2) 1057b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1058c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String value = canonicalize(s1); 1059c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String oValue = canonicalize(s2); 1060c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1061c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!value.equals(oValue)) 1062c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1063c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom value = stripInternalSpaces(value); 1064c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom oValue = stripInternalSpaces(oValue); 1065b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1066c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!value.equals(oValue)) 1067c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1068c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return false; 1069c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1070c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1071c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1072c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return true; 1073c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1074c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1075c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private String canonicalize(String s) 1076c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1077c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String value = Strings.toLowerCase(s.trim()); 1078c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1079c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (value.length() > 0 && value.charAt(0) == '#') 1080b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1081c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DERObject obj = decodeObject(value); 1082c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1083c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (obj instanceof DERString) 1084c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1085c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom value = Strings.toLowerCase(((DERString)obj).getString().trim()); 1086c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1087b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1088b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1089c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return value; 1090c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1091c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1092c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private ASN1Object decodeObject(String oValue) 1093c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1094c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom try 1095c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1096c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return ASN1Object.fromByteArray(Hex.decode(oValue.substring(1))); 1097c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1098c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom catch (IOException e) 1099c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1100c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throw new IllegalStateException("unknown encoding in name: " + e); 1101c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1102c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1103c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1104c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom private String stripInternalSpaces( 1105c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String str) 1106c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1107c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom StringBuffer res = new StringBuffer(); 1108c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1109c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (str.length() != 0) 1110c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1111c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom char c1 = str.charAt(0); 1112c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1113c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom res.append(c1); 1114c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1115c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom for (int k = 1; k < str.length(); k++) 1116c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1117c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom char c2 = str.charAt(k); 1118c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!(c1 == ' ' && c2 == ' ')) 1119c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1120c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom res.append(c2); 1121c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1122c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom c1 = c2; 1123c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1124c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1125c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1126c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return res.toString(); 1127b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1128b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1129b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private void appendValue( 1130b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam StringBuffer buf, 1131b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable oidSymbols, 1132b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERObjectIdentifier oid, 1133b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String value) 1134b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1135b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String sym = (String)oidSymbols.get(oid); 1136b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1137b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (sym != null) 1138b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1139b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam buf.append(sym); 1140b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1141b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 1142b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1143b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam buf.append(oid.getId()); 1144b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1145b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1146b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam buf.append('='); 1147b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1148b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam int index = buf.length(); 1149c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1150b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam buf.append(value); 1151b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1152b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam int end = buf.length(); 1153b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1154c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (value.length() >= 2 && value.charAt(0) == '\\' && value.charAt(1) == '#') 1155c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1156c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom index += 2; 1157c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1158c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1159b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam while (index != end) 1160b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1161b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if ((buf.charAt(index) == ',') 1162b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == '"') 1163b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == '\\') 1164b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == '+') 1165c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom || (buf.charAt(index) == '=') 1166b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == '<') 1167b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == '>') 1168b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam || (buf.charAt(index) == ';')) 1169b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1170b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam buf.insert(index, "\\"); 1171b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam index++; 1172b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam end++; 1173b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1174b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1175b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam index++; 1176b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1177b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1178b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1179b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 1180b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * convert the structure to a string - if reverse is true the 1181b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * oids and values are listed out starting with the last element 1182b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in the sequence (ala RFC 2253), otherwise the string will begin 1183b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * with the first element of the structure. If no string definition 1184b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * for the oid is found in oidSymbols the string value of the oid is 1185b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * added. Two standard symbol tables are provided DefaultSymbols, and 1186b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * RFC2253Symbols as part of this class. 1187b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 1188b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param reverse if true start at the end of the sequence and work back. 1189b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param oidSymbols look up table strings for oids. 1190b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 1191b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String toString( 1192b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean reverse, 1193b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Hashtable oidSymbols) 1194b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1195b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam StringBuffer buf = new StringBuffer(); 1196c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom Vector components = new Vector(); 1197b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean first = true; 1198b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1199c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom StringBuffer ava = null; 1200c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1201db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = 0; i < ordering.size(); i++) 1202c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1203db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom if (((Boolean)added.elementAt(i)).booleanValue()) 1204c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1205c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom ava.append('+'); 1206c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom appendValue(ava, oidSymbols, 1207db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom (DERObjectIdentifier)ordering.elementAt(i), 1208db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom (String)values.elementAt(i)); 1209c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1210c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 1211c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 1212c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom ava = new StringBuffer(); 1213c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom appendValue(ava, oidSymbols, 1214db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom (DERObjectIdentifier)ordering.elementAt(i), 1215db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom (String)values.elementAt(i)); 1216c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom components.addElement(ava); 1217c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1218c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 1219c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 1220b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (reverse) 1221b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1222db9f6e2562dff550a3c62aeb7c96e72fc40d1a06Brian Carlstrom for (int i = components.size() - 1; i >= 0; i--) 1223b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1224b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (first) 1225b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1226b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam first = false; 1227b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1228b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 1229b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1230c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom buf.append(','); 1231b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1232b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1233c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom buf.append(components.elementAt(i).toString()); 1234b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1235b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1236b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 1237b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1238c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom for (int i = 0; i < components.size(); i++) 1239b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1240b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (first) 1241b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1242b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam first = false; 1243b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1244b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 1245b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1246c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom buf.append(','); 1247b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1248b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1249c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom buf.append(components.elementAt(i).toString()); 1250b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1251b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1252b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1253b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return buf.toString(); 1254b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1255b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1256b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private String bytesToString( 1257b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam byte[] data) 1258b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1259b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam char[] cs = new char[data.length]; 1260b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1261b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i != cs.length; i++) 1262b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1263b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam cs[i] = (char)(data[i] & 0xff); 1264b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1265b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1266b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new String(cs); 1267b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1268b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 1269b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String toString() 1270b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 1271b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return toString(DefaultReverse, DefaultSymbols); 1272b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 1273b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 1274