# HG changeset patch # User juh # Date 1374695290 25200 # Node ID 42407be709a3d0d0100cd14e62444294dc436255 # Parent d6abf1c83aacf4d75da056edda0ed840fc272051 8016916: UnstructuredName should support DirectoryString Reviewed-by: mullan diff -r d6abf1c83aac -r 42407be709a3 jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java --- a/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Wed Jul 24 15:47:10 2013 +0200 +++ b/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Wed Jul 24 12:48:10 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -310,7 +310,8 @@ private static final Byte[][] PKCS9_VALUE_TAGS = { null, {new Byte(DerValue.tag_IA5String)}, // EMailAddress - {new Byte(DerValue.tag_IA5String)}, // UnstructuredName + {new Byte(DerValue.tag_IA5String), // UnstructuredName + new Byte(DerValue.tag_PrintableString)}, {new Byte(DerValue.tag_ObjectId)}, // ContentType {new Byte(DerValue.tag_OctetString)}, // MessageDigest {new Byte(DerValue.tag_UtcTime)}, // SigningTime diff -r d6abf1c83aac -r 42407be709a3 jdk/src/share/classes/sun/security/tools/keytool/Main.java --- a/jdk/src/share/classes/sun/security/tools/keytool/Main.java Wed Jul 24 15:47:10 2013 +0200 +++ b/jdk/src/share/classes/sun/security/tools/keytool/Main.java Wed Jul 24 12:48:10 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2198,8 +2198,15 @@ printExtensions(rb.getString("Extension.Request."), exts, out); } } else { - out.println(attr.getAttributeId()); - out.println(attr.getAttributeValue()); + out.println("Attribute: " + attr.getAttributeId()); + PKCS9Attribute pkcs9Attr = + new PKCS9Attribute(attr.getAttributeId(), + attr.getAttributeValue()); + out.print(pkcs9Attr.getName() + ": "); + Object attrVal = attr.getAttributeValue(); + out.println(attrVal instanceof String[] ? + Arrays.toString((String[]) attrVal) : + attrVal); } } if (debug) { diff -r d6abf1c83aac -r 42407be709a3 jdk/test/sun/security/pkcs/pkcs9/UnstructuredName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/pkcs/pkcs9/UnstructuredName.java Wed Jul 24 12:48:10 2013 -0700 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8016916 + * @summary UnstructuredName should support DirectoryString + */ + +import java.util.Base64; +import sun.security.pkcs10.PKCS10; + +public class UnstructuredName { + + // Certificate request with an Unstructured Name attribute + static String csrStr = + "MIIBtjCCAR8CAQAwEzERMA8GA1UEAxMIdGVzdE5hbWUwgZ8wDQYJKoZIhvcNAQEB\n" + + "BQADgY0AMIGJAoGBAMTEIVCsM8IIhvsbzn6AwQFX5C8RGAWIrL6P5XEr1z+bvHx3\n" + + "XhPD4tWLCR6CTKq0lTlo+QKKct7MUY7pdKShajpyYD+1YLgEve0nNd4r5kVUeoHe\n" + + "CyIZoImONgAlmVD7M8IJjz2Vg84WVVjkHK67H5qt7Agi1hUnFGmRbJ8rbL7jAgMB\n" + + "AAGgYzAXBgkqhkiG9w0BCQcxChMIcGFzc3dvcmQwHAYJKoZIhvcNAQkCMQ8TDW9w\n" + + "dGlvbmFsIG5hbWUwKgYJKoZIhvcNAQkOMR0wGzAMBgNVHRMBAf8EAjAAMAsGA1Ud\n" + + "DwQEAwIGQDANBgkqhkiG9w0BAQUFAAOBgQBc7ldGSmyCjMU+ssjglCimqknCVdig\n" + + "N8FsI/aNRgLqf+eXKWZOxl1v3GB9HCXWDtqOnHd6AJKFpGtK0bqRu7bIncYIiQ1a\n" + + "P1NW4Kup8d1fTPhw6xgYtxeHvUxRa2y4IXskPUYqp05HavfNZxmcJ5mZOLtgiDIC\n" + + "I3J80saqEUQKqQ=="; + + public static void main(String[] args) throws Exception { + PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(csrStr)); + + // If PKCS9Attribute did not accept the PrintableString ASN.1 tag, + // this would fail with an IOException + Object attr = req.getAttributes().getAttribute("1.2.840.113549.1.9.2"); + + // Check that the attribute exists + if (attr == null) { + throw new Exception("Attribute should not be null."); + } + + System.out.println("Test passed."); + } +}