Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/X509Factory/BigCRL.java
38853 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 709939926* @summary cannot deal with CRL file larger than 16MB27* @run main/othervm -Xshare:off -Xmx1024m BigCRL28*/2930import java.io.FileInputStream;31import java.math.BigInteger;32import java.security.KeyStore;33import java.security.cert.Certificate;34import java.security.PrivateKey;35import java.security.cert.X509CRLEntry;36import java.util.Arrays;37import java.util.Date;38import sun.security.x509.*;39import java.security.cert.CertificateFactory;40import java.io.ByteArrayInputStream;4142public class BigCRL {4344public static void main(String[] args) throws Exception {45int n = 500000;46String ks = System.getProperty("test.src", ".")47+ "/../../../../javax/net/ssl/etc/keystore";48String pass = "passphrase";49String alias = "dummy";5051KeyStore keyStore = KeyStore.getInstance("JKS");52keyStore.load(new FileInputStream(ks), pass.toCharArray());53Certificate signerCert = keyStore.getCertificate(alias);54byte[] encoded = signerCert.getEncoded();55X509CertImpl signerCertImpl = new X509CertImpl(encoded);56X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(57X509CertImpl.NAME + "." + X509CertImpl.INFO);58X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "."59+ X509CertInfo.DN_NAME);6061Date date = new Date();62PrivateKey privateKey = (PrivateKey)63keyStore.getKey(alias, pass.toCharArray());64String sigAlgName = signerCertImpl.getSigAlgOID();6566X509CRLEntry[] badCerts = new X509CRLEntry[n];67CRLExtensions ext = new CRLExtensions();68ext.set("Reason", new CRLReasonCodeExtension(1));69for (int i = 0; i < n; i++) {70badCerts[i] = new X509CRLEntryImpl(71BigInteger.valueOf(i), date, ext);72}73X509CRLImpl crl = new X509CRLImpl(owner, date, date, badCerts);74crl.sign(privateKey, sigAlgName);75byte[] data = crl.getEncodedInternal();7677// Make sure the CRL is big enough78if ((data[1]&0xff) != 0x84) {79throw new Exception("The file should be big enough?");80}8182CertificateFactory cf = CertificateFactory.getInstance("X.509");83cf.generateCRL(new ByteArrayInputStream(data));84}85}86878889