Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/pkcs11/fips/JSSEServer.java
38855 views
/*1* Copyright (c) 2002, 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 java.net.*;25import java.util.*;26import java.util.concurrent.*;2728import java.security.*;29import java.security.cert.*;30import java.security.cert.Certificate;3132import javax.net.ssl.*;3334class JSSEServer extends CipherTest.Server {3536SSLServerSocket serverSocket;3738JSSEServer(CipherTest cipherTest) throws Exception {39super(cipherTest);40SSLContext serverContext = SSLContext.getInstance("TLS");41serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);4243SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();44serverSocket = (SSLServerSocket)factory.createServerSocket(cipherTest.serverPort);45cipherTest.serverPort = serverSocket.getLocalPort();46serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());47// serverSocket.setWantClientAuth(true);48}4950public void run() {51System.out.println("JSSE Server listening on port " + cipherTest.serverPort);52Executor exec = Executors.newFixedThreadPool53(cipherTest.THREADS, DaemonThreadFactory.INSTANCE);54try {55while (true) {56final SSLSocket socket = (SSLSocket)serverSocket.accept();57socket.setSoTimeout(cipherTest.TIMEOUT);58Runnable r = new Runnable() {59public void run() {60try {61InputStream in = socket.getInputStream();62OutputStream out = socket.getOutputStream();63handleRequest(in, out);64out.flush();65socket.close();66socket.getSession().invalidate();67} catch (IOException e) {68cipherTest.setFailed();69e.printStackTrace();70} finally {71if (socket != null) {72try {73socket.close();74} catch (IOException e) {75cipherTest.setFailed();76System.out.println("Exception closing socket on server side:");77e.printStackTrace();78}79}80}81}82};83exec.execute(r);84}85} catch (IOException e) {86cipherTest.setFailed();87e.printStackTrace();88//89}90}9192}939495