v2 of 6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
# HG changeset patch
# User weijun
# Date 1234773025 -28800
# Node ID 00b37ebd3e73de0c1cec831d0b9a06870a84d4cf
# Parent d9d321205de08992a4cb89d52e11a079323d3898
6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
Reviewed-by: nobody
--- a/src/share/classes/sun/security/x509/BasicConstraintsExtension.java Mon Feb 16 16:26:31 2009 +0800
+++ b/src/share/classes/sun/security/x509/BasicConstraintsExtension.java Mon Feb 16 16:30:25 2009 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. 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
@@ -70,18 +70,15 @@
// Encode this extension value
private void encodeThis() throws IOException {
- if (ca == false && pathLen < 0) {
- this.extensionValue = null;
- return;
- }
DerOutputStream out = new DerOutputStream();
DerOutputStream tmp = new DerOutputStream();
if (ca) {
tmp.putBoolean(ca);
- }
- if (pathLen >= 0) {
- tmp.putInteger(pathLen);
+ // Only encode pathLen when ca == true
+ if (pathLen >= 0) {
+ tmp.putInteger(pathLen);
+ }
}
out.write(DerValue.tag_Sequence, tmp);
this.extensionValue = out.toByteArray();
@@ -134,17 +131,18 @@
throw new IOException("Invalid encoding of BasicConstraints");
}
- if (val.data == null) {
- // non-CA cert ("cA" field is FALSE by default), return -1
- return;
+ DerValue opt;
+ if (val.data.available() != 0) {
+ opt = val.data.getDerValue();
+ // Should not happen, since when cA is missing, pathLenConstraint
+ // should not exist either.
+ if (opt.tag != DerValue.tag_Boolean) {
+ // non-CA cert ("cA" field is FALSE by default), return -1
+ return;
+ }
+
+ this.ca = opt.getBoolean();
}
- DerValue opt = val.data.getDerValue();
- if (opt.tag != DerValue.tag_Boolean) {
- // non-CA cert ("cA" field is FALSE by default), return -1
- return;
- }
-
- this.ca = opt.getBoolean();
if (val.data.available() == 0) {
// From PKIX profile:
// Where pathLenConstraint does not appear, there is no
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/x509/Extensions/BCNull.java Mon Feb 16 16:30:25 2009 +0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary BasicConstraintsExtension does not encode when (ca==false && pathLen<0)
+ * @bug 6803376
+ */
+
+import sun.security.x509.BasicConstraintsExtension;
+import java.io.ByteArrayOutputStream;
+
+public class BCNull {
+ public static void main(String [] args) throws Exception {
+ new BasicConstraintsExtension(false, -1).encode(new ByteArrayOutputStream());
+ }
+}