Path: blob/master/test/jdk/sun/security/provider/X509Factory/BigCRL.java
41154 views
/*1* Copyright (c) 2011, 2014, 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* @modules java.base/sun.security.x50928* @run main/othervm -Xshare:off -Xmx1024m BigCRL29*/3031import java.io.FileInputStream;32import java.math.BigInteger;33import java.security.KeyStore;34import java.security.cert.Certificate;35import java.security.PrivateKey;36import java.security.cert.X509CRLEntry;37import java.util.Arrays;38import java.util.Date;39import sun.security.x509.*;40import java.security.cert.CertificateFactory;41import java.io.ByteArrayInputStream;4243public class BigCRL {4445public static void main(String[] args) throws Exception {46int n = 500000;47String ks = System.getProperty("test.src", ".")48+ "/../../../../javax/net/ssl/etc/keystore";49String pass = "passphrase";50String alias = "dummy";5152KeyStore keyStore = KeyStore.getInstance("JKS");53keyStore.load(new FileInputStream(ks), pass.toCharArray());54Certificate signerCert = keyStore.getCertificate(alias);55byte[] encoded = signerCert.getEncoded();56X509CertImpl signerCertImpl = new X509CertImpl(encoded);57X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(58X509CertImpl.NAME + "." + X509CertImpl.INFO);59X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "."60+ X509CertInfo.DN_NAME);6162Date date = new Date();63PrivateKey privateKey = (PrivateKey)64keyStore.getKey(alias, pass.toCharArray());65String sigAlgName = signerCertImpl.getSigAlgOID();6667X509CRLEntry[] badCerts = new X509CRLEntry[n];68CRLExtensions ext = new CRLExtensions();69ext.set("Reason", new CRLReasonCodeExtension(1));70for (int i = 0; i < n; i++) {71badCerts[i] = new X509CRLEntryImpl(72BigInteger.valueOf(i), date, ext);73}74X509CRLImpl crl = new X509CRLImpl(owner, date, date, badCerts);75crl.sign(privateKey, sigAlgName);76byte[] data = crl.getEncodedInternal();7778// Make sure the CRL is big enough79if ((data[1]&0xff) != 0x84) {80throw new Exception("The file should be big enough?");81}8283CertificateFactory cf = CertificateFactory.getInstance("X.509");84cf.generateCRL(new ByteArrayInputStream(data));85}86}87888990