Path: blob/master/test/jdk/sun/security/ssl/GenSSLConfigs/ClientThread.java
41152 views
/*1* Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.net.*;24import javax.net.ssl.*;2526class ClientThread extends Handler27implements HandshakeCompletedListener28{29private int port;30private InetAddress server;31private SSLSocketFactory factory;3233static private int threadCounter = 0;3435private static synchronized int getCounter ()36{ return ++threadCounter; }3738ClientThread (int port, SSLContext ctx)39{40super ("Client-" + getCounter ());41roleIsClient = true;42factory = ctx.getSocketFactory();4344try {45this.server = InetAddress.getLocalHost ();46this.port = port;47} catch (UnknownHostException e) {48synchronized (out) {49out.println ("%% " + getName ());50e.printStackTrace (out);51}52}53}5455ClientThread (InetAddress server, int port, SSLContext ctx)56{57super ("Client-" + getCounter ());58roleIsClient = true;59factory = ctx.getSocketFactory();6061this.server = server;62this.port = port;63}646566public void setReverseRole (boolean flag)67{68if (flag)69roleIsClient = false;70else71roleIsClient = true;72}7374public void run ()75{76try {77s = (SSLSocket) factory.createSocket(server, port);7879} catch (Throwable t) {80synchronized (out) {81out.println ("%% " + getName ());82t.printStackTrace (out);83}84return;85}8687if (basicCipherSuites != null) {88s.setEnabledCipherSuites (basicCipherSuites);89if (basicCipherSuites.length == 1)90System.out.println ("%% " + getName () + " trying "91+ basicCipherSuites [0]);92}9394super.run ();9596out.println ("%% " + getName ()97+ (passed () ? ", Passed!" : " ... FAILED"));98}99100}101102103