Path: blob/master/test/jdk/sun/security/ssl/GenSSLConfigs/ServerThread.java
41152 views
/*1* Copyright (c) 1997, 2005, 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.io.*;24import javax.net.ssl.*;2526class ServerThread extends TestThread27implements HandshakeCompletedListener28{29// Basic server identity info30private int port;31private SSLServerSocketFactory factory;3233private int backlog = 50;34private SSLServerSocket ss;3536// Crypto options ... start with basic ciphers, renegotiation37// can use a different set.38private String renegotiateSuites [];3940// Flags controlling testing -- passed to handler41private boolean needClientAuth;4243// Flags controlling testing -- main server thread only44private boolean useMT;4546ServerThread (int port, int backlog, SSLContext ctx)47{48super ("Server");49setDaemon (true);5051this.port = port;52this.backlog = backlog;53factory = ctx.getServerSocketFactory();54}555657// NEGOTIATION OPTIONS5859public void setRenegotiateSuites (String suites [])60{ renegotiateSuites = suites; }616263// DEFINE WHAT IS BEING TESTED6465public void setNeedClientAuth (boolean flag)66{ needClientAuth = flag; }67public boolean getNeedClientAuth ()68{ return needClientAuth; }6970public void setUseMT (boolean flag)71{ useMT = flag; }72public boolean getUseMT ()73{ return useMT; }7475public int getServerPort() {76return port;77}787980public void waitTillReady ()81{82synchronized (this) {83while (ss == null)84try { wait (); }85catch (InterruptedException e) { }86}87}888990public void run ()91{92// NOT TESTING:93// - connection backlog94// - binding to IP address95// - base class methods9697try {98synchronized (this) {99ss = (SSLServerSocket)100factory.createServerSocket(port, backlog);101port = ss.getLocalPort();102notify ();103}104105if (needClientAuth)106ss.setNeedClientAuth (true);107if (basicCipherSuites != null)108ss.setEnabledCipherSuites (basicCipherSuites);109110out.println ("%% Starting " + getName ());111112} catch (Throwable t) {113synchronized (out) {114out.println ("%% Error in " + getName ());115t.printStackTrace (out);116}117118return;119}120121// XXX for N connections ...122123while (true) {124try {125SSLSocket s = (SSLSocket) ss.accept ();126127if (listenHandshake)128s.addHandshakeCompletedListener (this);129130if (verbosity >= 1)131out.println ("%% " + getName () + " accepted from "132+ s.getInetAddress ().getHostName ()133+ ":" + s.getPort ());134135ServerHandler handler = new ServerHandler (s);136137handler.setVerbosity (verbosity);138handler.setOutput (out);139140handler.setDoRenegotiate (doRenegotiate);141handler.setInitiateHandshake (initiateHandshake);142handler.setListenHandshake (listenHandshake);143handler.setReverseRole (reverseRole);144handler.setNeedClientAuth (needClientAuth);145146if (prng != null)147handler.setPRNG (prng);148149if (useMT)150handler.start ();151else152handler.run ();153154} catch (Throwable t) {155synchronized (out) {156out.println ("%% Error in " + getName ());157t.printStackTrace (out);158}159160161return;162}163}164}165166167public void handshakeCompleted (HandshakeCompletedEvent event)168{169if (verbosity >= 2) {170out.println ("%% Handshook: " + event.getSource ());171172// if more verbosity, give cert chain173}174}175}176177178