jdk/test/sun/security/pkcs/pkcs9/UnstructuredName.java
author juh
Wed, 24 Jul 2013 12:48:10 -0700
changeset 19043 42407be709a3
child 30820 0d4717a011d3
permissions -rw-r--r--
8016916: UnstructuredName should support DirectoryString Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19043
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     1
/*
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     4
 *
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     8
 *
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    13
 * accompanied this code).
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    14
 *
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    18
 *
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    21
 * questions.
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    22
 */
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    23
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    24
/*
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    25
 * @test
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    26
 * @bug 8016916
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    27
 * @summary UnstructuredName should support DirectoryString
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    28
 */
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    29
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    30
import java.util.Base64;
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    31
import sun.security.pkcs10.PKCS10;
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    32
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    33
public class UnstructuredName {
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    34
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    35
    // Certificate request with an Unstructured Name attribute
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    36
    static String csrStr =
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    37
        "MIIBtjCCAR8CAQAwEzERMA8GA1UEAxMIdGVzdE5hbWUwgZ8wDQYJKoZIhvcNAQEB\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    38
        "BQADgY0AMIGJAoGBAMTEIVCsM8IIhvsbzn6AwQFX5C8RGAWIrL6P5XEr1z+bvHx3\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    39
        "XhPD4tWLCR6CTKq0lTlo+QKKct7MUY7pdKShajpyYD+1YLgEve0nNd4r5kVUeoHe\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    40
        "CyIZoImONgAlmVD7M8IJjz2Vg84WVVjkHK67H5qt7Agi1hUnFGmRbJ8rbL7jAgMB\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    41
        "AAGgYzAXBgkqhkiG9w0BCQcxChMIcGFzc3dvcmQwHAYJKoZIhvcNAQkCMQ8TDW9w\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    42
        "dGlvbmFsIG5hbWUwKgYJKoZIhvcNAQkOMR0wGzAMBgNVHRMBAf8EAjAAMAsGA1Ud\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    43
        "DwQEAwIGQDANBgkqhkiG9w0BAQUFAAOBgQBc7ldGSmyCjMU+ssjglCimqknCVdig\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    44
        "N8FsI/aNRgLqf+eXKWZOxl1v3GB9HCXWDtqOnHd6AJKFpGtK0bqRu7bIncYIiQ1a\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    45
        "P1NW4Kup8d1fTPhw6xgYtxeHvUxRa2y4IXskPUYqp05HavfNZxmcJ5mZOLtgiDIC\n" +
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    46
        "I3J80saqEUQKqQ==";
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    47
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    48
    public static void main(String[] args) throws Exception {
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    49
        PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(csrStr));
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    50
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    51
        // If PKCS9Attribute did not accept the PrintableString ASN.1 tag,
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    52
        // this would fail with an IOException
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    53
        Object attr = req.getAttributes().getAttribute("1.2.840.113549.1.9.2");
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    54
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    55
        // Check that the attribute exists
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    56
        if (attr == null) {
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    57
            throw new Exception("Attribute should not be null.");
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    58
        }
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    59
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    60
        System.out.println("Test passed.");
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    61
    }
42407be709a3 8016916: UnstructuredName should support DirectoryString
juh
parents:
diff changeset
    62
}