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/ssl/X509TrustManagerImpl/CheckNullEntity.java
38853 views
1
/*
2
* Copyright (c) 2005, 2007, 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 5053815
27
* @summary unspecified exceptions in X509TrustManager.checkClient[Server]Truste
28
d
29
* @author Xuelei Fan
30
*/
31
32
import java.io.*;
33
import java.net.*;
34
import javax.net.ssl.*;
35
import java.security.cert.X509Certificate;
36
import java.security.*;
37
import java.util.Enumeration;
38
39
import com.sun.net.ssl.internal.ssl.X509ExtendedTrustManager;
40
41
public class CheckNullEntity {
42
43
/*
44
* =============================================================
45
* Set the various variables needed for the tests, then
46
* specify what tests to run on each side.
47
*/
48
49
/*
50
* Should we run the client or server in a separate thread?
51
* Both sides can throw exceptions, but do you have a preference
52
* as to which side should be the main thread.
53
*/
54
static boolean separateServerThread = true;
55
56
/*
57
* Where do we find the keystores?
58
*/
59
static String pathToStores = "../../../../javax/net/ssl/etc";
60
static String keyStoreFile = "keystore";
61
static String trustStoreFile = "truststore";
62
static String passwd = "passphrase";
63
64
private void initialize() throws Exception {
65
String trustFilename =
66
System.getProperty("test.src", "./") + "/" + pathToStores +
67
"/" + trustStoreFile;
68
char[] passphrase = "passphrase".toCharArray();
69
70
KeyStore ks = KeyStore.getInstance("JKS");
71
ks.load(new FileInputStream(trustFilename), passphrase);
72
73
for (Enumeration e = ks.aliases() ; e.hasMoreElements() ;) {
74
String alias = (String)e.nextElement();
75
if (ks.isCertificateEntry(alias)) {
76
certChain[0] = (X509Certificate)ks.getCertificate(alias);
77
break;
78
}
79
}
80
81
TrustManagerFactory tmf =
82
TrustManagerFactory.getInstance("SunX509");
83
tmf.init(ks);
84
85
trustManager = (X509TrustManager)(tmf.getTrustManagers())[0];
86
}
87
88
/*
89
* =============================================================
90
* The remainder is just support stuff
91
*/
92
public static void main(String[] args) throws Exception {
93
/*
94
* Start the tests.
95
*/
96
new CheckNullEntity();
97
}
98
99
X509Certificate[] certChain = {null, null};
100
X509TrustManager trustManager = null;
101
102
/*
103
* Primary constructor, used to drive remainder of the test.
104
*
105
* Fork off the other side, then do your work.
106
*/
107
CheckNullEntity() throws Exception {
108
String authType = "RSA";
109
int failed = 0x3F; // indicate six tests for normal TM
110
int extFailed = 0x3F; // indicate six tests for extended TM
111
112
initialize();
113
try {
114
try {
115
trustManager.checkClientTrusted(certChain, (String)null);
116
} catch (IllegalArgumentException iae) {
117
// get the right exception
118
failed >>= 1;
119
}
120
121
try {
122
trustManager.checkServerTrusted(certChain, (String)null);
123
} catch (IllegalArgumentException iae) {
124
// get the right exception
125
failed >>= 1;
126
}
127
128
try {
129
trustManager.checkClientTrusted(certChain, "");
130
} catch (IllegalArgumentException iae) {
131
// get the right exception
132
failed >>= 1;
133
}
134
135
try {
136
trustManager.checkServerTrusted(certChain, "");
137
} catch (IllegalArgumentException iae) {
138
// get the right exception
139
failed >>= 1;
140
}
141
142
try {
143
trustManager.checkClientTrusted(null, authType);
144
} catch (IllegalArgumentException iae) {
145
// get the right exception
146
failed >>= 1;
147
}
148
149
try {
150
trustManager.checkServerTrusted(null, authType);
151
} catch (IllegalArgumentException iae) {
152
// get the right exception
153
failed >>= 1;
154
}
155
156
if (trustManager instanceof X509ExtendedTrustManager) {
157
try {
158
((X509ExtendedTrustManager)trustManager).checkClientTrusted(
159
certChain, (String)null, "localhost", null);
160
} catch (IllegalArgumentException iae) {
161
// get the right exception
162
extFailed >>= 1;
163
}
164
165
try {
166
((X509ExtendedTrustManager)trustManager).checkServerTrusted(
167
certChain, (String)null, "localhost", null);
168
} catch (IllegalArgumentException iae) {
169
// get the right exception
170
extFailed >>= 1;
171
}
172
173
try {
174
((X509ExtendedTrustManager)trustManager).checkClientTrusted(
175
certChain, "", "localhost", null);
176
} catch (IllegalArgumentException iae) {
177
// get the right exception
178
extFailed >>= 1;
179
}
180
181
try {
182
((X509ExtendedTrustManager)trustManager).checkServerTrusted(
183
certChain, "", "localhost", null);
184
} catch (IllegalArgumentException iae) {
185
// get the right exception
186
extFailed >>= 1;
187
}
188
189
try {
190
((X509ExtendedTrustManager)trustManager).checkClientTrusted(
191
null, authType, "localhost", null);
192
} catch (IllegalArgumentException iae) {
193
// get the right exception
194
extFailed >>= 1;
195
}
196
197
try {
198
((X509ExtendedTrustManager)trustManager).checkServerTrusted(
199
null, authType, "localhost", null);
200
} catch (IllegalArgumentException iae) {
201
// get the right exception
202
extFailed >>= 1;
203
}
204
} else {
205
extFailed = 0;
206
}
207
} catch (NullPointerException npe) {
208
// IllegalArgumentException should be thrown
209
failed = 1;
210
} catch (Exception e) {
211
// ignore
212
System.out.println("Got another exception e" + e);
213
}
214
215
if (failed != 0 || extFailed != 0) {
216
throw new Exception("Should throw IllegalArgumentException");
217
}
218
}
219
}
220
221