1 /* |
1 /* |
2 * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
|
24 import java.io.IOException; |
|
25 import java.io.InputStream; |
|
26 import java.io.OutputStream; |
|
27 import java.util.concurrent.Executor; |
|
28 import java.util.concurrent.Executors; |
24 |
29 |
25 import java.io.*; |
30 import javax.net.ssl.KeyManager; |
26 import java.net.*; |
31 import javax.net.ssl.SSLContext; |
27 import java.util.*; |
32 import javax.net.ssl.SSLServerSocket; |
28 import java.util.concurrent.*; |
33 import javax.net.ssl.SSLServerSocketFactory; |
29 |
34 import javax.net.ssl.SSLSocket; |
30 import java.security.*; |
35 import javax.net.ssl.TrustManager; |
31 import java.security.cert.*; |
|
32 import java.security.cert.Certificate; |
|
33 |
|
34 import javax.net.ssl.*; |
|
35 |
36 |
36 class JSSEServer extends CipherTest.Server { |
37 class JSSEServer extends CipherTest.Server { |
37 |
38 |
38 SSLServerSocket serverSocket; |
39 SSLServerSocket serverSocket; |
39 |
40 |
40 JSSEServer(CipherTest cipherTest) throws Exception { |
41 JSSEServer(CipherTest cipherTest) throws Exception { |
41 super(cipherTest); |
42 super(cipherTest); |
42 SSLContext serverContext = SSLContext.getInstance("TLS"); |
43 SSLContext serverContext = SSLContext.getInstance("TLS"); |
43 serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom); |
44 serverContext.init( |
|
45 new KeyManager[] { CipherTest.keyManager }, |
|
46 new TrustManager[] { CipherTest.trustManager }, |
|
47 CipherTest.secureRandom); |
44 |
48 |
45 SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory(); |
49 SSLServerSocketFactory factory |
46 serverSocket = (SSLServerSocket)factory.createServerSocket(cipherTest.serverPort); |
50 = (SSLServerSocketFactory) serverContext.getServerSocketFactory(); |
47 cipherTest.serverPort = serverSocket.getLocalPort(); |
51 serverSocket |
|
52 = (SSLServerSocket) factory.createServerSocket(CipherTest.serverPort); |
|
53 CipherTest.serverPort = serverSocket.getLocalPort(); |
48 serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites()); |
54 serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites()); |
49 serverSocket.setWantClientAuth(true); |
55 serverSocket.setWantClientAuth(true); |
50 } |
56 } |
51 |
57 |
52 public void run() { |
58 public void run() { |
53 System.out.println("JSSE Server listening on port " + cipherTest.serverPort); |
59 System.out.println("JSSE Server listening on port " + CipherTest.serverPort); |
54 Executor exec = Executors.newFixedThreadPool |
60 Executor exec = Executors.newFixedThreadPool |
55 (cipherTest.THREADS, DaemonThreadFactory.INSTANCE); |
61 (cipherTest.THREADS, DaemonThreadFactory.INSTANCE); |
56 try { |
62 try { |
57 while (true) { |
63 while (true) { |
58 final SSLSocket socket = (SSLSocket)serverSocket.accept(); |
64 final SSLSocket socket = (SSLSocket)serverSocket.accept(); |
59 socket.setSoTimeout(cipherTest.TIMEOUT); |
65 socket.setSoTimeout(CipherTest.TIMEOUT); |
60 Runnable r = new Runnable() { |
66 Runnable r = new Runnable() { |
61 public void run() { |
67 public void run() { |
62 try { |
68 try { |
63 InputStream in = socket.getInputStream(); |
69 InputStream in = socket.getInputStream(); |
64 OutputStream out = socket.getOutputStream(); |
70 OutputStream out = socket.getOutputStream(); |