X500PrincipalTest.java revision a89311332281f9959ee67b00875ff97230554587
162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath/* 262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * contributor license agreements. See the NOTICE file distributed with 462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * this work for additional information regarding copyright ownership. 562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * (the "License"); you may not use this file except in compliance with 762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * the License. You may obtain a copy of the License at 862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * 962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 1062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * 1162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Unless required by applicable law or agreed to in writing, software 1262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 1362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * See the License for the specific language governing permissions and 1562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * limitations under the License. 1662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 1762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 1862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathpackage org.apache.harmony.tests.javax.security.auth.x500; 1962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport javax.security.auth.x500.X500Principal; 2162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.io.ByteArrayInputStream; 22155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Rootimport java.io.ByteArrayOutputStream; 2362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.io.InputStream; 2462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.security.cert.CertificateFactory; 2562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.security.cert.X509Certificate; 2662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.util.ArrayList; 2762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.util.Arrays; 2862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.util.HashMap; 2962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.util.Locale; 3062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport java.util.Map; 3162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport junit.framework.TestCase; 3262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport org.apache.harmony.testframework.serialization.SerializationTest; 3362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport org.apache.harmony.security.tests.support.cert.TestUtils; 3462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathimport tests.support.resource.Support_Resources; 3562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 3662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 3762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath/** 3862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Tests for <code>X500Principal</code> class constructors and methods. 3962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * 4062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 4162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamathpublic class X500PrincipalTest extends TestCase { 4262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 4362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 4462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#X500Principal(String name) 4562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 4662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_X500Principal_01() { 4762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 4862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 4962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 5062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(name); 5162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull("Null object returned", xpr); 5262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(); 5362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(name, resName); 5462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 5562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 5662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 5762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 5862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 5962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal((String)null); 6062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("NullPointerException wasn't thrown"); 6162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (NullPointerException npe) { 6262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 6362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of NullPointerException"); 6462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 6562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 6662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 6762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal("X500PrincipalName"); 6862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 6962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException npe) { 7062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 7162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of IllegalArgumentException"); 7262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 7362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 7462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 7562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 7662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#X500Principal(InputStream is) 7762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 7862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_X500Principal_02() { 7962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 8062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] ba = getByteArray(TestUtils.getX509Certificate_v1()); 8162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(ba); 8262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath InputStream isNull = null; 8362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 8462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 8562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(is); 8662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull("Null object returned", xpr); 8762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] resArray = xpr.getEncoded(); 8862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(ba.length, resArray.length); 8962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 9062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 9162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 9262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 9362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 9462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(isNull); 9562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("NullPointerException wasn't thrown"); 9662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (NullPointerException npe) { 9762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 9862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of NullPointerException"); 9962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 10062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 10162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath is = new ByteArrayInputStream(name.getBytes()); 10262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 10362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(is); 10462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 10562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException npe) { 10662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 10762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of IllegalArgumentException"); 10862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 10962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 11062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 11162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 11262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#X500Principal(byte[] name) 11362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 11462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_X500Principal_03() { 11562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 11662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] ba = getByteArray(TestUtils.getX509Certificate_v1()); 11762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] baNull = null; 11862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 11962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 12062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(ba); 12162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull("Null object returned", xpr); 12262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] resArray = xpr.getEncoded(); 12362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(ba.length, resArray.length); 12462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 12562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 12662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 12762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 12862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 12962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(baNull); 13062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 13162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException npe) { 13262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 13362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of IllegalArgumentException"); 13462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 13562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 13662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ba = name.getBytes(); 13762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 13862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(ba); 13962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 14062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException npe) { 14162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 14262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(e + " was thrown instead of IllegalArgumentException"); 14362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 14462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 14562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 14662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 14762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#getName() 14862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 14962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_getName() { 15062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 15162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(name); 15262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 15362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(); 15462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(name, resName); 15562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 15662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 15762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 15862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 15962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 16062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 16162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#getName(String format) 16262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 16362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_getName_Format() { 16462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 16562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expectedName = "cn=duke,ou=javasoft,o=sun microsystems,c=us"; 16662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(name); 16762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 16862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(X500Principal.CANONICAL); 16962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(expectedName, resName); 17062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 17162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 17262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 17362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 17462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath expectedName = "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"; 17562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 17662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(X500Principal.RFC1779); 17762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(expectedName, resName); 17862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 17962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 18062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 18162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 18262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 18362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(X500Principal.RFC2253); 18462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(name, resName); 18562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 18662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 18762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 18862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 18962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 19062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName(null); 19162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 19262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException iae) { 19362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 19462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 19562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String resName = xpr.getName("RFC2254"); 19662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("IllegalArgumentException wasn't thrown"); 19762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException iae) { 19862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 19962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 20062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 20162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 20262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#hashCode() 20362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 20462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_hashCode() { 20562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US"; 20662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(name); 20762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 20862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath int res = xpr.hashCode(); 20962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull(res); 21062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 21162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 21262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 21362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 21462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 21562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 21662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#toString() 21762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 21862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_toString() { 21962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"; 22062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(name); 22162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 22262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String res = xpr.toString(); 22362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull(res); 22462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(name, res); 22562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 22662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 22762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 22862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 22962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 23062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 23162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#getEncoded() 23262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 23362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_getEncoded() { 23462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] ba = getByteArray(TestUtils.getX509Certificate_v1()); 23562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr = new X500Principal(ba); 23662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 23762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] res = xpr.getEncoded(); 23862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull(res); 23962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(ba.length, res.length); 24062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 24162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 24262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 24362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 24462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 24562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 24662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * javax.security.auth.x500.X500Principal#equals(Object o) 24762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 24862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_equals() { 24962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name1 = "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"; 25062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name2 = "cn=duke,ou=javasoft,o=sun microsystems,c=us"; 25162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name3 = "CN=Alex Astapchuk, OU=SSG, O=Intel ZAO, C=RU"; 25262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr1 = new X500Principal(name1); 25362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr2 = new X500Principal(name2); 25462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xpr3 = new X500Principal(name3); 25562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 25662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue("False returned", xpr1.equals(xpr2)); 25762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertFalse("True returned", xpr1.equals(xpr3)); 25862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 25962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Unexpected exception: " + e); 26062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 26162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 26262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 26362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private byte[] getByteArray(byte[] array) { 26462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] x = null; 26562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 26662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(array); 26762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath CertificateFactory cf = CertificateFactory.getInstance("X.509"); 26862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X509Certificate cert = (X509Certificate)cf.generateCertificate(is); 26962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xx = cert.getIssuerX500Principal(); 27062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath x = xx.getEncoded(); 27162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 27262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath return null; 27362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 27462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath return x; 27562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 27662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 27762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 27862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @tests javax.security.auth.x500.X500Principal#X500Principal(java.lang.String) 27962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 28062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_ConstructorLjava_lang_String() { 28162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal( 28262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=Hermione Granger, O=Apache Software Foundation, OU=Harmony, L=Hogwarts, ST=Hants, C=GB"); 28362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = principal.getName(); 28462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expectedOuput = "CN=Hermione Granger,O=Apache Software Foundation,OU=Harmony,L=Hogwarts,ST=Hants,C=GB"; 28562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("Output order precedence problem", expectedOuput, name); 28662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 28762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 28862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 28962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @tests javax.security.auth.x500.X500Principal#X500Principal(java.lang.String, java.util.Map) 29062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 29162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_ConstructorLjava_lang_String_java_util_Map() { 29262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Map<String, String> keyword = new HashMap<String, String>(); 29362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("CN", "2.19"); 29462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("OU", "1.2.5.19"); 29562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("O", "1.2.5"); 29662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal X500p = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US ,CN=DD", keyword); 29762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String name = X500p.getName(); 29862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expectedOut = "2.19=#130444756b65,1.2.5.19=#13084a617661536f6674,1.2.5=#131053756e204d6963726f73797374656d73,C=US,2.19=#13024444"; 29962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("Output order precedence problem", expectedOut, name); 30062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 30162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 30262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 30362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @tests javax.security.auth.x500.X500Principal#getName(java.lang.String) 30462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 30562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_getNameLjava_lang_String() { 30662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal( 30762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=Dumbledore, OU=Administration, O=Hogwarts School, C=GB"); 30862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical = principal.getName(X500Principal.CANONICAL); 30962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expected = "cn=dumbledore,ou=administration,o=hogwarts school,c=gb"; 31062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CANONICAL output differs from expected result", expected, 31162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath canonical); 31262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 31362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 31462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 31562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @tests javax.security.auth.x500.X500Principal#getName(java.lang.String, java.util.Map) 31662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 31762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_getNameLjava_lang_String_java_util_Map() { 31862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Map<String, String> keyword = new HashMap<String, String>(); 31962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("CN", "2.19"); 32062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("OU", "1.2.5.19"); 32162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("O", "1.2.5"); 32262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal X500p = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US ,CN=DD", keyword); 32362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword = new HashMap<String, String>(); 32462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath keyword.put("2.19", "mystring"); 32562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc1779Name = X500p.getName("RFC1779", keyword); 32662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc2253Name = X500p.getName("RFC2253", keyword); 32762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expected1779Out = "mystring=Duke, OID.1.2.5.19=JavaSoft, OID.1.2.5=Sun Microsystems, C=US, mystring=DD"; 32862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String expected2253Out = "mystring=Duke,1.2.5.19=#13084a617661536f6674,1.2.5=#131053756e204d6963726f73797374656d73,C=US,mystring=DD"; 32962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("Output order precedence problem", expected1779Out, rfc1779Name); 33062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("Output order precedence problem", expected2253Out, rfc2253Name); 33162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 33262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500p.getName("CANONICAL", keyword); 33362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("Should throw IllegalArgumentException exception here"); 33462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 33562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //expected IllegalArgumentException here 33662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 33762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 33862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 33962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private boolean testing = false; 34062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 34162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamPosition() throws Exception { 34262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //this encoding is read from the file 34362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /*byte [] mess = {0x30, 0x30, 34462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 34562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 34662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 1, 2, 3//extra bytes 34762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath }; 34862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 34962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 35062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath InputStream is = Support_Resources 35162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getResourceStream("X500PrincipalTest.0.dat"); 35262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 35362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.toString(); 35462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=B, CN=A, CN=B", s); 35562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] restBytes = new byte[] { 0, 0, 0 }; 35662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath is.read(restBytes); 35762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(restBytes[0], 1); 35862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(restBytes[1], 2); 35962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(restBytes[2], 3); 36062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath is.close(); 36162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 36262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 36362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamPosition_0() throws Exception { 36462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //this encoding is read from the file 36562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /*byte [] mess = {0x30, 0x30, 36662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 36762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 36862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath }; 36962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 37062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 37162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath InputStream is = Support_Resources 37262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getResourceStream("X500PrincipalTest.1.dat"); 37362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 37462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.toString(); 37562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=B, CN=A, CN=B", s); 37662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(0, is.available()); 37762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath is.close(); 37862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 37962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 38062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamPosition_1() throws Exception { 38162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 38262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 38362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 38462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 38562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 38662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 38762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 38862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 38962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 39062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 39162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 39262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 39362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 39462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 39562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 39662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 2, 39762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 3, 4 }; 39862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 39962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 40062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 40162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 40262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 40362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 40462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z", 40562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath s); 40662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(3, is.available()); 40762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(2, is.read()); 40862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(3, is.read()); 40962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(4, is.read()); 41062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 41162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 41262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamPosition_2() throws Exception { 41362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 41462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x41, 2 }; 41562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 41662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 41762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 41862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A", s); 41962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(1, is.available()); 42062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(2, is.read()); 42162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 42262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 42362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEncodingFromFile() throws Exception { 42462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //this encoding is read from the file 42562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /*byte [] mess = {0x30, 0x30, 42662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 42762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 42862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath }; 42962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 43062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath InputStream is = Support_Resources 43162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getResourceStream("X500PrincipalTest.1.dat"); 43262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 43362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.toString(); 43462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=B, CN=A, CN=B", s); 43562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath is.close(); 43662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 43762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 43862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEncodingFromEncoding() { 43962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] arr1 = new X500Principal("O=Org.").getEncoded(); 44062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] arr2 = new X500Principal(new X500Principal("O=Org.") 44162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getEncoded()).getEncoded(); 44262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(arr1, arr2)); 44362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 44462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 44562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 44662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * tests if the encoding is backed 44762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 44862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSafeEncoding() { 44962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 45062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x41 }; 45162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 45262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[mess.length - 1] = (byte) 0xFF; 45362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 45462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(enc[mess.length - 1], 0x41); 45562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 45662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 45762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 45862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 45962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets toString 46062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks the result 46162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 46262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testToString() throws Exception { 46362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 46462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 46562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 46662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 46762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.toString(); 46862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertNotNull(s); 46962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 47062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 47162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 47262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 47362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets hashCode 47462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 47562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 47662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testHashCode() throws Exception { 47762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 47862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 47962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 48062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 48162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath int hash = principal.hashCode(); 48262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals(principal.getName(X500Principal.CANONICAL).hashCode(), 48362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath hash); 48462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 48562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 48662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 48762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 48862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with equivalent string 48962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if <code>equals</code> returns true for first against second one 49062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 49162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEquals() throws Exception { 49262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 49362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 49462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 49562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 49662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal("CN=A, CN=B"); 49762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(principal.equals(principal2)); 49862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 49962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 50062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 50162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @tests javax.security.auth.x500.X500Principal#equals(Object) 50262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 50362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void test_equalsLjava_lang_Object() { 50462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal xp1 = new X500Principal( 50562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "C=US, ST=California, L=San Diego, O=Apache, OU=Project Harmony, CN=Test cert"); 50662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 50762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "C=US,ST=California,L=San Diego,O=Apache,OU=Project Harmony,CN=Test cert", 50862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath xp1.getName()); 50962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 51062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 51162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 51262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword 51362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Value is given as hex value 51462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * (extra spaces are given) 51562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 51662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 51762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 51862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testKWAsOid_RFC1779() throws Exception { 51962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A, OID.2.5.4.3 = #130142"; 52062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 52162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 52262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 52362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=B", s); 52462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 52562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 52662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 52762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword 52862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Value is given as hex value 52962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * (extra spaces are given) 53062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 53162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 53262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 53362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testKWAsOid_RFC2253() throws Exception { 53462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A, OID.2.5.4.3 = #130142"; 53562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 53662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 53762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 53862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,CN=B", s); 53962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 54062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 54162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 54262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword 54362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Value is given as hex value 54462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * (extra spaces are given) 54562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 54662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 54762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 54862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testKWAsOid_CANONICAL() throws Exception { 54962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A, OID.2.5.4.3 = #130142"; 55062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 55162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 55262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 55362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,cn=b", s); 55462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 55562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 55662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 55762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does not fall into any keyword 55862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 55962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 56062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 56162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testOid_RFC1779() throws Exception { 56262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 56362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 56462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 56562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[8] = 0x60; 56662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 56762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 56862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 56962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, OID.2.16.4.3=B", s); 57062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 57162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 57262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 57362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does not fall into any keyword 57462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 57562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 57662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 57762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testOid_RFC2253() throws Exception { 57862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 57962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x4F, 0x31, 0x0A, 0x30, 0x08, 0x06, 58062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 58162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[8] = 0x60; 58262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 58362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 58462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 58562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,2.16.4.3=#13014f", s); 58662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 58762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 58862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 58962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where Oid does not fall into any keyword 59062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 59162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 59262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 59362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testOid_CANONICAL() throws Exception { 59462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 59562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x4F, 0x31, 0x0A, 0x30, 0x08, 0x06, 59662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 59762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[8] = 0x60; 59862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 59962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 60062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 60162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,2.16.4.3=#13014f", s); 60262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 60362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 60462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 60562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string 60662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoded form 60762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected byte array 60862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 60962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameGetEncoding() throws Exception { 61062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 61162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 61262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 61362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 61462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 61562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 61662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 61762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 61862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 61962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 62062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 62162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 62262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 62362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 62462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 62562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 62662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z"; 62762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 62862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] s = principal.getEncoded(); 62962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 63062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(mess, s)); 63162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 63262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 63362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 63462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string 63562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoded form 63662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected byte array 63762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 63862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameGetEncoding_01() throws Exception { 63962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 64062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 64162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 64262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B"; 64362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 64462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] s = principal.getEncoded(); 64562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 64662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(mess, s)); 64762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 64862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 64962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 65062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 65162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 65262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 65362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 65462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_RFC1779() throws Exception { 65562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 65662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 65762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 65862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 65962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 66062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 66162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 66262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 66362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 66462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 66562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 66662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 66762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 66862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 66962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 67062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 67162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 67262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 67362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 67462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 67562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z", 67662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath s); 67762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 67862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 67962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 68062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 68162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 68262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 68362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 68462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 68562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_RFC2253() throws Exception { 68662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 68762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 68862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 68962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 69062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 69162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 69262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 69362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 69462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 69562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 69662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 69762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 69862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 69962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 70062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 70162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 70262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 70362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 70462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 70562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 70662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z", 70762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath s); 70862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 70962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 71062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 71162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 71262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 71362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 71462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 71562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL() throws Exception { 71662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 71762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 71862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 71962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 72062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 72162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 72262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 72362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 72462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 72562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 72662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 72762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 72862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 72962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 73062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 73162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 73262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 73362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 73462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 73562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 73662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z" 73762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .toLowerCase(Locale.US), s); 73862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 73962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 74062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 74162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 74262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 74362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 74462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 74562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamGetName_RFC1779() throws Exception { 74662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 74762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 74862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 74962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 75062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 75162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 75262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 75362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 75462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 75562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 75662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 75762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 75862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 75962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 76062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 76162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 76262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 76362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 76462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 76562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 76662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 76762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z", 76862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath s); 76962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 77062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 77162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 77262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 77362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 77462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 77562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 77662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamGetName_RFC2253() throws Exception { 77762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 77862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 77962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 78062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 78162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 78262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 78362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 78462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 78562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 78662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 78762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 78862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 78962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 79062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 79162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 79262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 79362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 79462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 79562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 79662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 79762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 79862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z", 79962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath s); 80062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 80162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 80262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 80362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array 80462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 80562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 80662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 80762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testStreamGetName_CANONICAL() throws Exception { 80862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A, 0x30, 0x08, 80962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 0x31, 0x0A, 81062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 81162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 81262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 81362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 81462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 81562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 81662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31, 81762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 81862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 81962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 82062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 82162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 82262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 82362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 }; 82462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 82562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(is); 82662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 82762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 82862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals( 82962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z" 83062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .toLowerCase(Locale.US), s); 83162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 83262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 83362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 83462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, where OID does not fall into any keyword 83562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoded form 83662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * inits new X500Principal with the encoding 83762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC1779 format 83862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 83962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 84062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_RFC1779() 84162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 84262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B; CN=A"; 84362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 84462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 84562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 84662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.RFC1779); 84762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("OID.2.16.4.3=B, CN=A", s); 84862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 84962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 85062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 85162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 85262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, where OID does not fall into any keyword 85362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoded form 85462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * inits new X500Principal with the encoding 85562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC2253 format 85662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 85762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 85862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_RFC2253() 85962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 86062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B; CN=A"; 86162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 86262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 86362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 86462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.RFC2253); 86562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4.3=#130142,CN=A", s); 86662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 86762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 86862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 86962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 87062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, where OID does not fall into any keyword 87162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoded form 87262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * inits new X500Principal with the encoding 87362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 87462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 87562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 87662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_CANONICAL() 87762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 87862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B; CN=A"; 87962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 88062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 88162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 88262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.CANONICAL); 88362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4.3=#130142,cn=a", s); 88462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 88562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 88662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 88762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 88862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, where OID does not fall into any keyword 88962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC1779 format 89062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 89162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 89262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_wrongOidButGoodName_RFC1779() throws Exception { 89362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 89462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 89562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 89662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 89762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("OID.2.16.4.3=B + CN=A", s); 89862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 89962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 90062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 90162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, where OID does not fall into any keyword 90262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC2253 format 90362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value 90462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 90562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_wrongOidButGoodName_RFC2253() throws Exception { 90662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 90762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 90862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 90962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 91062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4.3=#130142+CN=A", s); 91162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 91262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 91362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 91462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs 91562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 91662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 91762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 91862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder() throws Exception { 91962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "ST=C + CN=A; OU=B + CN=D"; 92062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 92162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 92262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 92362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a+st=c,cn=d+ou=b", s); 92462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 92562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 92662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 92762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 92862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 92962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 93062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 93162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 93262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_01() throws Exception { 93362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 93462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 93562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 93662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 93762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a+2.16.4.3=#130142", s); 93862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 93962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 94062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 94162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 94262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword, and value given in hex format 94362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 94462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 94562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 94662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_02() throws Exception { 94762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=#13024220+ CN=A"; 94862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 94962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 95062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 95162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a+2.16.4.3=#13024220", s); 95262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 95362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 95462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 95562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 95662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword 95762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 95862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 95962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 96062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_03() throws Exception { 96162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.9=A + OID.2.16.4.3=B"; 96262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 96362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 96462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 96562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4.3=#130142+2.16.4.9=#130141", s); 96662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 96762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 96862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 96962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 97062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword 97162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 97262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 97362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 97462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_04() throws Exception { 97562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.2.2.2=A + OID.1.1.1.1=B"; 97662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 97762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 97862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 97962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("1.1.1.1=#130142+2.2.2.2=#130141", s); 98062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 98162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 98262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 98362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 98462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword 98562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 98662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 98762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 98862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_05() throws Exception { 98962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.9=A + OID.2.16.4=B"; 99062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 99162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 99262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 99362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4=#130142+2.16.4.9=#130141", s); 99462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 99562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 99662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 99762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 99862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword 99962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 100062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 100162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 100262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_06() throws Exception { 100362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.1.1.2=A + OID.1.2=B"; 100462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 100562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 100662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 100762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("1.1.2=#130141+1.2=#130142", s); 100862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 100962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 101062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 101162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 101262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword 101362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 101462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 101562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 101662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_CANONICAL_SortOrder_07() throws Exception { 101762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.1.1.1=A + OID.1.1=B"; 101862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 101962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 102062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 102162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("1.1=#130142+1.1.1=#130141", s); 102262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 102362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 102462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 102562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 102662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * FIXME test is failed - implement unicode normalization 102762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * 102862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * @throws Exception 102962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 103062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetNameUnicodeNormalized() throws Exception { 103162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String unicodeStr = "CN= \u0401\u0410"; 103262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(unicodeStr); 103362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath principal.getName(X500Principal.CANONICAL); 103462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 103562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 103662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 103762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with empty string 103862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 103962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 104062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 104162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEmptyInputName() { 104262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"\""; 104362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0B, 0x31, 0x09, 0x30, 0x07, 0x06, 0x03, 0x55, 104462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x00 }; 104562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 104662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(mess, principal.getEncoded())); 104762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 104862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 104962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 105062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string as single escaped space 105162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 105262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 105362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 105462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSingleEscapedSpace() { 105562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ "; 105662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 105762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x20 }; 105862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 105962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(mess, principal.getEncoded())); 106062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 106162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 106262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 106362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string with spaces 106462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 106562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 106662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 106762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameOnlySpaces_RFC1779() { 106862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\" \""; 106962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 107062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\" \"", principal.getName(X500Principal.RFC1779)); 107162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 107262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 107362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 107462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string with spaces 107562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 107662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 107762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 107862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameOnlySpaces_RFC2253() { 107962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\" \""; 108062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 108162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\ \\ ", principal.getName(X500Principal.RFC2253)); 108262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 108362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 108462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 108562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string with only spaces, 108662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format:leading and trailing white space 108762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * chars are removed even string doesn't have other chars (bug???) 108862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 108962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameOnlySpaces_CANONICAL() { 109062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\" \""; 109162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 109262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=", principal.getName(X500Principal.CANONICAL)); 109362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 109462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 109562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ///*** Negative Tests ***/// 109662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 109762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 109862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where DN name is improper "CNN" 109962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 110062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 110162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName() { 110262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 110362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CNN=A"; 110462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 110562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper input name \"CNN\""); 110662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 110762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 110862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 110962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 111062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 111162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where there is leading ';' 111262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 111362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 111462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_01() { 111562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 111662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = ";CN=A"; 111762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 111862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on leading ';' in input name"); 111962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 112062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 112162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 112262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 112362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 112462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where there is leading '=' 112562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 112662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 112762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_02() { 112862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 112962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "=CN=A"; 113062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 113162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on leading '=' in input name"); 113262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 113362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 113462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 113562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 113662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 113762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where there is no value 113862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 113962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 114062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEmptyInputName_0() { 114162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN="; 114262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0B, 0x31, 0x09, 0x30, 0x07, 0x06, 0x03, 0x55, 114362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x00 }; 114462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 114562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(mess, principal.getEncoded())); 114662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 114762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 114862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEmptyInputName_1() { 114962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"\", C=\"\""; 115062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 115162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath dn = "CN=, C="; 115262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(dn); 115362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(principal.getEncoded(), principal2 115462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getEncoded())); 115562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 115662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 115762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 115862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testEmptyInputName_2() { 115962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"\" + OU=A, C=\"\""; 116062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 116162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath dn = "CN=+OU=A, C="; 116262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(dn); 116362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(principal.getEncoded(), principal2 116462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getEncoded())); 116562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 116662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 116762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 116862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_15() { 116962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 117062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=,C"; 117162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 117262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute value"); 117362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 117462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 117562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 117662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 117762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_16() { 117862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 117962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=,C=+"; 118062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 118162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute value"); 118262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 118362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 118462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 118562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 118662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 118762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given in wrong hex format 118862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 118962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 119062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_04() { 119162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 119262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#XYZ"; 119362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 119462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper hex value"); 119562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 119662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 119762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 119862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 119962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 120062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 120162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 120262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 120362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_05() { 120462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 120562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X+YZ"; 120662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 120762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute value"); 120862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 120962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 121062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 121162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 121262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 121362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 121462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Compatibility issue: according RFC 2253 such string is invalid 121562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * but we accept it, not string char is escaped 121662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 121762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_06() { 121862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X=YZ"; 121962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p = new X500Principal(dn); 122062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=X\\=YZ", p.getName(X500Principal.RFC2253)); 122162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 122262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 122362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 122462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with not string chars 122562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Compatibility issue: according RFC 2253 such string is invalid 122662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * but we accept it, not string char is escaped 122762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 122862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_07() { 122962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X\"YZ"; 123062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p = new X500Principal(dn); 123162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=X\\\"YZ", p.getName(X500Principal.RFC2253)); 123262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 123362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 123462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 123562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 123662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Compatibility issue: according RFC 2253 such string is invalid 123762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * but we accept it, special char is escaped 123862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 123962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_08() { 124062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X<YZ"; 124162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p = new X500Principal(dn); 124262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=X\\<YZ", p.getName(X500Principal.RFC2253)); 124362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 124462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 124562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 124662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 124762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 124862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 124962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_09() { 125062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 125162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#"; 125262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 125362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute hex value"); 125462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 125562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //ignore 125662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 125762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 125862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 125962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 126062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 126162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 126262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 126362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 126462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_10() { 126562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 126662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#13"; 126762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 126862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute hex value"); 126962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 127062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //ignore 127162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 127262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 127362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 127462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 127562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 127662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 127762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 127862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 127962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_11() { 128062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 128162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#1301"; 128262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 128362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute hex value"); 128462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 128562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //ignore 128662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 128762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 128862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 128962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 129062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 129162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 129262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 129362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 129462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_12() { 129562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 129662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#13010101"; 129762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 129862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute hex value"); 129962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 130062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 130162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 130262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 130362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 130462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given with special chars 130562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 130662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 130762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputName_13() { 130862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 130962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=# 0"; 131062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 131162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper attribute hex value"); 131262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 131362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 131462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 131562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 131662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 131762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string, where value is given in hex format, but improper tag 131862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if it is ignored 131962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 132062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSemiIllegalInputName_14() { 132162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=#7E0142"; 132262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 132362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 132462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 132562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testInitClause() { 132662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 132762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 132862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 132962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 133062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[3] = 0x12;//length field 133162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 133262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 133362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length field"); 133462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 133562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 133662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 133762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 133862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 133962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array = null 134062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 134162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 134262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_0() { 134362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 134462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = null; 134562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 134662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length field"); 134762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 134862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 134962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 135062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 135162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 135262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong length field 135362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 135462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 135562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray() { 135662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 135762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 135862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 135962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 136062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[3] = 0x12;//length field 136162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 136262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 136362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length field"); 136462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 136562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 136662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 136762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 136862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 136962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with input stream with wrong length field 137062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 137162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 137262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_is() { 137362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 137462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 137562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 137662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 137762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[3] = 0x12;//length field 137862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 137962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(is); 138062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 138162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length field"); 138262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 138362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 138462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 138562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 138662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 138762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong inner Sequence tag field 138862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 138962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 139062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_01() { 139162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 139262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 139362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 139462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 139562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[4] = 0x12;//inner Sequence tag field 139662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 139762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 139862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper inner Sequence tag field"); 139962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 140062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 140162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 140262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 140362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 140462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong last byte of OID 140562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 140662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 140762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_02() { 140862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 140962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 141062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 141162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 141262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[10] = (byte) 0xFE;//last byte of OID 141362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 141462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 141562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper last byte of OID"); 141662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 141762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 141862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 141962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 142062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 142162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong length of OID 142262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 142362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 142462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_03() { 142562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 142662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 142762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 142862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 142962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[7] = 2;//length of OID 143062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 143162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 143262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length of OID"); 143362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 143462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 143562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 143662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 143762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 143862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong tag of value 143962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if it is ignored 144062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 144162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSemiIllegalInputArray_04() { 144262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 144362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 144462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 144562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[11] = (byte) 0x0F;//tag of value 144662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 144762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 144862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 144962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 145062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array with wrong length of value 145162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 145262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 145362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_05() { 145462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 145562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 145662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 145762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 145862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[12] = 2;//length of value 145962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(mess); 146062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 146162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length of value"); 146262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 146362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 146462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 146562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 146662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 146762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with input stream with wrong length of value 146862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 146962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 147062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalInputArray_05_is() { 147162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 147262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 147362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 147462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 }; 147562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath mess[12] = 2;//length of value 147662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ByteArrayInputStream is = new ByteArrayInputStream(mess); 147762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(is); 147862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 147962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on input array with improper length of value"); 148062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 148162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 148262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 148362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 148462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 148562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with string 148662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Calls getName with improper parameter as format 148762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if proper exception is thrown 148862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 148962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testIllegalFormat() { 149062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 149162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A"; 149262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 149362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath principal.getName("WRONG FORMAT"); 149462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper parameter as format"); 149562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 149662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 149762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 149862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 149962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 150062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 150162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Gets encoding 150262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with the encoding 150362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC1779 format 150462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 150562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 150662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_RFC1779() 150762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 150862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 150962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 151062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 151162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 151262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.RFC1779); 151362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("OID.2.16.4.3=B + CN=A", s); 151462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 151562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 151662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 151762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 151862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 151962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Gets encoding 152062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with the encoding 152162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC2253 format 152262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 152362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 152462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_RFC2253() 152562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 152662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 152762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 152862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 152962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 153062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.RFC2253); 153162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("2.16.4.3=#130142+CN=A", s); 153262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 153362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 153462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 153562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 153662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 153762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Gets encoding 153862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with the encoding 153962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 154062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 154162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 154262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_CANONICAL() 154362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 154462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 154562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 154662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 154762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 154862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.CANONICAL); 154962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a+2.16.4.3=#130142", s); 155062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 155162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 155262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 155362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 155462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 155562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 155662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 155762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 155862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_RFC1779() throws Exception { 155962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 156062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 156162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 156262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 156362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\" A \"", s); 156462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 156562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 156662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 156762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 156862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 156962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 157062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 157162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 157262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_RFC2253() throws Exception { 157362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 157462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 157562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 157662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 157762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\ A\\ ", s); 157862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 157962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 158062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 158162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 158262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 158362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 158462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 158562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 158662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_CANONICAL() throws Exception { 158762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 158862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 158962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 159062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 159162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a", s); 159262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 159362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 159462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 159562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 159662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 159762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 159862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the string is in quotes 159962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 160062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_RFC1779() throws Exception { 160162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 160262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 160362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 160462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 160562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\";,\"", s); 160662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 160762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 160862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 160962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 161062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 161162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 161262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the characters are escaped 161362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 161462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_RFC2253() throws Exception { 161562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 161662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 161762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 161862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 161962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\;\\,", s); 162062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 162162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 162262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 162362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 162462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 162562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 162662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the characters are escaped 162762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 162862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_CANONICAL() throws Exception { 162962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 163062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 163162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 163262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 163362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\;\\,", s); 163462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 163562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 163662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 163762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 163862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 163962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 164062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 164162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 164262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779() throws Exception { 164362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 164462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 164562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 164662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=\"\\\"B\"", s); 164762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 164862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 164962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 165062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 165162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 165262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 165362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 165462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 165562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253() throws Exception { 165662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 165762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 165862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 165962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,CN=\\\"B", s); 166062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 166162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 166262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 166362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 166462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 166562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 166662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\b" 166762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 166862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL() throws Exception { 166962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 167062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 167162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 167262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,cn=\\\"b", s); 167362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 167462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 167562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 167662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 167762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 167862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 167962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\nB" 168062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 168162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_01() throws Exception { 1682a89311332281f9959ee67b00875ff97230554587Sergio Giro String dn = "CN=\\\nB"; 1683a89311332281f9959ee67b00875ff97230554587Sergio Giro X500Principal principal = new X500Principal(dn); 1684a89311332281f9959ee67b00875ff97230554587Sergio Giro String s = principal.getName(X500Principal.RFC1779); 1685a89311332281f9959ee67b00875ff97230554587Sergio Giro assertEquals("CN=\"\nB\"", s); 168662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 168762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 168862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 168962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 169062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 169162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\nB 169262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 169362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_01() throws Exception { 1694a89311332281f9959ee67b00875ff97230554587Sergio Giro X500Principal p = new X500Principal("CN=\\\nB"); 1695a89311332281f9959ee67b00875ff97230554587Sergio Giro assertEquals("CN=\nB", p.getName(X500Principal.RFC2253)); 169662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 169762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 169862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 169962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 170062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 170162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\nb 170262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 170362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_01() throws Exception { 170462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME testNameSpecialChars_RFC2253_01 170562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String dn = "CN=\\\nB"; 170662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // X500Principal principal = new X500Principal(dn); 170762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String s = principal.getName(X500Principal.CANONICAL); 170862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // assertEquals("cn=b", s); 170962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 171062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 171162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 171262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 171362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 171462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 171562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 171662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 171762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_02() throws Exception { 171862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 171962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 172062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 172162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"\\\\B\"", s); 172262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 172362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 172462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 172562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 172662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 172762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 172862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\B 172962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 173062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_02() throws Exception { 173162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 173262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 173362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 173462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\\\B", s); 173562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 173662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 173762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 173862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 173962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 174062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 174162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\b 174262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 174362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_02() throws Exception { 174462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 174562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 174662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 174762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\\\b", s); 174862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 174962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 175062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 175162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 175262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 175362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 175462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 175562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 175662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation() throws Exception { 175762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 175862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 175962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 176062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 176162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(new byte[] { 0x30, 0x11, 0x31, 0x0F, 0x30, 176262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0D, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06, 0x41, 0x42, 176362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x43, 0x44, 0x45, 0x46 }, enc)); 176462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 176562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 176662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 176762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 176862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "ABCDEF 176962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if the proper exception is thrown 177062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 177162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_01() throws Exception { 177262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF"; 177362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 177462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 177562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on string with no closing quotations"); 177662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 177762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 177862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 177962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 178062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 178162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 178262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 178362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 178462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 178562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_02() throws Exception { 178662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 178762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 178862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 178962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(new byte[] { 0x30, 0x12, 0x31, 0x10, 0x30, 179062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0E, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x07, 0x41, 0x42, 179162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x43, 0x44, 0x23, 0x45, 0x46 }, enc)); 179262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 179362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 179462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 179562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 179662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Compatibility issue: according RFC 2253 such string is invalid 179762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * but we accept it, not string char is escaped 179862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 179962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_03() throws Exception { 180062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=ABC\"DEF\""; 180162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 180262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABC\\\"DEF\\\"", principal 180362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getName(X500Principal.RFC2253)); 180462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 180562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 180662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 180762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 180862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 180962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "ABCDEF" 181062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 181162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_03() throws Exception { 181262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 181362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 181462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 181562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCDEF", s); 181662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 181762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 181862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 181962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 182062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 182162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 182262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - ABC"DEF" 182362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 182462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_03() throws Exception { 182562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 182662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 182762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 182862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCDEF", s); 182962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 183062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 183162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 183262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 183362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 183462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 183562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - abc"def" 183662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 183762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_03() throws Exception { 183862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 183962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 184062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 184162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=abcdef", s); 184262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 184362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 184462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 184562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 184662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 184762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 184862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "ABCD#EF" 184962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 185062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_04() throws Exception { 185162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 185262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 185362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 185462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"ABCD#EF\"", s); 185562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 185662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 185762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 185862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 185962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 186062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 186162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - ABCD\#EF 186262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 186362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_04() throws Exception { 186462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 186562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 186662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 186762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCD\\#EF", s); 186862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 186962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 187062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 187162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 187262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 187362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 187462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - abc"d#ef" 187562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 187662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_04() throws Exception { 187762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 187862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 187962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 188062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=abcd#ef", s); 188162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 188262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 188362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 188462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 188562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 188662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 188762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "X#YZ" 188862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 188962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_05() { 189062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 189162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 189262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 189362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 189462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"X#YZ\"", s); 189562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 189662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 189762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 189862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 189962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 190062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 190162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - X\#YZ 190262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 190362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_05() { 190462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 190562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 190662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 190762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 190862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 190962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=X\\#YZ", s); 191062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 191162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 191262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 191362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 191462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 191562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 191662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - x#yz 191762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 191862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_05() { 191962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 192062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 192162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 192262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 192362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=x#yz", s); 192462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 192562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 192662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 192762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 192862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 192962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 193062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="#XYZ" 193162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 193262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_6() throws Exception { 193362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 193462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 193562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 193662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"#XYZ\"", s); 193762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 193862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 193962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 194062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 194162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 194262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 194362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN=\#XYZ 194462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 194562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_6() throws Exception { 194662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 194762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 194862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 194962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\#XYZ", s); 195062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 195162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 195262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 195362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 195462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 195562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - cn=\#xyz 195662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 195762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_6() throws Exception { 195862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 195962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 196062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 196162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\#xyz", s); 196262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 196362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 196462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 196562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 196662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 196762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "B " 196862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 196962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779() throws Exception { 197062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 197162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 197262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 197362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=\"B \"", s); 197462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 197562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 197662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 197762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 197862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 197962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 198062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B\'space' 198162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 198262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253() throws Exception { 198362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 198462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 198562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 198662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,CN=B\\ ", s); 198762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 198862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 198962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 199062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 199162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 199262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 199362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B\ 199462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 199562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL() throws Exception { 199662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 199762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 199862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 199962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,cn=b", s); 200062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 200162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 200262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 200362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 200462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 200562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 200662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "B A" 200762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 200862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779_01() throws Exception { 200962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 201062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 201162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 2012155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root assertEquals("CN=\"B A\"", s); 201362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 201462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 201562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 201662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 201762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 201862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in 2253 format 201962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B'space''space''space'A 202062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 202162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253_01() throws Exception { 202262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 202362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 202462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 202562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=B A", s); 202662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 202762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 202862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 202962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 203062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 203162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 203262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - b'space'a 203362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 203462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL_01() throws Exception { 203562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 203662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 203762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 203862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=b a", s); 203962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 204062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 204162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 204262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 204362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 204462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 204562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - " B" 204662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 204762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779_02() throws Exception { 204862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 204962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 205062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 205162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\" B\"", s); 205262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 205362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 205462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 205562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 205662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 205762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 205862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \'space''space'B 205962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 206062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253_02() throws Exception { 206162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 206262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 206362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 2064155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root assertEquals("CN=\\ \\ B", s); 206562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 206662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 206762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 206862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 206962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 207062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 207162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \'space''space'b 207262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 207362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL_02() throws Exception { 207462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 207562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 207662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 207762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=b", s); 207862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 207962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 208062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 208162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 208262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ""B 208362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if the proper exception is thrown 208462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 208562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu() throws Exception { 208662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"\"B"; 208762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 208862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 208962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper string"); 209062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 209162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 209262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 209362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 209462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 209562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 209662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 209762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\"B" 209862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 209962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC1779_2() throws Exception { 210062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 210162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 210262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 210362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\"B\"", s); 210462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 210562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 210662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 210762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 210862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 210962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\"B 211062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 211162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC2253_2() throws Exception { 211262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 211362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 211462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 211562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\\\"B", s); 211662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 211762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 211862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 211962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 212062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 212162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - a\"b 212262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 212362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_CANONICAL_2() throws Exception { 212462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 212562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 212662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 212762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\\\"b", s); 212862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 212962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 213062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 213162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 213262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 213362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 213462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\"" 213562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 213662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC1779_3() throws Exception { 213762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 213862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 213962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 214062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\"\"", s); 214162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 214262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 214362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 214462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 214562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 214662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\" 214762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 214862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC2253_3() throws Exception { 214962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 215062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 215162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 215262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\\\"", s); 215362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 215462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 215562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 215662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 215762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 215862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\" 215962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 216062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_CANONICAL_3() throws Exception { 216162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 216262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 216362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 216462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\\\"", s); 216562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 216662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 216762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 216862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 216962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\", C=B" 217062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 217162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\", C=B" 217262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 217362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_4() throws Exception { 217462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\", C=B\""; 217562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 217662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 217762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\", C=B\"", s); 217862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 217962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 218062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 218162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 218262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN="A\\", C=B 218362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 218462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="A\\", C=B 218562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 218662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_5() throws Exception { 218762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\\\", C=B"; 218862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 218962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 219062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\\\", C=B", s); 219162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 219262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 219362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 219462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 219562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 219662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 219762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="A\nB" 219862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 219962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_RFC1779() throws Exception { 220062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 220162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 220262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 2203a89311332281f9959ee67b00875ff97230554587Sergio Giro assertEquals("CN=\"A\nB\"", s); 2204a89311332281f9959ee67b00875ff97230554587Sergio Giro } 2205a89311332281f9959ee67b00875ff97230554587Sergio Giro 2206a89311332281f9959ee67b00875ff97230554587Sergio Giro 2207a89311332281f9959ee67b00875ff97230554587Sergio Giro public void testNamePlus_RFC1779() throws Exception { 2208a89311332281f9959ee67b00875ff97230554587Sergio Giro String dn = "CN=A\\+B"; 2209a89311332281f9959ee67b00875ff97230554587Sergio Giro X500Principal principal = new X500Principal(dn); 2210a89311332281f9959ee67b00875ff97230554587Sergio Giro String s = principal.getName(X500Principal.RFC1779); 2211a89311332281f9959ee67b00875ff97230554587Sergio Giro assertEquals("CN=\"A+B\"", s); 221262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 221362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 221462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 221562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 221662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 221762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN=A\nB 221862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 221962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_RFC2253() throws Exception { 222062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 222162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 222262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 222362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\nB", s); 222462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 222562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 222662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 222762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 222862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 222962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - cn=a\nb 223062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 223162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_CANONICAL() throws Exception { 223262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 223362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 223462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 223562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\nb", s); 223662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 223762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 223862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public static final String[] RFC2253_SPECIAL = new String[] { ",", "=", 223962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "+", "<", ">", "#", ";" }; 224062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testValidDN() throws Exception { 224262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath TestList list = new TestList(); 224462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("", "", "", "", new byte[] { 0x30, 0x00 }); // empty RDN sequence 224662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // sequence of RDN: RDN *("," RDN) 224862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A,C=B", "CN=A,C=B", "CN=A, C=B", "cn=a,c=b"); 224962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("C=B,CN=A", "C=B,CN=A", "C=B, CN=A", "c=b,cn=a"); 225062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A,CN=A", "CN=A,CN=A", "CN=A, CN=A", "cn=a,cn=a"); // duplicate RDNs 225162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 225262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // sequence of RDN: RFC 1779 compatibility 225362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A , C=B", "CN=A,C=B", "CN=A, C=B"); 225462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A , C=B", "CN=A,C=B", "CN=A, C=B"); 225562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A;C=B", "CN=A,C=B", "CN=A, C=B"); 225662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A ; C=B", "CN=A,C=B", "CN=A, C=B"); 225762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=A\r,\rC=B", "CN=A,C=B"); // <CR> & comma => comma 225862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(" CN=A,C=B ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end 225962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(" CN=A,C=\"B\" ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end 226062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 226162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // set of ATAV: ATAV *("+" ATAV) 226262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST=CA", "CN=A+ST=CA", "CN=A + ST=CA", "cn=a+st=ca"); 226362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+CN=A", "CN=A+CN=A", "CN=A + CN=A", "cn=a+cn=a"); // duplicate AT 226462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list 226562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .add("2.5.4.3=A+2.5.4.3=A", "CN=A+CN=A", "CN=A + CN=A", 226662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=a+cn=a"); // duplicate AT 226762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 226862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // set of ATAV: RFC 1779 compatibility 226962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A + ST=CA", "CN=A+ST=CA", "CN=A + ST=CA"); 227062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A + ST=CA", "CN=A+ST=CA", "CN=A + ST=CA"); 227162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=A\r+\rST=CA", "CN=A+ST=CA"); // <CR> & '+' => '+' 227262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 227362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // ATAV = AttributeType "=" AttributeValue 227462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A", "CN=A", "CN=A"); 227562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cn=A", "CN=A", "CN=A"); // AT case insensitive 227662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cN=A", "CN=A", "CN=A"); // AT case insensitive 227762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cn=a", "CN=a", "CN=a"); // AT case insensitive 227862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 227962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // ATAV : RFC 1779 compatibility 228062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN = A", "CN=A", "CN=A"); 228162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN = A", "CN=A", "CN=A"); 228262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add("CN\r=\rA", "CN=A"); // <CR> & '=' => '=' 228362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 228462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeType = <name string> | <OID> 228562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // testing OID case : OID => <name string> 228662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // tested all OIDs from RFC 2253 (2.3) and RFC 1779 (Table 1) 228762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 228862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // different variants of 2.5.4.3 (CN) OID 228962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("OID.2.5.4.3=A", "CN=A", "CN=A"); 229062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("oid.2.5.4.3=A", "CN=A", "CN=A"); 229162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.3=A", "CN=A", "CN=A"); 229262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("02.5.4.3=A", "CN=A", "CN=A"); // first: 02 => 2 229362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.0003=A", "CN=A", "CN=A"); // last: 0003 => 3 229462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 229562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // the rest of OIDs 229662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.7=A", "L=A", "L=A", "l=a"); 229762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.8=A", "ST=A", "ST=A", "st=a"); 229862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.10=A", "O=A", "O=A", "o=a"); 229962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.11=A", "OU=A", "OU=A", "ou=a"); 230062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.6=A", "C=A", "C=A", "c=a"); 230162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.9=A", "STREET=A", "STREET=A", "street=a"); 230262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("0.9.2342.19200300.100.1.25=A", "DC=A", 2303155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root "OID.0.9.2342.19200300.100.1.25=A", "dc=#160141"); 230462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("0.9.2342.19200300.100.1.1=A", "UID=A", 230562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "OID.0.9.2342.19200300.100.1.1=A", "uid=a"); 230662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 230762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // attribute types from RFC 2459 (see Appendix A) 230862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // keywords are from the API spec 230962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("T=A", "2.5.4.12=#130141", "OID.2.5.4.12=A", 231062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.12=#130141"); 231162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("DNQ=A", "2.5.4.46=#130141", "OID.2.5.4.46=A", 231262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.46=#130141"); 231362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("DNQUALIFIER=A", "2.5.4.46=#130141", "OID.2.5.4.46=A", 231462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.46=#130141"); 231562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("SURNAME=A", "2.5.4.4=#130141", "OID.2.5.4.4=A", 231662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.4=#130141"); 231762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("GIVENNAME=A", "2.5.4.42=#130141", "OID.2.5.4.42=A", 231862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.42=#130141"); 231962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("INITIALS=A", "2.5.4.43=#130141", "OID.2.5.4.43=A", 232062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.43=#130141"); 232162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("GENERATION=A", "2.5.4.44=#130141", "OID.2.5.4.44=A", 232262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.44=#130141"); 2323155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("EMAILADDRESS=A", "1.2.840.113549.1.9.1=#160141", 2324155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root "OID.1.2.840.113549.1.9.1=A", "1.2.840.113549.1.9.1=#160141", 232562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath null, (byte) 0x05); //FIXME bug??? 232662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("SERIALNUMBER=A", "2.5.4.5=#130141", "OID.2.5.4.5=A", 232762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.5=#130141"); 232862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 232962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue => BER encoding (if OID in dotted-decimal form) 233062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // see RFC 2253 (2.4) 233162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("OID.2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("oid.2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("1.1=A", "1.1=#130141", "OID.1.1=A"); 233562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 233662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 233762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue first alternative : *( stringchar / pair ) 233862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // testing pair characters. 233962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 234062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Note: for RFC1779 quoted string is returned (unspecified) 234162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 234262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=", "CN=", "CN="); // zero string chars 234362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= ", "CN=", "CN="); // zero string chars 234462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST=", "CN=A+ST=", "CN=A + ST="); // zero string chars 234562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=+ST=A", "CN=+ST=A", "CN= + ST=A"); // empty value for 1 RDN 234662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST= ", "CN=A+ST=", "CN=A + ST="); // empty value for 1 RDN 234762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=+ST=", "CN=+ST=", "CN= + ST="); // empty value for both RDNs 234862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=,ST=B", "CN=,ST=B", "CN=, ST=B"); // empty value for 1 RDN 234962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=,ST=", "CN=,ST=", "CN=, ST="); // empty value for both RDNs 235062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=;ST=B", "CN=,ST=B", "CN=, ST=B"); // empty value for 1 RDN 235162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=;ST=", "CN=,ST=", "CN=, ST="); // empty value for both RDNs 235262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 235362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // \special 235462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\" + element, 235562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\" + element, "CN=\"" + element 235662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "\""); 235762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 235862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // A + \special + B 235962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\" + element + "B", "CN=A\\" 236062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 236162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 236262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 236362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 236462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \" 236562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\"", "CN=\\\"", "CN=\"\\\"\"", null, (byte) 0x02); 236662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\"A", "CN=\\\"A", "CN=\"\\\"A\"", null, (byte) 0x02); 236762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\",C=\\\"", "CN=\\\",C=\\\"", "CN=\"\\\"\", C=\"\\\"\"", 236862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath null, (byte) 0x02); // 2 RDN 236962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\\"B", "CN=A\\\"B", "CN=\"A\\\"B\"", null, (byte) 0x02); // A\"B 237062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A ST=B", "CN=A ST\\=B", "CN=\"A ST=B\""); // no RDN separator 237162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 237262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \space 237362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\ ", "CN=\\ ", "CN=\" \"", "cn="); 237462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 237562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \hexpair 237662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41", "CN=A", "CN=A"); // 0x41=='A' 237762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2C", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=',' 237862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2c", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=',' 237962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\D0\\AF", "CN=" + ((char) 1071), "CN=" + ((char) 1071), 238062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 238162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 238262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 238362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet 238462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\D0\\AFA\\41", "CN=" + ((char) 1071) + "AA", "CN=" 238562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F, 0x31, 0x0D, 238662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x03, 238762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 238862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41, 0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet 238962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF-8(0xE090AF) is non-shortest form of UTF-8(0xD0AF) 239062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\E0\\90\\AF", "CN=" + ((char) 1071), "CN=" 239162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 239262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 239362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 239462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); 239562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF-8(0xF08090AF) is non-shortest form of UTF-8(0xD0AF) 239662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\F0\\80\\90\\AF", "CN=" + ((char) 1071), "CN=" 239762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 239862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 239962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 240062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); 240162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\D0", "CN=" + ((char) 65533), "CN=" + ((char) 65533), 240262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 240362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 240462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 240562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x01, 0x3F }); // 0xD0 is not correct UTF8 char => '?' 240662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A' 240762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2C+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=',' 240862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2c+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=',' 240962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 241062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // stringchar '=' or not leading '#' 241162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME RFC 2253 grammar violation: '=' and '#' is a special char 241262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN==", "CN=\\=", "CN=\"=\""); 241362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A=", "CN=A\\=", "CN=\"A=\""); 241462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A#", "CN=A\\#", "CN=\"A#\""); 241562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 241662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // not leading or trailing spaces 241762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A B", "CN=A B", "CN=A B", "cn=a b"); 241862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\ B", "CN=A B", "CN=A B", "cn=a b"); 241962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A \\,B", "CN=A \\,B", "CN=\"A ,B\"", "cn=a \\,b"); 242062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 242162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //not alphabet chars 242262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=$", "CN=$", "CN=$", new byte[] { 0x30, 0x0C, 0x31, 0x0A, 242362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 242462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //UTF-8 String: "$" 242562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x24 }); 242662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=(", "CN=(", "CN=(", new byte[] { 0x30, 0x0C, 0x31, 0x0A, 242762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 242862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //PrintableString: "(" 242962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x28 }); 243062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 243162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue second alternative : "#" hexstring 243462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#130141", "CN=A", "CN=A", "cn=a"); // ASN1 Printable hex string = 'A' 2437155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN=#140141", "CN=A", "CN=A", "cn=a", new byte[] { 0x30, 243862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 243962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x14, 0x01, 0x41 }); // ASN1 Teletex hex string = 'A' 244062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 244162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#010100", "CN=#010100", "CN=#010100", "cn=#010100"); // ASN1 Boolean = FALSE 244262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#0101fF", "CN=#0101ff", "CN=#0101FF", "cn=#0101ff"); // ASN1 Boolean = TRUE 244362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#3000", "CN=#3000", "CN=#3000"); // ASN1 Sequence 244462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#0500", "CN=A", "CN=A"); // ASN1 Null 244562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF", "CN=#0101ff", "CN=#0101FF", // space at beginning 244662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 244762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE 244862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ); 244962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF+ST=A", "CN=#0101ff+ST=A", "CN=#0101FF + ST=A", 245062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=#0101ff+st=a"); //space 245162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF ", "CN=#0101ff", "CN=#0101FF", // space at the end 245262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 245362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE 245462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath , (byte) 0x00); 245562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 245662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME unspecified output for RFC1779 245762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#1C0141", "CN=A", "CN=A"); // ASN1 Universal hex string = 'A' 245862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#1E0141", "CN=A", "CN=A"); // ASN1 Bmp hex string = 'A' 245962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 246062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 246162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : " *( quotechar / pair ) " 246262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // quotechar = <any character except '\' or '"' > 246362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 246462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Note: 246562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RFC2253: passed quoted AV string is unquoted, special chars are escaped 246662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RFC1779: escaped quoted chars are unescaped 246762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 246862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\"", "CN=", "CN="); // empty quoted string 246962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\"", "CN=A", "CN=A"); // "A" 247062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 247162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "special" => \special 247262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"" + element + "\"", "CN=\\" 247362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element, "CN=\"" + element + "\""); 247462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 247562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "A + special + B" => A + \special + B 247662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A" + element + "B\"", "CN=A\\" 247762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 247862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 247962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 248062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 248162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "\special" => \special 248262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\" + element + "\"", "CN=\\" 248362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element, "CN=\"" + element + "\""); 248462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 248562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "A + \special + B" => A + \special + B 248662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\\" + element + "B\"", "CN=A\\" 248762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 248862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 248962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 249062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\\"\"", "CN=\\\"", "CN=\"\\\"\"", null, (byte) 0x02); // "\"" 249162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\\\"B\"", "CN=A\\\"B", "CN=\"A\\\"B\"", null, 249262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x02); // "A\"B" 249362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 249462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \hexpair (test cases are the same as for the first alternative) 249562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\"", "CN=A", "CN=A"); // 0x41=='A' 249662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2C\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=',' 249762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2c\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=',' 249862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\D0\\AF\"", "CN=" + ((char) 1071), "CN=" 249962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 250062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 250162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 250262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet 250362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\D0\\AFA\\41\"", "CN=" + ((char) 1071) + "AA", "CN=" 250462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F, 0x31, 0x0D, 250562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x03, 250662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 250762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41, 0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet 250862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\E0\\90\\AF\"", "CN=" + ((char) 1071), "CN=" 250962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 251062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 251162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 251262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xE090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet 251362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\F0\\80\\90\\AF\"", "CN=" + ((char) 1071), "CN=" 251462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 251562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 251662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 251762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xF08090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet 251862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 251962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\"+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A' 252062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2C\"+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=',' 252162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2c\"+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=',' 252262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 252362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : RFC 1779 compatibility 252462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\"\r\"", "CN=\"\r\""); // "<CR>" 252562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\"\\\r\"", "CN=\"\\\r\""); // "\<CR>" 252662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 252762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue : RFC 1779 compatibility 252862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= A ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces 2529155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN=\\ A ", "CN=\\ \\ A", "CN=\" A\"", "cn=a", null, 253062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x01); // escaped leading space 2531155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN= A \\ ", "CN=A\\ \\ ", "CN=\"A \"", "cn=a", null, 253262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x01); // escaped trailing space 253362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 253462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= \"A\" ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces 253562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 253662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 253762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (int i = 0; i < list.size(); i++) { 253862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 253962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Object[] obj = list.get(i); 254062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 254162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = (String) obj[0]; 254262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc2253 = (String) obj[1]; 254362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc1779 = (String) obj[2]; 254462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical = (String) obj[3]; 254562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded = (byte[]) obj[4]; 254662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte mask = ((byte[]) obj[5])[0]; 254762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 254862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 254962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p = new X500Principal(dn); 255062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) { 255162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x01) == 0)) { 255262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2553155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nRFC2253: " + i); 2554155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append(" \tparm: '" + dn + "'"); 255562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc2253 + "'"); 255662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2557155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.RFC2253) + "'"); 255862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 255962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 256062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 256162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc1779.equals(p.getName(X500Principal.RFC1779))) { 256262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x02) == 0)) { 256362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2564155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nRFC1779: " + i); 2565155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append(" \tparm: '" + dn + "'"); 2566155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\t\texpected: '" + rfc1779 + "'"); 256762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2568155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.RFC1779) + "'"); 256962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 257062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 257162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 257262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (canonical != null) { 257362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!canonical.equals(p.getName(X500Principal.CANONICAL))) { 257462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x04) == 0)) { 257562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2576155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nCANONICAL: " + i); 257762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\tparm: '" + dn + "'"); 2578155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\t\texpected: '" + canonical + "'"); 257962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2580155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.CANONICAL) + "'"); 258162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 258562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (encoded != null) { 258662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!Arrays.equals(encoded, p.getEncoded())) { 258762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x08) == 0)) { 258862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2589155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nUnexpected encoding for: " + i 2590155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + ", dn= '" + dn + "'"); 259162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 259262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath System.out.println("\nI " + i); 259362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = p.getEncoded(); 259462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (byte element : enc) { 259562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath System.out.print(", 0x" 259662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + Integer.toHexString(element)); 259762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 259862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 259962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 2602155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nIllegalArgumentException: " + i); 2603155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\tparm: '" + dn + "'"); 260462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 2605155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nException: " + i); 260662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\tparm: '" + dn + "'"); 2607155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\texcep: " + e.getClass().getName()); 260862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 261262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 261362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testInvalidDN() { 261862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String[] illegalDN = new String[] { 261962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RDN 262062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME " ", // space only 262162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN", // attribute type only 262262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A;", // RFC 1779: BNF allows this, but ... 262362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A,", // RFC 1779: BNF allows this, but ... 262462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ",CN=A", // no AttributeType for first RDN 262562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=,A", // no AttributeType for second RDN 262662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+", // no AttributeTypeAndValue for second RDN 262762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#130141 ST=B", // no RDN separator 262862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 262962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeType = <name string> | <OID> 263062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "AAA=A", // no such <name string> 263162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1..1=A", // wrong OID 263262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ".1.1=A", // wrong OID 263362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "11=A", // wrong OID 263462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1=A", // wrong OID 263562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "AID.1.1=A", // wrong OID 263662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1.50=A", // wrong OID 263762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "5.1.0=A", // wrong OID 263862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.-5.4.3=A", // wrong OID 263962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.-4.3=A", // wrong OID 264062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4-.3=A", // wrong OID 264162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "2.5.4.-3=A", // wrong OID 264262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 264362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue first alternative : *( stringchar / pair ) 264462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=,", // stringchar = ',' 264562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN==", 264662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=+", // stringchar = '+' 264762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=<", // stringchar = '<' 264862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=>", // stringchar = '>' 264962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#", // stringchar = '#' 265062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=Z#", // stringchar = '#' 265162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=;", // stringchar = ';' 265262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"", // stringchar = " 265362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=A\"B", // stringchar = " 265462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\", // stringchar = \ 265562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A\\", // stringchar = \ 265662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A\\B", // stringchar = \ 265762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\z", // invalid pair = \z 265862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4", // invalid pair = \4 265962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4Z", // invalid pair = \4Z 266062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4\\2c", // invalid pair = \4\2c 266162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 266262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue second alternative : "#" hexstring 266362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#", // no hex string 266462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#2", // no hex pair 266562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#22", // hexpair is not BER encoding 266662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#0001", // invalid BER encoding (missed content) 266762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#000201", // invalid BER encoding (wrong length) 266862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#0002010101", // invalid BER encoding (wrong length) 266962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#00FF", // invalid BER encoding (wrong length) 267062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#ZZ", // not hex pair 267162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 267262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME boolean with indefinite length 267362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //"CN=#0100010000", // invalid BER encoding (wrong length) 267462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 267562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : " *( quotechar / pair ) " 267662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"A\" B", // TODO comment me 267762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"A\\", // TODO comment me 267862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4\"", // invalid pair = \4 267962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4Z\"", // invalid pair = \4Z 268062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4\\2c\"", // invalid pair = \4\2c 268162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath }; 268262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 268362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 268462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : illegalDN) { 268562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 268662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 268762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(element); 268862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("No IllegalArgumentException: '" + element 268962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "'\n"); 269062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 269162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 269462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 269562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 269662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 269962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testValidEncoding() { 270062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath TestList list = new TestList(); 270162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 270262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 270362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Empty 270462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 270562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x00 }, "", "", ""); 270662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x02, 0x31, 0x00 }, "", "", ""); //??? invalid size constraints 270762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 270862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 270962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + string with different tags(all string) 271062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 271162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 271262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 271362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString 271462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 271562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 271662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 271762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TeletexString 2718155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x14, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 271962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 272062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 272162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UniversalString 272262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 272362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 272462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 272562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String 272662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 272762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 272862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 272962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // BMPString 273062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 273162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 273262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 273362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Unknown OID + string with different tags(all string) 273462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 273562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 273662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 273762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString 273862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x5A }, "0.0=#13015a", "OID.0.0=Z", "0.0=#13015a"); 273962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 274062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 274162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TeletexString 274262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x14, 0x01, 0x5A }, "0.0=#14015a", "OID.0.0=Z", "0.0=#14015a"); 274362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 274462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x00, 274562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UniversalString 274662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1C, 0x01, 0x5A }, "0.0=#1c015a", "OID.0.0=Z", "cn=z"); 274762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 274862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 274962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String 275062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A }, "0.0=#0c015a", "OID.0.0=Z", "0.0=#0c015a"); 275162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 275262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x00, 275362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // BMPString 275462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1E, 0x01, 0x5A }, "0.0=#1e015a", "OID.0.0=Z", "cn=z"); 275562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 275662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 275762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + not a string value 275862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 275962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 276062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 276162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Boolean 276262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x01, (byte) 0xFF }, "CN=#0101ff", "CN=#0101FF", 276362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=#0101ff"); 276462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 276562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 276662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Integer 276762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x02, 0x01, 0x0F }, "CN=#02010f", "CN=#02010F", "cn=#02010f"); 276862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 276962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 277062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // BitString 277162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x01, 0x00 }, "CN=#030100", "CN=#030100", "cn=#030100"); 277262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 277362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 277462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // SEQUENCE 277562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x01, 0x0A }, "CN=#30010a", "CN=#30010A", "cn=#30010a"); 277662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 277762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 277862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // unknown OID + not a string value 277962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 278062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 278162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 278262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Boolean 278362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x01, (byte) 0xFF }, "0.0=#0101ff", "OID.0.0=#0101FF", 278462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#0101ff"); 278562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 278662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 278762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Integer 278862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x02, 0x01, 0x0F }, "0.0=#02010f", "OID.0.0=#02010F", 278962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#02010f"); 279062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 279162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 279262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // BitString 279362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x01, 0x00 }, "0.0=#030100", "OID.0.0=#030100", 279462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#030100"); 279562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 279662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 279762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // SEQUENCE 279862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x01, 0x0A }, "0.0=#30010a", "OID.0.0=#30010A", 279962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#30010a"); 280062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 280162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 280262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + UTF-8 string with chars to be escaped 280362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 280462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 280562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // spaces 280662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 280762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 280862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a single space char 280962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x20 }, "CN=\\ ", "CN=\" \"", "cn="); 281062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 281162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 281262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a space char at the beginning 281362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x20, 0x5A }, "CN=\\ Z", "CN=\" Z\"", "cn=z"); 281462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 281562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 281662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two space chars at the beginning 2817155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x03, 0x20, 0x20, 0x5A }, "CN=\\ \\ Z", "CN=\" Z\"", 281862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z", (byte) 0x01); 281962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 282062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 282162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a space char at the end 282262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x20 }, "CN=Z\\ ", "CN=\"Z \"", "cn=z"); 282362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 282462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 282562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two space chars at the end 2826155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x03, 0x5A, 0x20, 0x20 }, "CN=Z\\ \\ ", "CN=\"Z \"", 282762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z", (byte) 0x01); 282862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 282962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // special chars 283062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 283162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 283262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a '#' char at the beginning 283362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x23, 0x5A }, "CN=\\#Z", "CN=\"#Z\"", "cn=\\#z"); 283462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 283562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 283662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two '#' chars 283762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x23, 0x5A, 0x23 }, "CN=\\#Z\\#", "CN=\"#Z#\"", 283862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\#z#"); 283962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 284062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 284162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ',' 284262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x2C }, "CN=Z\\,", "CN=\"Z,\"", "cn=z\\,"); 284362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 284462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 284562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '+' 284662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x2B }, "CN=Z\\+", "CN=\"Z+\"", "cn=z\\+"); 284762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 284862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 284962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '"' 285062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x22 }, "CN=Z\\\"", "CN=\"Z\\\"\"", 285162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z\\\"", (byte) 0x02); 285262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 285362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 285462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '\' 285562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x5C }, "CN=Z\\\\", "CN=\"Z\\\\\"", 285662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z\\\\", (byte) 0x02); 285762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 285862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 285962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '<' 286062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3C }, "CN=Z\\<", "CN=\"Z<\"", "cn=z\\<"); 286162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 286262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 286362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '>' 286462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3E }, "CN=Z\\>", "CN=\"Z>\"", "cn=z\\>"); 286562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 286662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 286762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ';' 286862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3B }, "CN=Z\\;", "CN=\"Z;\"", "cn=z\\;"); 286962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 287062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 287162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '=' 287262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3D }, "CN=Z\\=", "CN=\"Z=\"", "cn=z="); 287362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 287462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 287562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: ';' 287662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, 0x5A, 0x0D }, "CN=Z\\\r", "CN=\"Z\r\"", "cn=z"); 287762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 287862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // combinations 287962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 288062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 288162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '\ ' 288262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5C, 0x20 }, "CN=\\\\\\ ", "CN=\"\\\\ \"", 288362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\\\", (byte) 0x02); 288462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 288562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 288662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' \' 288762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x20, 0x5C }, "CN=\\ \\\\", "CN=\" \\\\\"", 288862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\\\", (byte) 0x02); 288962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 289062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 289162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' \ ' 289262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x20, 0x5C, 0x20 }, "CN=\\ \\\\\\ ", 289362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\" \\\\ \"", "cn=\\\\", (byte) 0x02); 289462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 289562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 289662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z Z' no escaping 289762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x5A, 0x20, 0x5A }, "CN=Z Z", "CN=Z Z", "cn=z z"); 289862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 289962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 290062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z Z' no escaping 2901155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x04, 0x5A, 0x20, 0x20, 0x5A }, "CN=Z Z", "CN=\"Z Z\"", 290262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z z", (byte) 0x02); 290362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 290462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 290562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' #Z ' no escaping 290662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, 0x20, 0x23, 0x5A, 0x20 }, "CN=\\ \\#Z\\ ", 290762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\" #Z \"", "cn=#z"); 290862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 290962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 291062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Special cases 291162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 291262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // list.add(new byte[] { 291362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // Name 291462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 291562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // OID 291662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x06, 0x0A, 0x09, (byte) 0x92, 0x26, (byte) 0x89, (byte) 0x93, 291762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // (byte) 0xF2, 0x2C, 0x64, 0x01, 0x01, 291862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // ANY 291962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x13, 0x01, 0x41 }, "UID=A", "OID.0.9.2342.19200300.100.1.1=A", 292062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "uid=a"); 292162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 292262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 292362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z", 292462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "cn=#1e015a"); 292562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 292662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 292762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Multi-valued DN 292862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 292962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x14, 0x31, 0x12, 293062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 1 293162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 293262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z' 293362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A, 293462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //2 293562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x06, 0x06, 0x01, 0x01, 293662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'A' 293762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x41 }, "CN=Z+0.1=#0c0141", "CN=Z + OID.0.1=A", 293862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z+0.1=#0c0141"); 293962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 294062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 294462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 294562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: the last letter(capital) of Russian alphabet 294662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }, "CN=" + ((char) 1071), 294762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=" + ((char) 1071), "cn=" + ((char) 1103)); 294862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 294962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 295062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: the last letter(capital) of Russian alphabet 295162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x03, (byte) 0xE0, (byte) 0x90, (byte) 0xAF }, "CN=" 295262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), "CN=" + ((char) 1071), "cn=" + ((char) 1103)); 295362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add( 295462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 295562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 295662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: the last letter(capital) of Russian alphabet 295762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x04, (byte) 0xF0, (byte) 0x80, (byte) 0x90, 295862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // (byte) 0xAF }, "CN=" + ((char) 1071), "CN=" 295962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), "cn=" + ((char) 1103)); 296062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 296162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 296262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString: char '$' is not in table 8 (X.680) 296362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x24 }, "CN=$", "CN=$", "cn=$"); 296462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 296562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 296662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (int i = 0; i < list.size(); i++) { 296762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 296862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Object[] values = list.get(i); 296962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded = (byte[]) values[0]; 297062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc2253 = (String) values[1]; 297162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc1179 = (String) values[2]; 297262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical = (String) values[3]; 297362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte mask = ((byte[]) values[4])[0]; 297462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 297562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p; 297662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 297762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath p = new X500Principal(encoded); 297862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 297962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) { 298062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x01) == 0)) { 298162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("RFC2253: " + i); 298262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc2253 + "'"); 298362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 298462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.RFC2253) + "'\n"); 298562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 298662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 298762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 298862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc1179.equals(p.getName(X500Principal.RFC1779))) { 298962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x02) == 0)) { 299062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("RFC1779: " + i); 299162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc1179 + "'"); 299262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 299362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.RFC1779) + "'\n"); 299462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 299562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 299662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 299762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!canonical.equals(p.getName(X500Principal.CANONICAL))) { 299862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x04) == 0)) { 299962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("CANONICAL: " + i); 300062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: " + canonical + "'"); 300162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 300262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.CANONICAL) + "'\n"); 300362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 300462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 300562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 300662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 300762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\nIllegalArgumentException: " + i + ", for " 300862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + rfc2253); 300962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath continue; 301062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 301162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("Exception: " + i + ", for " + rfc2253); 301262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\texcep: " + e.getClass().getName() + "\n"); 301362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath continue; 301462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 301562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 301662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 301762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 301862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 301962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 302062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 302162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 302262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 302362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath @SuppressWarnings("serial") 302462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public static class TestList extends ArrayList<Object[]> { 302562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 302662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TODO comment me 302762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 302862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779) { 302962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(param, rfc2253, rfc1779, (byte[]) null); 303062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 303162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 303262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 303362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical) { 303462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(param, rfc2253, rfc1779, canonical, null); 303562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 303662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 303762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 303862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded) { 303962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, null, encoded, 304062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath emptyMask }); 304162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 304262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 304362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 304462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded, byte mask) { 304562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, null, encoded, 304662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 304762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 304862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 304962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 305062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte[] encoded) { 305162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, canonical, encoded, 305262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath emptyMask }); 305362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 305462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 305562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 305662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte[] encoded, byte mask) { 305762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, canonical, encoded, 305862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 305962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 306062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 306262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TODO comment me 306362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 306462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private static final byte[] emptyMask = new byte[] { 0x00 }; 306662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(byte[] encoding, String rfc2253, String rfc1779, 306862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical) { 306962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { encoding, rfc2253, rfc1779, canonical, emptyMask }); 307062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 307162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 307262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(byte[] encoding, String rfc2253, String rfc1779, 307362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte mask) { 307462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { encoding, rfc2253, rfc1779, canonical, 307562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 307662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 307762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 307862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 307962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSerializationSelf() throws Exception { 308162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath SerializationTest.verifySelf(getSerializationData()); 308262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 308362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSerializationGolden() throws Exception { 308562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath SerializationTest.verifyGolden(this, getSerializationData()); 308662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 308762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private Object[] getSerializationData() { 308962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath return new Object[] { new X500Principal("CN=A"), 309062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal("CN=A, C=B"), 309162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal("CN=A, CN=B + C=C") }; 309262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 309362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath} 309462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 3095