Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/security/cert/CertPathBuilder/selfIssued/StatusLoopDependency.java
48803 views
1
/*
2
* Copyright (c) 2009, 2014, 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
// Security properties, once set, cannot revert to unset. To avoid
26
// conflicts with tests running in the same VM isolate this test by
27
// running it in otherVM mode.
28
//
29
30
/**
31
* @test
32
* @bug 6852744
33
* @summary PIT b61: PKI test suite fails because self signed certificates
34
* are being rejected
35
* @run main/othervm StatusLoopDependency subca
36
* @run main/othervm StatusLoopDependency subci
37
* @run main/othervm StatusLoopDependency alice
38
* @author Xuelei Fan
39
*/
40
41
import java.io.*;
42
import java.net.SocketException;
43
import java.util.*;
44
import java.security.Security;
45
import java.security.cert.*;
46
import java.security.cert.CertPathValidatorException.BasicReason;
47
import sun.security.util.DerInputStream;
48
49
/**
50
* KeyUsage extension plays a important rule during looking for the issuer
51
* of a certificate or CRL. A certificate issuer should have the keyCertSign
52
* bit set, and a CRL issuer should have the cRLSign bit set.
53
*
54
* Sometime, a delegated CRL issuer would also have the keyCertSign bit set,
55
* as would be troublesome to find the proper CRL issuer during certificate
56
* path build if the delegated CRL issuer is a self-issued certificate, for
57
* it is hard to identify it from its issuer by the "issuer" field only.
58
*
59
* In the test case, the delegated CRL issuers have keyCertSign bit set, and
60
* the CAs have the cRLSign bit set also. If we cannot identify the delegated
61
* CRL issuer from its issuer, there is a potential loop to find the correct
62
* CRL.
63
*
64
* And when revocation enabled, needs to check the status of the delegated
65
* CRL issuers. If the delegated CRL issuer issues itself status, there is
66
* a potential loop to verify the CRL and check the status of delegated CRL
67
* issuer.
68
*
69
* The fix of 6852744 should addresses above issues.
70
*/
71
public final class StatusLoopDependency {
72
73
// the trust anchor
74
static String selfSignedCertStr =
75
"-----BEGIN CERTIFICATE-----\n" +
76
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
77
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMThaFw0zMDA2MDgxMzMyMTha\n" +
78
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
79
"AQUAA4GNADCBiQKBgQDInJhXi0655bPXAVkz1n5I6fAcZejzPnOPuwq3hU3OxFw8\n" +
80
"81Uf6o9oKI1h4w4XAD8u1cUNOgiX+wPwojronlp68bIfO6FVhNf287pLtLhNJo+7\n" +
81
"m6Qxw3ymFvEKy+PVj20CHSggdKHxUa4MBZBmHMFNBuxfYmjwzn+yTMmCCXOvSwID\n" +
82
"AQABo4GJMIGGMB0GA1UdDgQWBBSQ52Dpau+gtL+Kc31dusYnKj16ZTBHBgNVHSME\n" +
83
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
84
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
85
"DQYJKoZIhvcNAQEEBQADgYEAjBt6ea65HCqbGsS2rs/HhlGusYXtThRVC5vwXSey\n" +
86
"ZFYwSgukuq1KDzckqZFu1meNImEwdZjwxdN0e2p/nVREPC42rZliSj6V1ThayKXj\n" +
87
"DWEZW1U5aR8T+3NYfDrdKcJGx4Hzfz0qKz1j4ssV1M9ptJxYYv4y2Da+592IN1S9\n" +
88
"v/E=\n" +
89
"-----END CERTIFICATE-----";
90
91
// the sub-ca
92
static String subCaCertStr =
93
"-----BEGIN CERTIFICATE-----\n" +
94
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
95
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjRaFw0yOTAzMTUxMzMyMjRa\n" +
96
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
97
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFv24SK78VI0gWlyIrq/X\n" +
98
"srl1431K5hJJxMYZtaQunyPmrYg3oI9KvKFykxnR0N4XDPaIi75p9dXGppVu80BA\n" +
99
"+csvIPBwlBQoNmKDQWTziDOqfK4tE+IMuL/Y7pxnH6CDMY7VGpvatty2zcmH+m/v\n" +
100
"E/n+HPyeELJQT2rT/3T+7wIDAQABo4GJMIGGMB0GA1UdDgQWBBRidC8Dt3dBzYES\n" +
101
"KpR2tR560sZ0+zBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
102
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
103
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMeMKqrMr5d3eTQsv\n" +
104
"MYOD15Dl3THQGLAa4ad5Eyq5/1eUeEOpztzCgDfi0iPD8YCubIEVasBTSqTiGXqb\n" +
105
"RpGuPHOwwfWvHrTeHSludiFBAUiKj7aEV+oQa0FBn4U4TT8HA62HQ93FhzTDI3jP\n" +
106
"iil34GktVl6gfMKGzUEW/Dh8OM4=\n" +
107
"-----END CERTIFICATE-----";
108
109
// a delegated CRL issuer, it's a self-issued certificate of trust anchor
110
static String topCrlIssuerCertStr =
111
"-----BEGIN CERTIFICATE-----\n" +
112
"MIICPjCCAaegAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
113
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjNaFw0yOTAzMTUxMzMyMjNa\n" +
114
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
115
"AQUAA4GNADCBiQKBgQC99u93trf+WmpfiqunJy/P31ej1l4rESxft2JSGNjKuLFN\n" +
116
"/BO3SAugGJSkCARAwXjB0c8eeXhXWhVVWdNpbKepRJTxrjDfnFIavLgtUvmFwn/3\n" +
117
"hPXe+RQeA8+AJ99Y+o+10kY8JAZLa2j93C2FdmwOjUbo8aIz85yhbiV1tEDjLwID\n" +
118
"AQABo4GJMIGGMB0GA1UdDgQWBBSyFyA3XWLbdL6W6hksmBn7RKsQmDBHBgNVHSME\n" +
119
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
120
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
121
"DQYJKoZIhvcNAQEEBQADgYEAHTm8aRTeakgCfEBCgSWK9wvMW1c18ANGMm8OFDBk\n" +
122
"xabVy9BT0MVFHlaneh89oIxTZN0FMTpg21GZMAvIzhEt7DGdO7HLsW7JniN7/OZ0\n" +
123
"rACmpK5frmZrLS03zUm8c+rTbazNfYLoZVG3/mDZbKIi+4y8IGnFcgLVsHsYoBNP\n" +
124
"G0c=\n" +
125
"-----END CERTIFICATE-----";
126
127
// a delegated CRL issuer, it's a self-issued certificate of sub-ca
128
static String subCrlIssuerCertStr =
129
"-----BEGIN CERTIFICATE-----\n" +
130
"MIICUDCCAbmgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
131
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjdaFw0yOTAzMTUxMzMyMjda\n" +
132
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
133
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+8AcLJtGAVUWvv3ifcyQw\n" +
134
"OGqwzcPrBw/XCs6vTMlcdtFzcH1M+Z3/QHN9+5VT1gqeTIZ+b8g9005Og3XKy/HX\n" +
135
"obXZeLv20VZsr+jm52ySghEYOVCTJ9OyFOAp5adp6nf0cA66Feh3LsmVhpTEcDOG\n" +
136
"GnyntQm0DBYxRoOT/GBlvQIDAQABo4GJMIGGMB0GA1UdDgQWBBSRWhMuZLQoHSDN\n" +
137
"xhxr+vdDmfAY8jBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
138
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
139
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMIDZLdOLFiPyS1bh\n" +
140
"Ch4eUYHT+K1WG93skbga3kVYg3GSe+gctwkKwKK13bwfi8zc7wwz6MtmQwEYhppc\n" +
141
"pKKKEwi5QirBCP54rihLCvRQaj6ZqUJ6VP+zPAqHYMDbzlBbHtVF/1lQUP30I6SV\n" +
142
"Fu987DvLmZ2GuQA9FKJsnlD9pbU=\n" +
143
"-----END CERTIFICATE-----";
144
145
// the target EE certificate
146
static String targetCertStr =
147
"-----BEGIN CERTIFICATE-----\n" +
148
"MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
149
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy\n" +
150
"MzBaFw0yOTAzMTUxMzMyMzBaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
151
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG\n" +
152
"9w0BAQEFAAOBjQAwgYkCgYEA7wnsvR4XEOfVznf40l8ClLod+7L0y2/+smVV+GM/\n" +
153
"T1/QF/stajAJxXNy08gK00WKZ6ruTHhR9vh/Z6+EQM2RZDCpU0A7LPa3kLE/XTmS\n" +
154
"1MLDu8ntkdlpURpvhdDWem+rl2HU5oZgzV8Jkcov9vXuSjqEDfr45FlPuV40T8+7\n" +
155
"cxsCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSBwsAhi6Z1kriOs3ty\n" +
156
"uSIujv9a3DAfBgNVHSMEGDAWgBRidC8Dt3dBzYESKpR2tR560sZ0+zANBgkqhkiG\n" +
157
"9w0BAQQFAAOBgQDEiBqd5AMy2SQopFaS3dYkzj8MHlwtbCSoNVYkOfDnewcatrbk\n" +
158
"yFcp6FX++PMdOQFHWvvnDdkCUAzZQp8kCkF9tGLVLBtOK7XxQ1us1LZym7kOPzsd\n" +
159
"G93Dcf0U1JRO77juc61Br5paAy8Bok18Y/MeG7uKgB2MAEJYKhGKbCrfMw==\n" +
160
"-----END CERTIFICATE-----";
161
162
// CRL issued by the delegated CRL issuer, topCrlIssuerCertStr
163
static String topCrlStr =
164
"-----BEGIN X509 CRL-----\n" +
165
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
166
"ChMHRXhhbXBsZRcNMDkwNjI4MTMzMjM4WhcNMjgwODI3MTMzMjM4WjAiMCACAQUX\n" +
167
"DTA5MDYyODEzMzIzN1owDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQEwDQYJ\n" +
168
"KoZIhvcNAQEEBQADgYEAVUIeu2x7ZwsliafoCBOg+u8Q4S/VFfTe/SQnRyTM3/V1\n" +
169
"v+Vn5Acc7eo8Rh4AHcnFFbLNk38n6lllov/CaVR0IPZ6hnrNHVa7VYkNlRAwV2aN\n" +
170
"GUUhkMMOLVLnN25UOrN9J637SHmRE6pB+TRMaEQ73V7UNlWxuSMK4KofWen0A34=\n" +
171
"-----END X509 CRL-----";
172
173
// CRL issued by the delegated CRL issuer, subCrlIssuerCertStr
174
static String subCrlStr =
175
"-----BEGIN X509 CRL-----\n" +
176
"MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
177
"ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNjI4MTMzMjQzWhcNMjgw\n" +
178
"ODI3MTMzMjQzWjAiMCACAQQXDTA5MDYyODEzMzIzOFowDDAKBgNVHRUEAwoBBKAO\n" +
179
"MAwwCgYDVR0UBAMCAQEwDQYJKoZIhvcNAQEEBQADgYEACQZEf6ydb3fKTMPJ8DBO\n" +
180
"oo630MsrT3P0x0AC4+aQOueCBaGpNqW/H379uZxXAad7yr+aXUBwaeBMYVKUbwOe\n" +
181
"5TrN5QWPe2eCkU+MSQvh1SHASDDMH4jhWFMRdO3aPMDKKPlO/Q3s0G72eD7Zo5dr\n" +
182
"N9AvUXxGxU4DruoJuFPcrCI=\n" +
183
"-----END X509 CRL-----";
184
185
private static Set<TrustAnchor> generateTrustAnchors()
186
throws CertificateException {
187
// generate certificate from cert string
188
CertificateFactory cf = CertificateFactory.getInstance("X.509");
189
190
ByteArrayInputStream is =
191
new ByteArrayInputStream(selfSignedCertStr.getBytes());
192
Certificate selfSignedCert = cf.generateCertificate(is);
193
194
// generate a trust anchor
195
TrustAnchor anchor =
196
new TrustAnchor((X509Certificate)selfSignedCert, null);
197
198
return Collections.singleton(anchor);
199
}
200
201
private static CertStore generateCertificateStore() throws Exception {
202
Collection entries = new HashSet();
203
204
// generate certificate from certificate string
205
CertificateFactory cf = CertificateFactory.getInstance("X.509");
206
207
ByteArrayInputStream is;
208
209
is = new ByteArrayInputStream(targetCertStr.getBytes());
210
Certificate cert = cf.generateCertificate(is);
211
entries.add(cert);
212
213
is = new ByteArrayInputStream(subCaCertStr.getBytes());
214
cert = cf.generateCertificate(is);
215
entries.add(cert);
216
217
is = new ByteArrayInputStream(selfSignedCertStr.getBytes());
218
cert = cf.generateCertificate(is);
219
entries.add(cert);
220
221
is = new ByteArrayInputStream(topCrlIssuerCertStr.getBytes());
222
cert = cf.generateCertificate(is);
223
entries.add(cert);
224
225
is = new ByteArrayInputStream(subCrlIssuerCertStr.getBytes());
226
cert = cf.generateCertificate(is);
227
entries.add(cert);
228
229
// generate CRL from CRL string
230
is = new ByteArrayInputStream(topCrlStr.getBytes());
231
Collection mixes = cf.generateCRLs(is);
232
entries.addAll(mixes);
233
234
is = new ByteArrayInputStream(subCrlStr.getBytes());
235
mixes = cf.generateCRLs(is);
236
entries.addAll(mixes);
237
238
return CertStore.getInstance("Collection",
239
new CollectionCertStoreParameters(entries));
240
}
241
242
private static X509CertSelector generateSelector(String name)
243
throws Exception {
244
X509CertSelector selector = new X509CertSelector();
245
246
// generate certificate from certificate string
247
CertificateFactory cf = CertificateFactory.getInstance("X.509");
248
ByteArrayInputStream is = null;
249
if (name.equals("subca")) {
250
is = new ByteArrayInputStream(subCaCertStr.getBytes());
251
} else if (name.equals("subci")) {
252
is = new ByteArrayInputStream(subCrlIssuerCertStr.getBytes());
253
} else {
254
is = new ByteArrayInputStream(targetCertStr.getBytes());
255
}
256
257
X509Certificate target = (X509Certificate)cf.generateCertificate(is);
258
byte[] extVal = target.getExtensionValue("2.5.29.14");
259
if (extVal != null) {
260
DerInputStream in = new DerInputStream(extVal);
261
byte[] subjectKID = in.getOctetString();
262
selector.setSubjectKeyIdentifier(subjectKID);
263
} else {
264
// unlikely to happen.
265
throw new Exception("unexpected certificate: no SKID extension");
266
}
267
268
return selector;
269
}
270
271
private static boolean match(String name, Certificate cert)
272
throws Exception {
273
X509CertSelector selector = new X509CertSelector();
274
275
// generate certificate from certificate string
276
CertificateFactory cf = CertificateFactory.getInstance("X.509");
277
ByteArrayInputStream is = null;
278
if (name.equals("subca")) {
279
is = new ByteArrayInputStream(subCaCertStr.getBytes());
280
} else if (name.equals("subci")) {
281
is = new ByteArrayInputStream(subCrlIssuerCertStr.getBytes());
282
} else {
283
is = new ByteArrayInputStream(targetCertStr.getBytes());
284
}
285
X509Certificate target = (X509Certificate)cf.generateCertificate(is);
286
287
return target.equals(cert);
288
}
289
290
291
public static void main(String[] args) throws Exception {
292
// MD5 is used in this test case, don't disable MD5 algorithm.
293
Security.setProperty(
294
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
295
296
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
297
298
X509CertSelector selector = generateSelector(args[0]);
299
300
Set<TrustAnchor> anchors = generateTrustAnchors();
301
CertStore certs = generateCertificateStore();
302
303
304
PKIXBuilderParameters params =
305
new PKIXBuilderParameters(anchors, selector);
306
params.addCertStore(certs);
307
params.setRevocationEnabled(true);
308
params.setDate(new Date(109, 7, 1)); // 2009-07-01
309
Security.setProperty("ocsp.enable", "false");
310
System.setProperty("com.sun.security.enableCRLDP", "true");
311
312
PKIXCertPathBuilderResult result =
313
(PKIXCertPathBuilderResult)builder.build(params);
314
315
if (!match(args[0], result.getCertPath().getCertificates().get(0))) {
316
throw new Exception("unexpected certificate");
317
}
318
}
319
}
320
321