6803376: BasicConstraintsExtension does not encode when (ca==false && pathLen<0)

Reviewed-by: xuelei
This commit is contained in:
Weijun Wang 2009-02-23 10:05:41 +08:00
parent 9081658837
commit 500caf95bd
2 changed files with 43 additions and 9 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -70,18 +70,15 @@ implements CertAttrSet<String> {
// Encode this extension value // Encode this extension value
private void encodeThis() throws IOException { private void encodeThis() throws IOException {
if (ca == false && pathLen < 0) {
this.extensionValue = null;
return;
}
DerOutputStream out = new DerOutputStream(); DerOutputStream out = new DerOutputStream();
DerOutputStream tmp = new DerOutputStream(); DerOutputStream tmp = new DerOutputStream();
if (ca) { if (ca) {
tmp.putBoolean(ca); tmp.putBoolean(ca);
} // Only encode pathLen when ca == true
if (pathLen >= 0) { if (pathLen >= 0) {
tmp.putInteger(pathLen); tmp.putInteger(pathLen);
}
} }
out.write(DerValue.tag_Sequence, tmp); out.write(DerValue.tag_Sequence, tmp);
this.extensionValue = out.toByteArray(); this.extensionValue = out.toByteArray();
@ -134,7 +131,7 @@ implements CertAttrSet<String> {
throw new IOException("Invalid encoding of BasicConstraints"); throw new IOException("Invalid encoding of BasicConstraints");
} }
if (val.data == null) { if (val.data == null || val.data.available() == 0) {
// non-CA cert ("cA" field is FALSE by default), return -1 // non-CA cert ("cA" field is FALSE by default), return -1
return; return;
} }

View File

@ -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());
}
}