Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/X509Factory/BigCRL.java
38853 views
1
/*
2
* Copyright (c) 2011, 2012, 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 7099399
27
* @summary cannot deal with CRL file larger than 16MB
28
* @run main/othervm -Xshare:off -Xmx1024m BigCRL
29
*/
30
31
import java.io.FileInputStream;
32
import java.math.BigInteger;
33
import java.security.KeyStore;
34
import java.security.cert.Certificate;
35
import java.security.PrivateKey;
36
import java.security.cert.X509CRLEntry;
37
import java.util.Arrays;
38
import java.util.Date;
39
import sun.security.x509.*;
40
import java.security.cert.CertificateFactory;
41
import java.io.ByteArrayInputStream;
42
43
public class BigCRL {
44
45
public static void main(String[] args) throws Exception {
46
int n = 500000;
47
String ks = System.getProperty("test.src", ".")
48
+ "/../../../../javax/net/ssl/etc/keystore";
49
String pass = "passphrase";
50
String alias = "dummy";
51
52
KeyStore keyStore = KeyStore.getInstance("JKS");
53
keyStore.load(new FileInputStream(ks), pass.toCharArray());
54
Certificate signerCert = keyStore.getCertificate(alias);
55
byte[] encoded = signerCert.getEncoded();
56
X509CertImpl signerCertImpl = new X509CertImpl(encoded);
57
X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
58
X509CertImpl.NAME + "." + X509CertImpl.INFO);
59
X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "."
60
+ X509CertInfo.DN_NAME);
61
62
Date date = new Date();
63
PrivateKey privateKey = (PrivateKey)
64
keyStore.getKey(alias, pass.toCharArray());
65
String sigAlgName = signerCertImpl.getSigAlgOID();
66
67
X509CRLEntry[] badCerts = new X509CRLEntry[n];
68
CRLExtensions ext = new CRLExtensions();
69
ext.set("Reason", new CRLReasonCodeExtension(1));
70
for (int i = 0; i < n; i++) {
71
badCerts[i] = new X509CRLEntryImpl(
72
BigInteger.valueOf(i), date, ext);
73
}
74
X509CRLImpl crl = new X509CRLImpl(owner, date, date, badCerts);
75
crl.sign(privateKey, sigAlgName);
76
byte[] data = crl.getEncodedInternal();
77
78
// Make sure the CRL is big enough
79
if ((data[1]&0xff) != 0x84) {
80
throw new Exception("The file should be big enough?");
81
}
82
83
CertificateFactory cf = CertificateFactory.getInstance("X.509");
84
cf.generateCRL(new ByteArrayInputStream(data));
85
}
86
}
87
88
89