Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/sanity/interop/JSSEServer.java
38861 views
/*1* Copyright (c) 2002, 2018, 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();53serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());54serverSocket.setWantClientAuth(true);55}5657public void run() {58System.out.println("JSSE Server listening on port " + CipherTest.serverPort);59Executor exec = Executors.newFixedThreadPool60(cipherTest.THREADS, DaemonThreadFactory.INSTANCE);61try {62while (true) {63final SSLSocket socket = (SSLSocket)serverSocket.accept();64socket.setSoTimeout(CipherTest.TIMEOUT);65Runnable r = new Runnable() {66public void run() {67try {68InputStream in = socket.getInputStream();69OutputStream out = socket.getOutputStream();70handleRequest(in, out);71out.flush();72socket.close();73socket.getSession().invalidate();74} catch (IOException e) {75cipherTest.setFailed();76e.printStackTrace();77} finally {78if (socket != null) {79try {80socket.close();81} catch (IOException e) {82cipherTest.setFailed();83System.out.println("Exception closing socket on server side:");84e.printStackTrace();85}86}87}88}89};90exec.execute(r);91}92} catch (IOException e) {93cipherTest.setFailed();94e.printStackTrace();95//96}97}9899}100101102