Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/FixingJavadocs/SSLSocketInherit.java
41153 views
1
/*
2
* Copyright (c) 2001, 2011, 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 4387882
27
* @summary Need to revisit the javadocs for JSSE, especially the
28
* promoted classes. This test checks to see if the settings
29
* on the server sockets get propagated to the sockets.
30
* @run main/othervm SSLSocketInherit
31
*
32
* SunJSSE does not support dynamic system properties, no way to re-use
33
* system properties in samevm/agentvm mode.
34
* @author Brad Wetmore
35
*/
36
37
import java.net.*;
38
import javax.net.ssl.*;
39
40
public class SSLSocketInherit {
41
String pathToStores = "../etc";
42
static String keyStoreFile = "keystore";
43
static String trustStoreFile = "truststore";
44
static String passwd = "passphrase";
45
46
volatile int serverPort = 0;
47
48
/*
49
* Let's just create silly sockets to do a basic connection,
50
* that's all we really need.
51
*/
52
Thread forkClient() {
53
Thread clientThread = new Thread() {
54
public void run() {
55
try {
56
new Socket("localhost", serverPort);
57
} catch (Exception e) {
58
// ignore for now...
59
}
60
}
61
};
62
clientThread.start();
63
return clientThread;
64
}
65
66
SSLSocketInherit() throws Exception {
67
Exception exc = null;
68
69
String keyFilename =
70
System.getProperty("test.src", "./") + "/" + pathToStores +
71
"/" + keyStoreFile;
72
String trustFilename =
73
System.getProperty("test.src", "./") + "/" + pathToStores +
74
"/" + trustStoreFile;
75
76
System.setProperty("javax.net.ssl.keyStore", keyFilename);
77
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
78
System.setProperty("javax.net.ssl.trustStore", trustFilename);
79
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
80
81
SSLServerSocketFactory sslssf =
82
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
83
SSLServerSocket sslss =
84
(SSLServerSocket) sslssf.createServerSocket(0);
85
serverPort = sslss.getLocalPort();
86
87
Thread client = forkClient();
88
89
String [] ciphers =
90
new String [] { "SSL_RSA_WITH_DES_CBC_SHA" };
91
92
String [] protocols =
93
new String [] { "SSLv3" };
94
95
sslss.setEnabledCipherSuites(ciphers);
96
sslss.setEnabledProtocols(protocols);
97
sslss.setNeedClientAuth(true);
98
sslss.setUseClientMode(true);
99
sslss.setEnableSessionCreation(true);
100
101
SSLSocket ssls = (SSLSocket) sslss.accept();
102
103
if (((ciphers = ssls.getEnabledCipherSuites()) == null) ||
104
(ciphers.length != 1) ||
105
(ciphers[0].compareToIgnoreCase(
106
"SSL_RSA_WITH_DES_CBC_SHA") != 0)) {
107
exc = new Exception("problem with get/setEnabledCipherSuites()");
108
}
109
110
if (((protocols = ssls.getEnabledProtocols()) == null) ||
111
(protocols.length != 1) ||
112
(protocols[0].compareToIgnoreCase(
113
"SSLv3") != 0)) {
114
exc = new Exception("problem with get/setEnabledProtocols()");
115
}
116
117
if (ssls.getNeedClientAuth() != true) {
118
exc = new Exception("problem with get/setNeedClientAuth()");
119
}
120
121
if (ssls.getUseClientMode() != true) {
122
exc = new Exception("problem with get/setUseClientMode()");
123
}
124
125
client.join();
126
127
if (exc != null) {
128
throw exc;
129
}
130
131
System.out.println("First SSLSocket inherited right info");
132
133
/*
134
* Try it again.
135
*/
136
client = forkClient();
137
138
ciphers = new String [] { "SSL_DH_anon_WITH_DES_CBC_SHA" };
139
protocols = new String [] { "TLSv1" };
140
141
sslss.setEnabledCipherSuites(ciphers);
142
sslss.setEnabledProtocols(protocols);
143
sslss.setWantClientAuth(true);
144
sslss.setUseClientMode(false);
145
sslss.setEnableSessionCreation(false);
146
147
ssls = (SSLSocket) sslss.accept();
148
149
if (((ciphers = ssls.getEnabledCipherSuites()) == null) ||
150
(ciphers.length != 1) ||
151
(ciphers[0].compareToIgnoreCase(
152
"SSL_DH_anon_WITH_DES_CBC_SHA") != 0)) {
153
exc = new Exception("problem with get/setEnabledCipherSuites()");
154
}
155
156
if (((protocols = ssls.getEnabledProtocols()) == null) ||
157
(protocols.length != 1) ||
158
(protocols[0].compareToIgnoreCase(
159
"TLSv1") != 0)) {
160
exc = new Exception("problem with get/setEnabledProtocols()");
161
}
162
163
if (ssls.getWantClientAuth() != true) {
164
exc = new Exception("problem with get/setWantClientAuth()");
165
}
166
167
if (ssls.getUseClientMode() != false) {
168
exc = new Exception("problem with get/setUseClientMode()");
169
}
170
171
client.join();
172
173
if (exc != null) {
174
throw exc;
175
}
176
177
System.out.println("Second SSLSocket inherited right info");
178
179
/*
180
* Lastly, try to set some wild suites, and make sure we
181
* catch it.
182
*/
183
184
ciphers = sslss.getSupportedCipherSuites();
185
ciphers[1] = "this isn't a cipher suite";
186
187
try {
188
sslss.setEnabledCipherSuites(ciphers);
189
throw new Exception(
190
"server socket setEnabledCipherSuites didn't throw Exception");
191
} catch (IllegalArgumentException e) {
192
System.out.println("Caught proper Exception on server socket");
193
}
194
195
try {
196
ssls.setEnabledCipherSuites(ciphers);
197
throw new Exception(
198
"socket setEnabledCipherSuites didn't throw Exception");
199
} catch (IllegalArgumentException e) {
200
System.out.println("Caught proper Exception on socket");
201
}
202
203
try {
204
ssls.setEnabledProtocols(null);
205
throw new Exception(
206
"socket setEnabledProtocols null didn't throw Exception");
207
} catch (IllegalArgumentException e) {
208
System.out.println("Caught proper Exception on socket");
209
}
210
211
try {
212
sslss.setEnabledProtocols(null);
213
throw new Exception(
214
"server socket setEnabledProtocols null "+
215
"didn't throw Exception");
216
} catch (IllegalArgumentException e) {
217
System.out.println("Caught proper Exception on server socket");
218
}
219
220
try {
221
ssls.setEnabledCipherSuites(null);
222
throw new Exception(
223
"socket setEnabledCipherSuites null didn't throw Exception");
224
} catch (IllegalArgumentException e) {
225
System.out.println("Caught proper Exception on socket");
226
}
227
228
try {
229
sslss.setEnabledCipherSuites(null);
230
throw new Exception(
231
"server socket setEnabledCipherSuites null "+
232
"didn't throw Exception");
233
} catch (IllegalArgumentException e) {
234
System.out.println("Caught proper Exception on server socket");
235
}
236
237
System.out.println("All tests PASS!");
238
239
}
240
241
public static void main(String args[]) throws Exception {
242
new SSLSocketInherit();
243
}
244
}
245
246