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