X500PrincipalTest.java revision c0c7fab7faae8f0a9482f9fcdae4f59a36a038d0
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); 1513c0c7fab7faae8f0a9482f9fcdae4f59a36a038d0Piotr Jastrzebski assertTrue("OID.2.16.4.3=B + CN=A".equals(s) || 1514c0c7fab7faae8f0a9482f9fcdae4f59a36a038d0Piotr Jastrzebski "CN=A + OID.2.16.4.3=B".equals(s)); 151562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 151662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 151762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 151862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 151962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 152062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Gets encoding 152162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with the encoding 152262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in RFC2253 format 152362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 152462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 152562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_RFC2253() 152662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 152762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 152862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 152962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 153062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 153162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.RFC2253); 1532c0c7fab7faae8f0a9482f9fcdae4f59a36a038d0Piotr Jastrzebski assertTrue("2.16.4.3=#130142+CN=A".equals(s) || 1533c0c7fab7faae8f0a9482f9fcdae4f59a36a038d0Piotr Jastrzebski "CN=A+2.16.4.3=#130142".equals(s)); 153462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 153562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 153662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 153762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 153862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword 153962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Gets encoding 154062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits other X500Principal with the encoding 154162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets string in CANONICAL format 154262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value paying attention on sorting order of AVAs 154362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 154462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_CANONICAL() 154562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath throws Exception { 154662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "OID.2.16.4.3=B + CN=A"; 154762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 154862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 154962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal2 = new X500Principal(enc); 155062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal2.getName(X500Principal.CANONICAL); 155162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a+2.16.4.3=#130142", s); 155262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 155362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 155462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 155562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 155662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 155762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 155862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 155962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 156062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_RFC1779() throws Exception { 156162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 156262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 156362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 156462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 156562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\" A \"", s); 156662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 156762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 156862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 156962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 157062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 157162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 157262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 157362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 157462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_RFC2253() throws Exception { 157562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 157662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 157762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 157862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 157962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\ A\\ ", s); 158062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 158162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 158262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 158362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 158462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are leading and tailing spaces 158562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 158662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name 158762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 158862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaceFromEncoding_CANONICAL() throws Exception { 158962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 159062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, }; 159162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 159262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 159362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a", s); 159462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 159562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 159662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 159762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 159862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 159962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 160062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the string is in quotes 160162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 160262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_RFC1779() throws Exception { 160362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 160462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 160562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 160662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 160762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\";,\"", s); 160862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 160962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 161062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 161162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 161262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 161362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 161462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the characters are escaped 161562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 161662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_RFC2253() throws Exception { 161762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 161862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 161962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 162062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 162162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\;\\,", s); 162262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 162362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 162462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 162562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 162662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with byte array, where there are special characters 162762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 162862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name, checks if the characters are escaped 162962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 163062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialCharsFromEncoding_CANONICAL() throws Exception { 163162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 163262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C }; 163362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(mess); 163462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 163562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\;\\,", s); 163662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 163762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 163862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 163962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 164062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 164162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 164262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 164362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 164462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779() throws Exception { 164562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 164662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 164762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 164862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=\"\\\"B\"", s); 164962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 165062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 165162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 165262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 165362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 165462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 165562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 165662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 165762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253() throws Exception { 165862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 165962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 166062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 166162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,CN=\\\"B", s); 166262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 166362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 166462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 166562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 166662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \"B 166762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 166862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\b" 166962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 167062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL() throws Exception { 167162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=\\\"B"; 167262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 167362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 167462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,cn=\\\"b", s); 167562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 167662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 167762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 167862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 167962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 168062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 168162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\nB" 168262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 168362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_01() throws Exception { 168462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME see testNameSpecialChars_RFC2253_01 168562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String dn = "CN=\\\nB"; 168662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // X500Principal principal = new X500Principal(dn); 168762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String s = principal.getName(X500Principal.RFC1779); 168862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // assertEquals("CN=\"\nB\"", s); 168962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 169062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 169162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 169262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 169362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 169462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 169562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\nB 169662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 169762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_01() throws Exception { 169862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 169962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 170062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // compatibility issue: 170162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // don't accept escaped \n because it is not a special char 170262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal("CN=\\\nB"); 170362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No expected IllegalArgumentException"); 170462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 170562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 170662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 170762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 170862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 170962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\nB 171062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 171162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\nb 171262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 171362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_01() throws Exception { 171462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME testNameSpecialChars_RFC2253_01 171562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String dn = "CN=\\\nB"; 171662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // X500Principal principal = new X500Principal(dn); 171762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // String s = principal.getName(X500Principal.CANONICAL); 171862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // assertEquals("cn=b", s); 171962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 172062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 172162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 172262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 172362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 172462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 172562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "\B" 172662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 172762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_02() throws Exception { 172862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 172962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 173062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 173162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"\\\\B\"", s); 173262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 173362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 173462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 173562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 173662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 173762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 173862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\B 173962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 174062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_02() throws Exception { 174162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 174262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 174362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 174462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\\\B", s); 174562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 174662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 174762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 174862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 174962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\B 175062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 175162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \\b 175262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 175362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_02() throws Exception { 175462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\\\B"; 175562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 175662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 175762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\\\b", s); 175862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 175962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 176062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 176162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 176262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 176362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 176462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 176562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 176662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation() throws Exception { 176762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 176862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 176962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 177062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 177162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(new byte[] { 0x30, 0x11, 0x31, 0x0F, 0x30, 177262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0D, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06, 0x41, 0x42, 177362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x43, 0x44, 0x45, 0x46 }, enc)); 177462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 177562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 177662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 177762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 177862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "ABCDEF 177962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if the proper exception is thrown 178062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 178162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_01() throws Exception { 178262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF"; 178362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 178462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 178562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on string with no closing quotations"); 178662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 178762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 178862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 178962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 179062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 179162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 179262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets encoding 179362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected encoding 179462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 179562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_02() throws Exception { 179662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 179762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 179862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = principal.getEncoded(); 179962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertTrue(Arrays.equals(new byte[] { 0x30, 0x12, 0x31, 0x10, 0x30, 180062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0E, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x07, 0x41, 0x42, 180162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x43, 0x44, 0x23, 0x45, 0x46 }, enc)); 180262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 180362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 180462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 180562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 180662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Compatibility issue: according RFC 2253 such string is invalid 180762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * but we accept it, not string char is escaped 180862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 180962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameWithQuotation_03() throws Exception { 181062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=ABC\"DEF\""; 181162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 181262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABC\\\"DEF\\\"", principal 181362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .getName(X500Principal.RFC2253)); 181462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 181562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 181662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 181762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 181862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 181962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "ABCDEF" 182062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 182162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_03() throws Exception { 182262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 182362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 182462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 182562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCDEF", s); 182662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 182762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 182862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 182962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 183062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 183162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 183262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - ABC"DEF" 183362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 183462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_03() throws Exception { 183562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 183662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 183762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 183862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCDEF", s); 183962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 184062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 184162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 184262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 184362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"DEF" 184462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 184562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - abc"def" 184662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 184762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_03() throws Exception { 184862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCDEF\""; 184962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 185062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 185162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=abcdef", s); 185262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 185362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 185462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 185562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 185662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 185762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 185862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "ABCD#EF" 185962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 186062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_04() throws Exception { 186162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 186262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 186362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 186462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"ABCD#EF\"", s); 186562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 186662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 186762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 186862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 186962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 187062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 187162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - ABCD\#EF 187262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 187362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_04() throws Exception { 187462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 187562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 187662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 187762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=ABCD\\#EF", s); 187862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 187962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 188062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 188162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 188262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ABC"D#EF" 188362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 188462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - abc"d#ef" 188562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 188662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_04() throws Exception { 188762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"ABCD#EF\""; 188862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 188962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 189062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=abcd#ef", s); 189162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 189262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 189362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 189462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 189562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 189662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 189762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "X#YZ" 189862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 189962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_05() { 190062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 190162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 190262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 190362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 190462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"X#YZ\"", s); 190562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 190662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 190762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 190862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 190962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 191062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 191162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - X\#YZ 191262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 191362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_05() { 191462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 191562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 191662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 191762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 191862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 191962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=X\\#YZ", s); 192062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 192162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 192262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 192362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 192462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - X#YZ 192562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 192662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - x#yz 192762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 192862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_05() { 192962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=X#YZ"; 193062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 193162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 193262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 193362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=x#yz", s); 193462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 193562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 193662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 193762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 193862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 193962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 194062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="#XYZ" 194162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 194262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC1779_6() throws Exception { 194362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 194462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 194562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 194662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"#XYZ\"", s); 194762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 194862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 194962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 195062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 195162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 195262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 195362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN=\#XYZ 195462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 195562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_RFC2253_6() throws Exception { 195662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 195762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 195862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 195962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\\#XYZ", s); 196062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 196162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 196262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 196362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=\#XYZ 196462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 196562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - cn=\#xyz 196662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 196762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpecialChars_CANONICAL_6() throws Exception { 196862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\#XYZ"; 196962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 197062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 197162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=\\#xyz", s); 197262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 197362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 197462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 197562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 197662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 197762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "B " 197862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 197962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779() throws Exception { 198062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 198162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 198262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 198362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A, CN=\"B \"", s); 198462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 198562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 198662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 198762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 198862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 198962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 199062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B\'space' 199162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 199262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253() throws Exception { 199362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 199462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 199562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 199662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A,CN=B\\ ", s); 199762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 199862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 199962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 200062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 200162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - B\'space' 200262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 200362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B\ 200462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 200562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL() throws Exception { 200662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A,CN=B\\ "; 200762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 200862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 200962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a,cn=b", s); 201062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 201162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 201262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 201362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 201462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 201562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 201662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "B A" 201762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 201862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779_01() throws Exception { 201962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 202062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 202162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 2022155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root assertEquals("CN=\"B A\"", s); 202362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 202462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 202562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 202662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 202762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 202862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in 2253 format 202962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - B'space''space''space'A 203062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 203162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253_01() throws Exception { 203262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 203362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 203462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 203562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=B A", s); 203662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 203762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 203862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 203962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 204062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "B'space''space''space'A" 204162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 204262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - b'space'a 204362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 204462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL_01() throws Exception { 204562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"B A\""; 204662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 204762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 204862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=b a", s); 204962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 205062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 205162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 205262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 205362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 205462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 205562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - " B" 205662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 205762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC1779_02() throws Exception { 205862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 205962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 206062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 206162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\" B\"", s); 206262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 206362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 206462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 206562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 206662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 206762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 206862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \'space''space'B 206962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 207062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_RFC2253_02() throws Exception { 207162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 207262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 207362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 2074155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root assertEquals("CN=\\ \\ B", s); 207562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 207662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 207762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 207862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 207962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - \\'space''space'B 208062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 208162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - \'space''space'b 208262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 208362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameSpaces_CANONICAL_02() throws Exception { 208462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\\ B"; 208562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 208662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 208762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=b", s); 208862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 208962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 209062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 209162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 209262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - ""B 209362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * checks if the proper exception is thrown 209462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 209562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu() throws Exception { 209662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"\"B"; 209762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 209862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(dn); 209962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail("No IllegalArgumentException on improper string"); 210062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 210162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 210262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 210362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 210462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 210562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 210662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 210762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\"B" 210862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 210962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC1779_2() throws Exception { 211062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 211162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 211262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 211362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\"B\"", s); 211462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 211562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 211662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 211762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 211862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 211962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\"B 212062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 212162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC2253_2() throws Exception { 212262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 212362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 212462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 212562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\\\"B", s); 212662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 212762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 212862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 212962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"B" 213062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 213162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - a\"b 213262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 213362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_CANONICAL_2() throws Exception { 213462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"B\""; 213562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 213662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 213762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\\\"b", s); 213862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 213962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 214062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 214162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 214262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 214362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 214462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\"" 214562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 214662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC1779_3() throws Exception { 214762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 214862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 214962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 215062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\"\"", s); 215162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 215262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 215362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 215462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 215562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 215662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\" 215762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 215862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_RFC2253_3() throws Exception { 215962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 216062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 216162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 216262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\\\"", s); 216362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 216462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 216562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 216662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\"" 216762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 216862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - A\" 216962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 217062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_CANONICAL_3() throws Exception { 217162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\"\""; 217262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 217362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 217462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\\\"", s); 217562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 217662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 217762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 217862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 217962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - "A\", C=B" 218062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 218162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - "A\", C=B" 218262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 218362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_4() throws Exception { 218462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\", C=B\""; 218562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 218662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 218762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\", C=B\"", s); 218862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 218962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 219062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 219162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 219262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN="A\\", C=B 219362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 219462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="A\\", C=B 219562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 219662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameQu_5() throws Exception { 219762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=\"A\\\\\", C=B"; 219862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 219962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 220062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=\"A\\\\\", C=B", s); 220162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 220262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 220362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 220462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 220562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 220662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC1779 format 220762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN="A\nB" 220862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 220962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_RFC1779() throws Exception { 221062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 221162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 221262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC1779); 221362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\nB", s); 221462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 221562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 221662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 221762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 221862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in RFC2253 format 221962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - CN=A\nB 222062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 222162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_RFC2253() throws Exception { 222262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 222362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 222462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.RFC2253); 222562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("CN=A\nB", s); 222662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 222762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 222862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath /** 222962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * Inits X500Principal with the string with special characters - CN=A\nB 223062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * gets Name in CANONICAL format 223162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath * compares with expected value of name - cn=a\nb 223262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath */ 223362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testNameCR_CANONICAL() throws Exception { 223462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = "CN=A\nB"; 223562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal principal = new X500Principal(dn); 223662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String s = principal.getName(X500Principal.CANONICAL); 223762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath assertEquals("cn=a\nb", s); 223862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 223962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public static final String[] RFC2253_SPECIAL = new String[] { ",", "=", 224162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "+", "<", ">", "#", ";" }; 224262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testValidDN() throws Exception { 224462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath TestList list = new TestList(); 224662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("", "", "", "", new byte[] { 0x30, 0x00 }); // empty RDN sequence 224862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 224962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // sequence of RDN: RDN *("," RDN) 225062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A,C=B", "CN=A,C=B", "CN=A, C=B", "cn=a,c=b"); 225162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("C=B,CN=A", "C=B,CN=A", "C=B, CN=A", "c=b,cn=a"); 225262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A,CN=A", "CN=A,CN=A", "CN=A, CN=A", "cn=a,cn=a"); // duplicate RDNs 225362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 225462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // sequence of RDN: RFC 1779 compatibility 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 list.add("CN=A;C=B", "CN=A,C=B", "CN=A, C=B"); 225862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A ; C=B", "CN=A,C=B", "CN=A, C=B"); 225962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=A\r,\rC=B", "CN=A,C=B"); // <CR> & comma => comma 226062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(" CN=A,C=B ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end 226162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(" CN=A,C=\"B\" ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end 226262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 226362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // set of ATAV: ATAV *("+" ATAV) 226462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST=CA", "CN=A+ST=CA", "CN=A + ST=CA", "cn=a+st=ca"); 226562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+CN=A", "CN=A+CN=A", "CN=A + CN=A", "cn=a+cn=a"); // duplicate AT 226662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list 226762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath .add("2.5.4.3=A+2.5.4.3=A", "CN=A+CN=A", "CN=A + CN=A", 226862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=a+cn=a"); // duplicate AT 226962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 227062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // set of ATAV: RFC 1779 compatibility 227162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A + ST=CA", "CN=A+ST=CA", "CN=A + ST=CA"); 227262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A + ST=CA", "CN=A+ST=CA", "CN=A + ST=CA"); 227362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=A\r+\rST=CA", "CN=A+ST=CA"); // <CR> & '+' => '+' 227462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 227562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // ATAV = AttributeType "=" AttributeValue 227662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A", "CN=A", "CN=A"); 227762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cn=A", "CN=A", "CN=A"); // AT case insensitive 227862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cN=A", "CN=A", "CN=A"); // AT case insensitive 227962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("cn=a", "CN=a", "CN=a"); // AT case insensitive 228062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 228162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // ATAV : RFC 1779 compatibility 228262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN = A", "CN=A", "CN=A"); 228362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN = A", "CN=A", "CN=A"); 228462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add("CN\r=\rA", "CN=A"); // <CR> & '=' => '=' 228562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 228662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeType = <name string> | <OID> 228762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // testing OID case : OID => <name string> 228862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // tested all OIDs from RFC 2253 (2.3) and RFC 1779 (Table 1) 228962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 229062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // different variants of 2.5.4.3 (CN) OID 229162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("OID.2.5.4.3=A", "CN=A", "CN=A"); 229262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("oid.2.5.4.3=A", "CN=A", "CN=A"); 229362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.3=A", "CN=A", "CN=A"); 229462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("02.5.4.3=A", "CN=A", "CN=A"); // first: 02 => 2 229562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.0003=A", "CN=A", "CN=A"); // last: 0003 => 3 229662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 229762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // the rest of OIDs 229862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.7=A", "L=A", "L=A", "l=a"); 229962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.8=A", "ST=A", "ST=A", "st=a"); 230062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.10=A", "O=A", "O=A", "o=a"); 230162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.11=A", "OU=A", "OU=A", "ou=a"); 230262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.6=A", "C=A", "C=A", "c=a"); 230362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.9=A", "STREET=A", "STREET=A", "street=a"); 230462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("0.9.2342.19200300.100.1.25=A", "DC=A", 2305155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root "OID.0.9.2342.19200300.100.1.25=A", "dc=#160141"); 230662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("0.9.2342.19200300.100.1.1=A", "UID=A", 230762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "OID.0.9.2342.19200300.100.1.1=A", "uid=a"); 230862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 230962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // attribute types from RFC 2459 (see Appendix A) 231062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // keywords are from the API spec 231162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("T=A", "2.5.4.12=#130141", "OID.2.5.4.12=A", 231262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.12=#130141"); 231362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("DNQ=A", "2.5.4.46=#130141", "OID.2.5.4.46=A", 231462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.46=#130141"); 231562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("DNQUALIFIER=A", "2.5.4.46=#130141", "OID.2.5.4.46=A", 231662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.46=#130141"); 231762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("SURNAME=A", "2.5.4.4=#130141", "OID.2.5.4.4=A", 231862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.4=#130141"); 231962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("GIVENNAME=A", "2.5.4.42=#130141", "OID.2.5.4.42=A", 232062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.42=#130141"); 232162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("INITIALS=A", "2.5.4.43=#130141", "OID.2.5.4.43=A", 232262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.43=#130141"); 232362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("GENERATION=A", "2.5.4.44=#130141", "OID.2.5.4.44=A", 232462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.44=#130141"); 2325155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("EMAILADDRESS=A", "1.2.840.113549.1.9.1=#160141", 2326155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root "OID.1.2.840.113549.1.9.1=A", "1.2.840.113549.1.9.1=#160141", 232762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath null, (byte) 0x05); //FIXME bug??? 232862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("SERIALNUMBER=A", "2.5.4.5=#130141", "OID.2.5.4.5=A", 232962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4.5=#130141"); 233062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 233162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue => BER encoding (if OID in dotted-decimal form) 233262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // see RFC 2253 (2.4) 233362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("OID.2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("oid.2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A"); 233662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("1.1=A", "1.1=#130141", "OID.1.1=A"); 233762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 233862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 233962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue first alternative : *( stringchar / pair ) 234062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // testing pair characters. 234162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 234262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Note: for RFC1779 quoted string is returned (unspecified) 234362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 234462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=", "CN=", "CN="); // zero string chars 234562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= ", "CN=", "CN="); // zero string chars 234662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST=", "CN=A+ST=", "CN=A + ST="); // zero string chars 234762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=+ST=A", "CN=+ST=A", "CN= + ST=A"); // empty value for 1 RDN 234862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A+ST= ", "CN=A+ST=", "CN=A + ST="); // 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 list.add("CN=;ST=B", "CN=,ST=B", "CN=, ST=B"); // empty value for 1 RDN 235362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=;ST=", "CN=,ST=", "CN=, ST="); // empty value for both RDNs 235462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 235562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // \special 235662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\" + element, 235762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\" + element, "CN=\"" + element 235862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "\""); 235962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 236062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // A + \special + B 236162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\" + element + "B", "CN=A\\" 236262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 236362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 236462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 236562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 236662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \" 236762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\"", "CN=\\\"", "CN=\"\\\"\"", null, (byte) 0x02); 236862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\"A", "CN=\\\"A", "CN=\"\\\"A\"", null, (byte) 0x02); 236962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\\",C=\\\"", "CN=\\\",C=\\\"", "CN=\"\\\"\", C=\"\\\"\"", 237062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath null, (byte) 0x02); // 2 RDN 237162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\\"B", "CN=A\\\"B", "CN=\"A\\\"B\"", null, (byte) 0x02); // A\"B 237262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A ST=B", "CN=A ST\\=B", "CN=\"A ST=B\""); // no RDN separator 237362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 237462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \space 237562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\ ", "CN=\\ ", "CN=\" \"", "cn="); 237662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 237762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \hexpair 237862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41", "CN=A", "CN=A"); // 0x41=='A' 237962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2C", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=',' 238062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2c", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=',' 238162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\D0\\AF", "CN=" + ((char) 1071), "CN=" + ((char) 1071), 238262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 238362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 238462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 238562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet 238662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\D0\\AFA\\41", "CN=" + ((char) 1071) + "AA", "CN=" 238762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F, 0x31, 0x0D, 238862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x03, 238962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 239062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41, 0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet 239162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF-8(0xE090AF) is non-shortest form of UTF-8(0xD0AF) 239262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\E0\\90\\AF", "CN=" + ((char) 1071), "CN=" 239362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 239462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 239562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 239662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); 239762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF-8(0xF08090AF) is non-shortest form of UTF-8(0xD0AF) 239862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\F0\\80\\90\\AF", "CN=" + ((char) 1071), "CN=" 239962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 240062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 240162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 240262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); 240362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\\D0", "CN=" + ((char) 65533), "CN=" + ((char) 65533), 240462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 240562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 240662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8 String 240762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x01, 0x3F }); // 0xD0 is not correct UTF8 char => '?' 240862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A' 240962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2C+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=',' 241062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\\41\\2c+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=',' 241162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 241262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // stringchar '=' or not leading '#' 241362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME RFC 2253 grammar violation: '=' and '#' is a special char 241462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN==", "CN=\\=", "CN=\"=\""); 241562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A=", "CN=A\\=", "CN=\"A=\""); 241662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A#", "CN=A\\#", "CN=\"A#\""); 241762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 241862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // not leading or trailing spaces 241962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A B", "CN=A B", "CN=A B", "cn=a b"); 242062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A\\ B", "CN=A B", "CN=A B", "cn=a b"); 242162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=A \\,B", "CN=A \\,B", "CN=\"A ,B\"", "cn=a \\,b"); 242262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 242362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //not alphabet chars 242462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=$", "CN=$", "CN=$", new byte[] { 0x30, 0x0C, 0x31, 0x0A, 242562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 242662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //UTF-8 String: "$" 242762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x24 }); 242862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=(", "CN=(", "CN=(", new byte[] { 0x30, 0x0C, 0x31, 0x0A, 242962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 243062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //PrintableString: "(" 243162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x28 }); 243262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 243362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue second alternative : "#" hexstring 243662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 243862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#130141", "CN=A", "CN=A", "cn=a"); // ASN1 Printable hex string = 'A' 2439155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN=#140141", "CN=A", "CN=A", "cn=a", new byte[] { 0x30, 244062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 244162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x14, 0x01, 0x41 }); // ASN1 Teletex hex string = 'A' 244262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 244362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#010100", "CN=#010100", "CN=#010100", "cn=#010100"); // ASN1 Boolean = FALSE 244462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=#0101fF", "CN=#0101ff", "CN=#0101FF", "cn=#0101ff"); // ASN1 Boolean = TRUE 244562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#3000", "CN=#3000", "CN=#3000"); // ASN1 Sequence 244662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#0500", "CN=A", "CN=A"); // ASN1 Null 244762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF", "CN=#0101ff", "CN=#0101FF", // space at beginning 244862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 244962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE 245062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ); 245162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF+ST=A", "CN=#0101ff+ST=A", "CN=#0101FF + ST=A", 245262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=#0101ff+st=a"); //space 245362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= #0101fF ", "CN=#0101ff", "CN=#0101FF", // space at the end 245462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 245562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE 245662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath , (byte) 0x00); 245762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 245862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME unspecified output for RFC1779 245962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#1C0141", "CN=A", "CN=A"); // ASN1 Universal hex string = 'A' 246062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=#1E0141", "CN=A", "CN=A"); // ASN1 Bmp hex string = 'A' 246162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 246262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 246362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : " *( quotechar / pair ) " 246462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // quotechar = <any character except '\' or '"' > 246562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 246662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Note: 246762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RFC2253: passed quoted AV string is unquoted, special chars are escaped 246862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RFC1779: escaped quoted chars are unescaped 246962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 247062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\"", "CN=", "CN="); // empty quoted string 247162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\"", "CN=A", "CN=A"); // "A" 247262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 247362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "special" => \special 247462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"" + element + "\"", "CN=\\" 247562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element, "CN=\"" + element + "\""); 247662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 247762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "A + special + B" => A + \special + B 247862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A" + element + "B\"", "CN=A\\" 247962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 248062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 248162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 248262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : RFC2253_SPECIAL) { 248362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "\special" => \special 248462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\" + element + "\"", "CN=\\" 248562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element, "CN=\"" + element + "\""); 248662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 248762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "A + \special + B" => A + \special + B 248862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\\" + element + "B\"", "CN=A\\" 248962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + element + "B", "CN=\"A" + element 249062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "B\""); 249162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 249262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\\"\"", "CN=\\\"", "CN=\"\\\"\"", null, (byte) 0x02); // "\"" 249362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"A\\\"B\"", "CN=A\\\"B", "CN=\"A\\\"B\"", null, 249462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x02); // "A\"B" 249562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 249662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // pair = \hexpair (test cases are the same as for the first alternative) 249762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\"", "CN=A", "CN=A"); // 0x41=='A' 249862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2C\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=',' 249962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2c\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=',' 250062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\D0\\AF\"", "CN=" + ((char) 1071), "CN=" 250162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 250262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 250362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 250462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet 250562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\D0\\AFA\\41\"", "CN=" + ((char) 1071) + "AA", "CN=" 250662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F, 0x31, 0x0D, 250762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x03, 250862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 250962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41, 0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet 251062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\E0\\90\\AF\"", "CN=" + ((char) 1071), "CN=" 251162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 251262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 251362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 251462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xE090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet 251562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\F0\\80\\90\\AF\"", "CN=" + ((char) 1071), "CN=" 251662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 251762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 251862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8 String 251962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xF08090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet 252062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 252162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\"+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A' 252262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2C\"+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=',' 252362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN=\"\\41\\2c\"+ST=A", "CN=A\\,+ST=A", "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=',' 252462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 252562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : RFC 1779 compatibility 252662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\"\r\"", "CN=\"\r\""); // "<CR>" 252762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add("CN=\"\\\r\"", "CN=\"\\\r\""); // "\<CR>" 252862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 252962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue : RFC 1779 compatibility 253062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= A ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces 2531155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN=\\ A ", "CN=\\ \\ A", "CN=\" A\"", "cn=a", null, 253262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x01); // escaped leading space 2533155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root list.add("CN= A \\ ", "CN=A\\ \\ ", "CN=\"A \"", "cn=a", null, 253462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath (byte) 0x01); // escaped trailing space 253562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 253662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add("CN= \"A\" ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces 253762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 253862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 253962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (int i = 0; i < list.size(); i++) { 254062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 254162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Object[] obj = list.get(i); 254262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 254362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String dn = (String) obj[0]; 254462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc2253 = (String) obj[1]; 254562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc1779 = (String) obj[2]; 254662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical = (String) obj[3]; 254762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded = (byte[]) obj[4]; 254862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte mask = ((byte[]) obj[5])[0]; 254962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 255062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 255162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p = new X500Principal(dn); 255262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) { 255362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x01) == 0)) { 255462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2555155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nRFC2253: " + i); 2556155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append(" \tparm: '" + dn + "'"); 255762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc2253 + "'"); 255862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2559155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.RFC2253) + "'"); 256062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 256162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 256262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 256362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc1779.equals(p.getName(X500Principal.RFC1779))) { 256462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x02) == 0)) { 256562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2566155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nRFC1779: " + i); 2567155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append(" \tparm: '" + dn + "'"); 2568155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\t\texpected: '" + rfc1779 + "'"); 256962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2570155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.RFC1779) + "'"); 257162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 257262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 257362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 257462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (canonical != null) { 257562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!canonical.equals(p.getName(X500Principal.CANONICAL))) { 257662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x04) == 0)) { 257762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2578155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nCANONICAL: " + i); 257962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\tparm: '" + dn + "'"); 2580155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\t\texpected: '" + canonical + "'"); 258162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 2582155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + p.getName(X500Principal.CANONICAL) + "'"); 258362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 258662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 258762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (encoded != null) { 258862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!Arrays.equals(encoded, p.getEncoded())) { 258962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x08) == 0)) { 259062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 2591155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nUnexpected encoding for: " + i 2592155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root + ", dn= '" + dn + "'"); 259362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 259462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath System.out.println("\nI " + i); 259562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] enc = p.getEncoded(); 259662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (byte element : enc) { 259762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath System.out.print(", 0x" 259862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + Integer.toHexString(element)); 259962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 260362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 2604155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nIllegalArgumentException: " + i); 2605155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\tparm: '" + dn + "'"); 260662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 2607155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\nException: " + i); 260862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\tparm: '" + dn + "'"); 2609155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root errorMsg.append("\texcep: " + e.getClass().getName()); 261062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 261462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 261562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 261862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 261962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testInvalidDN() { 262062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String[] illegalDN = new String[] { 262162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // RDN 262262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME " ", // space only 262362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN", // attribute type only 262462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A;", // RFC 1779: BNF allows this, but ... 262562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A,", // RFC 1779: BNF allows this, but ... 262662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ",CN=A", // no AttributeType for first RDN 262762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=,A", // no AttributeType for second RDN 262862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A+", // no AttributeTypeAndValue for second RDN 262962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#130141 ST=B", // no RDN separator 263062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 263162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeType = <name string> | <OID> 263262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "AAA=A", // no such <name string> 263362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1..1=A", // wrong OID 263462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath ".1.1=A", // wrong OID 263562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "11=A", // wrong OID 263662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1=A", // wrong OID 263762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "AID.1.1=A", // wrong OID 263862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "1.50=A", // wrong OID 263962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "5.1.0=A", // wrong OID 264062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.-5.4.3=A", // wrong OID 264162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.-4.3=A", // wrong OID 264262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "2.5.4-.3=A", // wrong OID 264362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "2.5.4.-3=A", // wrong OID 264462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 264562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue first alternative : *( stringchar / pair ) 264662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=,", // stringchar = ',' 264762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN==", 264862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=+", // stringchar = '+' 264962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=<", // stringchar = '<' 265062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=>", // stringchar = '>' 265162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#", // stringchar = '#' 265262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=Z#", // stringchar = '#' 265362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=;", // stringchar = ';' 265462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"", // stringchar = " 265562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME "CN=A\"B", // stringchar = " 265662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\", // stringchar = \ 265762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A\\", // stringchar = \ 265862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=A\\B", // stringchar = \ 265962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\z", // invalid pair = \z 266062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4", // invalid pair = \4 266162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4Z", // invalid pair = \4Z 266262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\\4\\2c", // invalid pair = \4\2c 266362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 266462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue second alternative : "#" hexstring 266562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#", // no hex string 266662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#2", // no hex pair 266762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#22", // hexpair is not BER encoding 266862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#0001", // invalid BER encoding (missed content) 266962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#000201", // invalid BER encoding (wrong length) 267062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#0002010101", // invalid BER encoding (wrong length) 267162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#00FF", // invalid BER encoding (wrong length) 267262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=#ZZ", // not hex pair 267362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 267462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME boolean with indefinite length 267562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //"CN=#0100010000", // invalid BER encoding (wrong length) 267662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 267762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // AttributeValue third alternative : " *( quotechar / pair ) " 267862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"A\" B", // TODO comment me 267962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"A\\", // TODO comment me 268062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4\"", // invalid pair = \4 268162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4Z\"", // invalid pair = \4Z 268262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\"\\4\\2c\"", // invalid pair = \4\2c 268362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath }; 268462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 268562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 268662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (String element : illegalDN) { 268762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 268862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 268962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal(element); 269062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("No IllegalArgumentException: '" + element 269162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + "'\n"); 269262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 269362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 269662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 269762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 269862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 269962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 270062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 270162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testValidEncoding() { 270262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath TestList list = new TestList(); 270362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 270462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 270562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Empty 270662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 270762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x00 }, "", "", ""); 270862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x02, 0x31, 0x00 }, "", "", ""); //??? invalid size constraints 270962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 271062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 271162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + string with different tags(all string) 271262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 271362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 271462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 271562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString 271662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 271762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 271862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 271962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TeletexString 2720155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x14, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 272162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 272262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 272362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UniversalString 272462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 272562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 272662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 272762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String 272862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 272962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 273062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 273162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // BMPString 273262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z"); 273362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 273462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 273562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Unknown OID + string with different tags(all string) 273662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 273762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 273862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 273962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString 274062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x5A }, "0.0=#13015a", "OID.0.0=Z", "0.0=#13015a"); 274162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 274262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 274362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TeletexString 274462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x14, 0x01, 0x5A }, "0.0=#14015a", "OID.0.0=Z", "0.0=#14015a"); 274562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 274662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x00, 274762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UniversalString 274862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1C, 0x01, 0x5A }, "0.0=#1c015a", "OID.0.0=Z", "cn=z"); 274962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 275062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 275162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String 275262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A }, "0.0=#0c015a", "OID.0.0=Z", "0.0=#0c015a"); 275362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME:compatibility list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 275462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x00, 275562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // BMPString 275662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x1E, 0x01, 0x5A }, "0.0=#1e015a", "OID.0.0=Z", "cn=z"); 275762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 275862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 275962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + not a string value 276062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 276162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 276262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 276362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Boolean 276462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x01, (byte) 0xFF }, "CN=#0101ff", "CN=#0101FF", 276562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=#0101ff"); 276662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 276762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 276862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Integer 276962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x02, 0x01, 0x0F }, "CN=#02010f", "CN=#02010F", "cn=#02010f"); 277062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 277162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 277262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // BitString 277362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x01, 0x00 }, "CN=#030100", "CN=#030100", "cn=#030100"); 277462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 277562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 277662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // SEQUENCE 277762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x01, 0x0A }, "CN=#30010a", "CN=#30010A", "cn=#30010a"); 277862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 277962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 278062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // unknown OID + not a string value 278162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 278262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 278362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 278462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Boolean 278562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x01, 0x01, (byte) 0xFF }, "0.0=#0101ff", "OID.0.0=#0101FF", 278662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#0101ff"); 278762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 278862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 278962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Integer 279062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x02, 0x01, 0x0F }, "0.0=#02010f", "OID.0.0=#02010F", 279162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#02010f"); 279262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 279362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 279462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // BitString 279562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x03, 0x01, 0x00 }, "0.0=#030100", "OID.0.0=#030100", 279662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#030100"); 279762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01, 279862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x00, 279962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // SEQUENCE 280062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x01, 0x0A }, "0.0=#30010a", "OID.0.0=#30010A", 280162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "0.0=#30010a"); 280262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 280362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 280462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Known OID + UTF-8 string with chars to be escaped 280562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 280662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 280762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // spaces 280862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 280962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 281062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a single space char 281162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x20 }, "CN=\\ ", "CN=\" \"", "cn="); 281262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 281362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 281462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a space char at the beginning 281562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x20, 0x5A }, "CN=\\ Z", "CN=\" Z\"", "cn=z"); 281662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 281762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 281862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two space chars at the beginning 2819155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x03, 0x20, 0x20, 0x5A }, "CN=\\ \\ Z", "CN=\" Z\"", 282062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z", (byte) 0x01); 282162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 282262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 282362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a space char at the end 282462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x20 }, "CN=Z\\ ", "CN=\"Z \"", "cn=z"); 282562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 282662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 282762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two space chars at the end 2828155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x03, 0x5A, 0x20, 0x20 }, "CN=Z\\ \\ ", "CN=\"Z \"", 282962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z", (byte) 0x01); 283062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 283162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // special chars 283262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 283362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 283462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: a '#' char at the beginning 283562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x23, 0x5A }, "CN=\\#Z", "CN=\"#Z\"", "cn=\\#z"); 283662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 283762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 283862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: two '#' chars 283962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x23, 0x5A, 0x23 }, "CN=\\#Z\\#", "CN=\"#Z#\"", 284062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\#z#"); 284162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 284262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 284362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ',' 284462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x2C }, "CN=Z\\,", "CN=\"Z,\"", "cn=z\\,"); 284562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 284662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 284762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '+' 284862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x2B }, "CN=Z\\+", "CN=\"Z+\"", "cn=z\\+"); 284962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 285062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 285162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '"' 285262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x22 }, "CN=Z\\\"", "CN=\"Z\\\"\"", 285362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z\\\"", (byte) 0x02); 285462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 285562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 285662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '\' 285762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x5C }, "CN=Z\\\\", "CN=\"Z\\\\\"", 285862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z\\\\", (byte) 0x02); 285962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 286062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 286162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '<' 286262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3C }, "CN=Z\\<", "CN=\"Z<\"", "cn=z\\<"); 286362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 286462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 286562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '>' 286662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3E }, "CN=Z\\>", "CN=\"Z>\"", "cn=z\\>"); 286762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 286862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 286962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ';' 287062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3B }, "CN=Z\\;", "CN=\"Z;\"", "cn=z\\;"); 287162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 287262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 287362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '=' 287462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5A, 0x3D }, "CN=Z\\=", "CN=\"Z=\"", "cn=z="); 287562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //FIXME list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 287662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 287762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: ';' 287862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x02, 0x5A, 0x0D }, "CN=Z\\\r", "CN=\"Z\r\"", "cn=z"); 287962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 288062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // combinations 288162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 288262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 288362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: '\ ' 288462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x5C, 0x20 }, "CN=\\\\\\ ", "CN=\"\\\\ \"", 288562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\\\", (byte) 0x02); 288662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 288762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 288862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' \' 288962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, 0x20, 0x5C }, "CN=\\ \\\\", "CN=\" \\\\\"", 289062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=\\\\", (byte) 0x02); 289162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 289262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 289362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' \ ' 289462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x20, 0x5C, 0x20 }, "CN=\\ \\\\\\ ", 289562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\" \\\\ \"", "cn=\\\\", (byte) 0x02); 289662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 289762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 289862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z Z' no escaping 289962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x03, 0x5A, 0x20, 0x5A }, "CN=Z Z", "CN=Z Z", "cn=z z"); 290062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 290162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 290262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z Z' no escaping 2903155ee0c0ba582c28487cd5c3964ff8645478c628Kenny Root 0x0C, 0x04, 0x5A, 0x20, 0x20, 0x5A }, "CN=Z Z", "CN=\"Z Z\"", 290462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z z", (byte) 0x02); 290562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 290662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 290762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: ' #Z ' no escaping 290862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x04, 0x20, 0x23, 0x5A, 0x20 }, "CN=\\ \\#Z\\ ", 290962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=\" #Z \"", "cn=#z"); 291062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 291162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 291262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Special cases 291362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 291462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // list.add(new byte[] { 291562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // Name 291662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 291762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // OID 291862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x06, 0x0A, 0x09, (byte) 0x92, 0x26, (byte) 0x89, (byte) 0x93, 291962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // (byte) 0xF2, 0x2C, 0x64, 0x01, 0x01, 292062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // ANY 292162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x13, 0x01, 0x41 }, "UID=A", "OID.0.9.2342.19200300.100.1.1=A", 292262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "uid=a"); 292362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 292462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 292562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z", 292662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // "cn=#1e015a"); 292762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 292862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 292962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // Multi-valued DN 293062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 293162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x14, 0x31, 0x12, 293262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 1 293362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 293462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'Z' 293562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x5A, 293662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath //2 293762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x30, 0x06, 0x06, 0x01, 0x01, 293862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: 'A' 293962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x01, 0x41 }, "CN=Z+0.1=#0c0141", "CN=Z + OID.0.1=A", 294062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "cn=z+0.1=#0c0141"); 294162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 294262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 294562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 294662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 294762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // UTF8String: the last letter(capital) of Russian alphabet 294862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }, "CN=" + ((char) 1071), 294962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath "CN=" + ((char) 1071), "cn=" + ((char) 1103)); 295062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 295162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 295262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: the last letter(capital) of Russian alphabet 295362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x03, (byte) 0xE0, (byte) 0x90, (byte) 0xAF }, "CN=" 295462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), "CN=" + ((char) 1071), "cn=" + ((char) 1103)); 295562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // FIXME list.add( 295662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 295762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x55, 0x04, 0x03, 295862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // // UTF8String: the last letter(capital) of Russian alphabet 295962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 0x0C, 0x04, (byte) 0xF0, (byte) 0x80, (byte) 0x90, 296062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // (byte) 0xAF }, "CN=" + ((char) 1071), "CN=" 296162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // + ((char) 1071), "cn=" + ((char) 1103)); 296262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 296362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x55, 0x04, 0x03, 296462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // PrintableString: char '$' is not in table 8 (X.680) 296562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 0x13, 0x01, 0x24 }, "CN=$", "CN=$", "cn=$"); 296662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 296762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath StringBuffer errorMsg = new StringBuffer(); 296862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath for (int i = 0; i < list.size(); i++) { 296962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 297062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath Object[] values = list.get(i); 297162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded = (byte[]) values[0]; 297262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc2253 = (String) values[1]; 297362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String rfc1179 = (String) values[2]; 297462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical = (String) values[3]; 297562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte mask = ((byte[]) values[4])[0]; 297662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 297762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath X500Principal p; 297862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath try { 297962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath p = new X500Principal(encoded); 298062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 298162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) { 298262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x01) == 0)) { 298362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("RFC2253: " + i); 298462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc2253 + "'"); 298562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 298662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.RFC2253) + "'\n"); 298762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 298862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 298962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 299062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!rfc1179.equals(p.getName(X500Principal.RFC1779))) { 299162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x02) == 0)) { 299262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("RFC1779: " + i); 299362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: '" + rfc1179 + "'"); 299462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 299562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.RFC1779) + "'\n"); 299662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 299762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 299862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 299962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!canonical.equals(p.getName(X500Principal.CANONICAL))) { 300062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (!testing || ((mask & 0x04) == 0)) { 300162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("CANONICAL: " + i); 300262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\t\texpected: " + canonical + "'"); 300362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\treturned: '" 300462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + p.getName(X500Principal.CANONICAL) + "'\n"); 300562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 300662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 300762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 300862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (IllegalArgumentException e) { 300962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\nIllegalArgumentException: " + i + ", for " 301062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath + rfc2253); 301162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath continue; 301262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } catch (Exception e) { 301362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("Exception: " + i + ", for " + rfc2253); 301462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath errorMsg.append("\texcep: " + e.getClass().getName() + "\n"); 301562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath continue; 301662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 301762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 301862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 301962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 302062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath if (errorMsg.length() != 0) { 302162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath fail(errorMsg.toString()); 302262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 302362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 302462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 302562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath @SuppressWarnings("serial") 302662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public static class TestList extends ArrayList<Object[]> { 302762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 302862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TODO comment me 302962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 303062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779) { 303162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(param, rfc2253, rfc1779, (byte[]) null); 303262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 303362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 303462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 303562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical) { 303662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(param, rfc2253, rfc1779, canonical, null); 303762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 303862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 303962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 304062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded) { 304162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, null, encoded, 304262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath emptyMask }); 304362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 304462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 304562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 304662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath byte[] encoded, byte mask) { 304762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, null, encoded, 304862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 304962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 305062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 305162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 305262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte[] encoded) { 305362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, canonical, encoded, 305462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath emptyMask }); 305562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 305662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 305762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(String param, String rfc2253, String rfc1779, 305862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte[] encoded, byte mask) { 305962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { param, rfc2253, rfc1779, canonical, encoded, 306062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 306162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 306262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 306462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // TODO comment me 306562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath // 306662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private static final byte[] emptyMask = new byte[] { 0x00 }; 306862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 306962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(byte[] encoding, String rfc2253, String rfc1779, 307062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical) { 307162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { encoding, rfc2253, rfc1779, canonical, emptyMask }); 307262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 307362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 307462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void add(byte[] encoding, String rfc2253, String rfc1779, 307562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath String canonical, byte mask) { 307662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath add(new Object[] { encoding, rfc2253, rfc1779, canonical, 307762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new byte[] { mask } }); 307862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 307962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 308062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSerializationSelf() throws Exception { 308362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath SerializationTest.verifySelf(getSerializationData()); 308462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 308562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 308662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath public void testSerializationGolden() throws Exception { 308762542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath SerializationTest.verifyGolden(this, getSerializationData()); 308862542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 308962542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 309062542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath private Object[] getSerializationData() { 309162542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath return new Object[] { new X500Principal("CN=A"), 309262542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal("CN=A, C=B"), 309362542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath new X500Principal("CN=A, CN=B + C=C") }; 309462542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath } 309562542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath} 309662542d811e9bc4126ef912bc6e60e1b9952b4e09Narayan Kamath 3097