Skip to content

Commit ca1700b

Browse files
author
Mark Powers
committed
8336665: CCE in X509CRLImpl$TBSCertList.getCertIssuer
Reviewed-by: mullan
1 parent d1540e2 commit ca1700b

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

src/java.base/share/classes/sun/security/x509/X509CRLImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -280,14 +280,20 @@ public X500Principal getIssuerX500Principal() {
280280
* prevCertIssuer if it does not exist
281281
*/
282282
private X500Principal getCertIssuer(X509CRLEntryImpl entry,
283-
X500Principal prevCertIssuer) {
283+
X500Principal prevCertIssuer) throws CRLException {
284284

285285
CertificateIssuerExtension ciExt =
286286
entry.getCertificateIssuerExtension();
287287
if (ciExt != null) {
288288
GeneralNames names = ciExt.getNames();
289-
X500Name issuerDN = (X500Name) names.get(0).getName();
290-
return issuerDN.asX500Principal();
289+
Iterator<GeneralName> itr = names.iterator();
290+
while (itr.hasNext()) {
291+
if (itr.next().getName() instanceof X500Name issuerDN) {
292+
return issuerDN.asX500Principal();
293+
}
294+
}
295+
throw new CRLException("Parsing error: CertificateIssuer "
296+
+ "field does not contain an X.500 DN");
291297
} else {
292298
return prevCertIssuer;
293299
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2024, 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 8336665
27+
* @summary Verify that generateCRLs method does not throw ClassCastException.
28+
* It should throw CRLException instead.
29+
* @library /test/lib
30+
*/
31+
import java.security.NoSuchProviderException;
32+
import java.security.cert.*;
33+
import java.io.ByteArrayInputStream;
34+
import java.util.Base64;
35+
36+
import jdk.test.lib.Utils;
37+
38+
public class UnexpectedCCE {
39+
static CertificateFactory cf = null;
40+
41+
public static void main(String[] av ) throws CertificateException,
42+
NoSuchProviderException {
43+
44+
// Fuzzed data input stream looks like an x509.OIDName
45+
// in the CertificateIssuerExtension. A CRLException is thrown
46+
// because an X500Name is expected.
47+
byte[] encoded_1 = Base64.getDecoder().decode("""
48+
MIIBljCCAVMCAQEwCwYHKoZIzjgEAwUAMC0xEzARBgoJkiaJk/IsZAEZEwNjb20xFjA\
49+
UBgoJkiaJjvIsZAEZEwZ0ZXN0Q0EXDTAzMDcxNTE2MjAwNVoXDTAzMDcyMDE2MjAwNV\
50+
owgdIwUwIBBBcNMDMwNzE1MTYyMDAzWjA/MD0GA1UdHQEB/wQzMDGILzETMBEGCgmSJ\
51+
omT8ixkARkMA2NvbTEYMBYGCgmSJomT8ixkARkTCGNlcnRzUlVTMBICAQMXDTAzMDcx\
52+
NTE2MjAwNFowUwIBAhcNMDMwNzE1MTYyMDA0WjA/MD0GA1UdIQEB/wQzMDEwGAYDVQQ\
53+
DExEwDyqGMDEUMgAwgDAuRQA1MRYGCgmSJomT8ixkARkTCG15VGVzdENBMBICAQEXDT\
54+
AzMDcxNTE2MjAwNFqgHzAdMA8GA1UdHAEB/wQFMAOEAf8wCgYDVR0UAwACAQIwCwYHK\
55+
oZIzjgEAwUAAzAAMC0CFBaZDryEEOr8Cw7sOAAAAKaDgtHcAhUAkUenJpwYZgS6IPjy\
56+
AjZG+RfHdO4=""");
57+
58+
// Fuzzed data input stream looks like an x509.X400Address
59+
// in the CertificateIssuerExtension. A CRLException is thrown
60+
// because an X500Name is expected.
61+
byte[] encoded_2 = Base64.getDecoder().decode("""
62+
MIIBljCCAVMCAQEwCwYHKoZIzjgEAwUAMC0xEzARBgoJkiaJk/IsZAEZEwNjb20xFjA\
63+
UBgoJkiaJk/IsZAEZEwZ0ZXN0J0EXDTAzMDcxNTE2MjAwNVoXDTAzMDcyMDE2MjAwNV\
64+
owgdIwUwIBBBcNMDMwNzE1MTYyMDA0WjA/MD0GA1UdHQEB/wQzMDGkLzETMBEGCgmSJ\
65+
omT8ixkARkTA2NvbTEYMBYGCgmSJomT8ixkARkTCGNlcnRzUlVTMBICAQMXDTAzMDcx\
66+
NTE2MjAwNFowUwIBAhcNMDMwNzE1MTYyMDA0WjA/MD0GA1UdHQEB/wQzMDGjLzETMBE\
67+
GCgmSJomT8ixkARkTA2NvGG0wMRYGCgmSJomT8ixkARkTCG15VGVzdENBMBICAQEXDT\
68+
AzMDcxNTE2MjAwNVqgHzAdMGAGA1UdHAEB/wQFMAOEAf8wCgYDVR0UBAMCAQIwCwYHK\
69+
oZIzjgEAwUAAzAAMC0CFBaZDryEEOr8Cw7sJa07gqaDgtHcAhUAkUenJpwYZgS6IPjy\
70+
AjZG+RfHdO4=""");
71+
72+
cf = CertificateFactory.getInstance("X.509", "SUN");
73+
74+
run(encoded_1);
75+
run(encoded_2);
76+
}
77+
78+
private static void run(byte[] buf) {
79+
Utils.runAndCheckException(
80+
() -> cf.generateCRLs(new ByteArrayInputStream(buf)),
81+
CRLException.class);
82+
}
83+
}

0 commit comments

Comments
 (0)