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