Path: blob/master/test/jdk/javax/net/ssl/sanity/interop/JSSEServer.java
41154 views
/*1* Copyright (c) 2002, 2019, 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.IOException;24import java.io.InputStream;25import java.io.OutputStream;26import java.util.concurrent.Executor;27import java.util.concurrent.Executors;2829import javax.net.ssl.KeyManager;30import javax.net.ssl.SSLContext;31import javax.net.ssl.SSLServerSocket;32import javax.net.ssl.SSLServerSocketFactory;33import javax.net.ssl.SSLSocket;34import javax.net.ssl.TrustManager;3536class JSSEServer extends CipherTest.Server {3738SSLServerSocket serverSocket;3940JSSEServer(CipherTest cipherTest) throws Exception {41super(cipherTest);42SSLContext serverContext = SSLContext.getInstance("TLS");43serverContext.init(44new KeyManager[] { CipherTest.keyManager },45new TrustManager[] { CipherTest.trustManager },46CipherTest.secureRandom);4748SSLServerSocketFactory factory49= (SSLServerSocketFactory) serverContext.getServerSocketFactory();50serverSocket51= (SSLServerSocket) factory.createServerSocket(CipherTest.serverPort);52CipherTest.serverPort = serverSocket.getLocalPort();5354// JDK-8190492: Enable all supported protocols on server side to test SSLv355serverSocket.setEnabledProtocols(serverSocket.getSupportedProtocols());5657serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());58serverSocket.setWantClientAuth(true);59}6061public void run() {62System.out.println("JSSE Server listening on port " + CipherTest.serverPort);63Executor exec = Executors.newFixedThreadPool64(cipherTest.THREADS, DaemonThreadFactory.INSTANCE);65try {66while (true) {67final SSLSocket socket = (SSLSocket)serverSocket.accept();68socket.setSoTimeout(CipherTest.TIMEOUT);69Runnable r = new Runnable() {70public void run() {71try {72InputStream in = socket.getInputStream();73OutputStream out = socket.getOutputStream();74handleRequest(in, out);75out.flush();76socket.close();77socket.getSession().invalidate();78} catch (IOException e) {79cipherTest.setFailed();80e.printStackTrace();81} finally {82if (socket != null) {83try {84socket.close();85} catch (IOException e) {86cipherTest.setFailed();87System.out.println("Exception closing socket on server side:");88e.printStackTrace();89}90}91}92}93};94exec.execute(r);95}96} catch (IOException e) {97cipherTest.setFailed();98e.printStackTrace();99//100}101}102103}104105106