/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
//
// SunJSSE does not support dynamic system properties, no way to re-use
//
/*
* @test
* @bug 4416068 4478803 4479736
* @summary 4273544 JSSE request for function forceV3ClientHello()
* 4479736 setEnabledProtocols API does not work correctly
* 4478803 Need APIs to determine the protocol versions used in an SSL
* session
* 4701722 protocol mismatch exceptions should be consistent between
* SSLv3 and TLSv1
* @author Ram Marti
*/
public class testEnabledProtocols {
/*
* For each of the valid protocols combinations, start a server thread
* that sets up an SSLServerSocket supporting that protocol. Then run
* a client thread that attemps to open a connection with all
* possible protocol combinataion. Verify that we get handshake
* exceptions correctly. Whenever the connection is established
* successfully, verify that the negotiated protocol was correct.
* See results file in this directory for complete results.
*/
{"TLSv1"},
{"TLSv1", "SSLv2Hello"},
{"TLSv1", "SSLv3"},
{"SSLv3", "SSLv2Hello"},
{"SSLv3"},
{"TLSv1", "SSLv3", "SSLv2Hello"}
};
static final boolean [][] eXceptionArray = {
// Do we expect exception? Protocols supported by the server
{ false, true, false, true, true, true }, // TLSv1
{ false, false, false, true, true, false}, // TLSv1,SSLv2Hello
{ false, true, false, true, false, true }, // TLSv1,SSLv3
{ true, true, false, false, false, false}, // SSLv3, SSLv2Hello
{ true, true, false, true, false, true }, // SSLv3
{ false, false, false, false, false, false } // TLSv1,SSLv3,SSLv2Hello
};
// TLSv1
// TLSv1,SSLv2Hello
// TLSv1,SSLv3
// SSLv3, SSLv2Hello
// SSLv3
// TLSv1,SSLv3,SSLv2Hello
{ "TLSv1", "TLSv1", "TLSv1", "SSLv3", "SSLv3", "TLSv1" }
};
/*
* Where do we find the keystores?
*/
/*
* Is the server ready to serve?
*/
volatile static boolean serverReady = false;
/*
* Turn on SSL debugging?
*/
final static boolean debug = false;
// use any free port by default
"/" + keyStoreFile;
"/" + trustStoreFile;
if (debug)
new testEnabledProtocols();
}
/*
* Start the tests.
*/
// sslServerSocket.setNeedClientAuth(true);
eXceptionArray[i][j], protocolSelected[i][j]);
if (clientException != null) {
ss.requestStop();
throw clientException;
}
}
ss.requestStop();
}
}
int numExpConns;
volatile boolean stopRequested = false;
int numExpConns) {
super("Server Thread");
serverReady = false;
this.sslServerSocket = sslServerSocket;
this.numExpConns = numExpConns;
}
public void requestStop() {
stopRequested = true;
}
public void run() {
int conns = 0;
while (!stopRequested) {
try {
serverReady = true;
conns++;
// set ready to false. this is just to make the
// client wait and synchronise exception messages
serverReady = false;
// sleep for a while so that the server thread can be
// stopped
} catch (SSLHandshakeException se) {
// ignore it; this is part of the testing
// log it for debugging
// must have been interrupted, no harm
break;
// must have been interrupted, no harm
break;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
}
} catch (IOException e) {
// ignore
}
}
if (conns >= numExpConns) {
break;
}
}
}
}
}
boolean hsCompleted = false;
boolean exceptionExpected = false;
boolean eXception,
super("Client Thread");
this.enabledP = enabledProtocol;
this.exceptionExpected = eXception;
this.protocolToUse = protocol;
}
public void run() {
try {
while (!serverReady) {
}
} else {
throw new RuntimeException
("expected protocol " + protocolToUse +
" but using " + protocolName);
}
} catch (SSLHandshakeException e) {
if (!exceptionExpected) {
clientException = e;
} else {
}
} catch (RuntimeException e) {
clientException = e;
} catch (Exception e) {
clientException = e;
}
}
}
}