|
| 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