Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/GenSSLConfigs/Handler.java
41152 views
1
/*
2
* Copyright (c) 1997, 2001, 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
import java.io.*;
25
import java.net.Socket;
26
import java.net.SocketException;
27
28
import javax.net.ssl.*;
29
30
//
31
// Base connection handler class -- server and client roles are almost
32
// identical, this class holds everything except what's different.
33
//
34
abstract class Handler extends TestThread
35
implements HandshakeCompletedListener
36
{
37
protected SSLSocket s;
38
protected boolean roleIsClient;
39
40
// generates the stream of test data
41
private Traffic traffic;
42
43
// for optional use in renegotiation
44
private String renegotiateSuites [];
45
46
// Test flag: did we pass this test?
47
private boolean pass = false;
48
49
50
Handler (String name)
51
{
52
super (name);
53
}
54
55
56
public void setRenegotiateSuites (String suites [])
57
{ renegotiateSuites = suites; }
58
59
60
abstract public void setReverseRole (boolean flag);
61
62
63
// XXX override setVerbosity() and pass that to
64
// the traffic generation module
65
66
67
public void run ()
68
{
69
try {
70
traffic = new Traffic (s.getInputStream (), s.getOutputStream ());
71
} catch (IOException e) {
72
e.printStackTrace ();
73
return;
74
}
75
76
if (prng != null)
77
traffic.setPRNG (prng);
78
79
if (listenHandshake || doRenegotiate)
80
s.addHandshakeCompletedListener (this);
81
82
try {
83
if (initiateHandshake)
84
s.startHandshake ();
85
86
// XXX if use client auth ...
87
88
doTraffic (0);
89
90
if (doRenegotiate)
91
s.startHandshake ();
92
93
doTraffic (iterations);
94
95
// XXX abortive shutdown should be a test option
96
97
s.close ();
98
99
// XXX want a close-this-session-down option
100
101
} catch (IOException e) {
102
String message = e.getMessage ();
103
104
synchronized (out) {
105
if (message.equalsIgnoreCase ("no cipher suites in common")) {
106
out.println ("%% " + getName () + " " + message);
107
108
} else {
109
out.println ("%% " + getName ());
110
e.printStackTrace (out);
111
}
112
}
113
114
} catch (Throwable t) {
115
synchronized (out) {
116
out.println ("%% " + getName ());
117
t.printStackTrace (out);
118
}
119
}
120
}
121
122
123
public boolean passed ()
124
{ return pass; }
125
126
127
private void doTraffic (int n)
128
throws IOException
129
{
130
try {
131
if (roleIsClient)
132
traffic.initiate (n);
133
else
134
traffic.respond (n);
135
136
pass = true;
137
138
} catch (SSLException e) {
139
String m = e.getMessage ();
140
141
//
142
// As of this writing, self-signed certs won't be accepted
143
// by the simple trust decider. That rules out testing all
144
// of the SSL_DHE_DSS_* flavors for now, and for testers
145
// that don't have a Verisign cert, it also rules out testing
146
// SSL_RSA_* flavors.
147
//
148
// XXX need two things to fix this "right": (a) ability to
149
// let the 'simple trust decider import arbitrary certs, as
150
// exported by a keystore; (b) specialized exceptions, since
151
// comparing message strings is bogus.
152
//
153
if (m.equalsIgnoreCase ("untrusted server cert chain")
154
|| m.equalsIgnoreCase (
155
"Received fatal alert: certificate_unknown")) {
156
System.out.println ("%% " + Thread.currentThread ().getName ()
157
+ ", " + m);
158
s.close ();
159
} else
160
throw e;
161
162
} catch (SocketException e) {
163
String m = e.getMessage ();
164
165
if (m.equalsIgnoreCase ("Socket closed"))
166
System.out.println ("%% " + Thread.currentThread ().getName ()
167
+ ", " + m);
168
else
169
throw e;
170
171
} catch (EOFException e) {
172
// ignore
173
}
174
}
175
176
177
public void handshakeCompleted (HandshakeCompletedEvent event)
178
{
179
if (verbosity >= 1) {
180
Socket sock = (Socket) event.getSource ();
181
182
out.println ("%% " + getName ()
183
+ ", port " + sock.getLocalPort ()
184
+ " to " + sock.getInetAddress ().getHostName ()
185
+ ":" + sock.getPort ()
186
+ ", " + event.getCipherSuite ());
187
188
// if more verbosity, give cert chain
189
}
190
}
191
}
192
193