Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/cert/CertPathValidator/nameConstraints/NameConstraintsWithoutRID.java
41161 views
1
/*
2
* Copyright (c) 2009, 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
*
27
* @bug 6845286
28
* @summary Add regression test for name constraints
29
* @author Xuelei Fan
30
*/
31
32
import java.io.*;
33
import java.net.SocketException;
34
import java.util.*;
35
import java.security.Security;
36
import java.security.cert.*;
37
import java.security.cert.CertPathValidatorException.BasicReason;
38
39
public class NameConstraintsWithoutRID {
40
41
static String selfSignedCertStr =
42
"-----BEGIN CERTIFICATE-----\n" +
43
"MIICTjCCAbegAwIBAgIJAIoSzC1A/k4vMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
44
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxMloXDTMwMDQx\n" +
45
"NzA5MjcxMlowHzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUwgZ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0wco+c7rsyEbP0CRQunVIP8/kOL8+zyQix+QZquY23tvBCbia424GXDkT\n" +
65
"irvK/M4yGzrdS51hA5dlH3SHY3CWOAqEPqKtNLn1My4MWtTiUWbHi0YjFuOv0BXz\n" +
66
"x9lTEfMf+3QcOgO5FitcqHIMP4jIlT+lAgMBAAGjgaYwgaMwHQYDVR0OBBYEFJHg\n" +
67
"eyEWcjxcAwc01BPQrau/4HJaME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsP\n" +
68
"UvDtoSOkITAfMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A\n" +
69
"/k4vMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgIEMBMGA1UdHgQMMAqhCDAG\n" +
70
"iAQqAwQFMA0GCSqGSIb3DQEBBQUAA4GBAI3CDQWZiTlVVVqfCiZwc/yIL7G5bu2g\n" +
71
"ccgVz9PyKfTpq8vk59S23TvPwdPt4ZVx4RSoar9ONtbrcLxfP3X6WQ7e9popWNZV\n" +
72
"q49YfyU1tD5HFuxj7CAsvfykuRo4ovXaTCVWlTMi7fJJdzU0Eb4xkXXhiWT/RbHG\n" +
73
"R7J+8ROMZ+nR\n" +
74
"-----END CERTIFICATE-----";
75
76
static String targetCertStr =
77
"-----BEGIN CERTIFICATE-----\n" +
78
"MIICPTCCAaagAwIBAgIJAOA8c10w019WMA0GCSqGSIb3DQEBBQUAMDExCzAJBgNV\n" +
79
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFzcy0xMB4XDTA5\n" +
80
"MDUwNzEwMjY0MloXDTI5MDEyMjEwMjY0MlowPzELMAkGA1UEBhMCVVMxEDAOBgNV\n" +
81
"BAoTB0V4YW1wbGUxEDAOBgNVBAsTB0NsYXNzLTExDDAKBgNVBAMTA0JvYjCBnzAN\n" +
82
"BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAx4N+y29y5mAGnVQHA3x3fQehxm3nFohQ\n" +
83
"gKV10bZ24/hwZn6rZXG6VsBaqkrgw7ipRZzk99etihAomAFL9k0q/0nxFP/Ovwio\n" +
84
"NzacF3vpv85FF6ATwY1Zs+p4hfxU3WnnyyS9la9Z3o5QBhQbV/WjA/JSG5+ImQFp\n" +
85
"nLkPfzU4wXECAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBTxUJG+QewS\n" +
86
"rSGcuiJy+K4gb1g/BzAfBgNVHSMEGDAWgBSR4HshFnI8XAMHNNQT0K2rv+ByWjAN\n" +
87
"BgkqhkiG9w0BAQUFAAOBgQA9fDeTtSXmP/MEni0vtAmgTPd6R31NcPWKibDizwYS\n" +
88
"BWjUMcbTN8xeXjm4uQLMK8ZQy2+cmNrTvQ59BZ8Y97y7SJUcBLOW5eivO/mKuBsC\n" +
89
"ACB9IxBUGVEwNup7KJ5ixox5jKt+qPwzCheyQQb9NEDJdB0YaHRhFpCcpCFak8yK\n" +
90
"/A==\n" +
91
"-----END CERTIFICATE-----";
92
93
private static CertPath generateCertificatePath()
94
throws CertificateException {
95
// generate certificate from cert strings
96
CertificateFactory cf = CertificateFactory.getInstance("X.509");
97
98
ByteArrayInputStream is;
99
100
is = new ByteArrayInputStream(targetCertStr.getBytes());
101
Certificate targetCert = cf.generateCertificate(is);
102
103
is = new ByteArrayInputStream(subCaCertStr.getBytes());
104
Certificate subCaCert = cf.generateCertificate(is);
105
106
is = new ByteArrayInputStream(selfSignedCertStr.getBytes());
107
Certificate selfSignedCert = cf.generateCertificate(is);
108
109
// generate certification path
110
List<Certificate> list = Arrays.asList(new Certificate[] {
111
targetCert, subCaCert, selfSignedCert});
112
113
return cf.generateCertPath(list);
114
}
115
116
private static Set<TrustAnchor> generateTrustAnchors()
117
throws CertificateException {
118
// generate certificate from cert string
119
CertificateFactory cf = CertificateFactory.getInstance("X.509");
120
121
ByteArrayInputStream is =
122
new ByteArrayInputStream(selfSignedCertStr.getBytes());
123
Certificate selfSignedCert = cf.generateCertificate(is);
124
125
// generate a trust anchor
126
TrustAnchor anchor =
127
new TrustAnchor((X509Certificate)selfSignedCert, null);
128
129
return Collections.singleton(anchor);
130
}
131
132
public static void main(String args[]) throws Exception {
133
CertPath path = generateCertificatePath();
134
Set<TrustAnchor> anchors = generateTrustAnchors();
135
136
PKIXParameters params = new PKIXParameters(anchors);
137
138
// disable certificate revocation checking
139
params.setRevocationEnabled(false);
140
141
// set the validation time
142
params.setDate(new Date(109, 5, 8)); // 2009-05-01
143
144
// disable OCSP checker
145
Security.setProperty("ocsp.enable", "false");
146
147
// disable CRL checker
148
System.setProperty("com.sun.security.enableCRLDP", "false");
149
150
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
151
152
try {
153
validator.validate(path, params);
154
} catch (CertPathValidatorException uoe) {
155
// unexpected exception, rethrow it.
156
throw uoe;
157
}
158
}
159
}
160
161