33 class JSSEClient extends CipherTestUtils.Client { |
33 class JSSEClient extends CipherTestUtils.Client { |
34 |
34 |
35 private static final String DEFAULT = "DEFAULT"; |
35 private static final String DEFAULT = "DEFAULT"; |
36 private static final String TLS = "TLS"; |
36 private static final String TLS = "TLS"; |
37 |
37 |
38 private final SSLContext sslContext; |
38 private final SSLContext context; |
39 private final MyX509KeyManager keyManager; |
39 private final MyX509KeyManager keyManager; |
40 private final int serverPort; |
40 private final int port; |
41 private final String serverHost; |
41 private final String host; |
42 private final String testedProtocol; |
42 private final String protocol; |
43 |
43 |
44 JSSEClient(CipherTestUtils cipherTest, String serverHost, int serverPort, |
44 JSSEClient(CipherTestUtils cipherTest, String host, int port, |
45 String testedProtocols, String testedCipherSuite) throws Exception { |
45 String protocols, String ciphersuite) throws Exception { |
46 super(cipherTest, testedCipherSuite); |
46 super(cipherTest, ciphersuite); |
47 this.serverHost = serverHost; |
47 this.host = host; |
48 this.serverPort = serverPort; |
48 this.port = port; |
49 this.testedProtocol = testedProtocols; |
49 this.protocol = protocols; |
50 this.keyManager = |
50 this.keyManager = new MyX509KeyManager( |
51 new MyX509KeyManager(cipherTest.getClientKeyManager()); |
51 cipherTest.getClientKeyManager()); |
52 sslContext = SSLContext.getInstance(TLS); |
52 context = SSLContext.getInstance(TLS); |
53 } |
53 } |
54 |
54 |
55 @Override |
55 @Override |
56 void runTest(CipherTestUtils.TestParameters params) throws Exception { |
56 void runTest(CipherTestUtils.TestParameters params) throws Exception { |
57 SSLSocket socket = null; |
57 keyManager.setAuthType(params.clientAuth); |
58 try { |
58 context.init( |
59 System.out.println("Connecting to server..."); |
59 new KeyManager[]{ keyManager }, |
60 keyManager.setAuthType(params.clientAuth); |
60 new TrustManager[]{ cipherTest.getClientTrustManager() }, |
61 sslContext.init(new KeyManager[]{keyManager}, |
61 CipherTestUtils.secureRandom); |
62 new TrustManager[]{cipherTest.getClientTrustManager()}, |
62 SSLSocketFactory factory = (SSLSocketFactory)context.getSocketFactory(); |
63 CipherTestUtils.secureRandom); |
63 |
64 SSLSocketFactory factory = (SSLSocketFactory) sslContext. |
64 System.out.println("Connecting to server..."); |
65 getSocketFactory(); |
65 try (SSLSocket socket = (SSLSocket) factory.createSocket(host, port)) { |
66 socket = (SSLSocket) factory.createSocket(serverHost, |
|
67 serverPort); |
|
68 socket.setSoTimeout(CipherTestUtils.TIMEOUT); |
66 socket.setSoTimeout(CipherTestUtils.TIMEOUT); |
69 socket.setEnabledCipherSuites(params.cipherSuite.split(",")); |
67 socket.setEnabledCipherSuites(params.cipherSuite.split(",")); |
70 if (params.protocol != null && !params.protocol.trim().equals("") |
68 if (params.protocol != null && !params.protocol.trim().isEmpty() |
71 && !params.protocol.trim().equals(DEFAULT)) { |
69 && !params.protocol.trim().equals(DEFAULT)) { |
72 socket.setEnabledProtocols(params.protocol.split(",")); |
70 socket.setEnabledProtocols(params.protocol.split(",")); |
73 } |
71 } |
74 CipherTestUtils.printInfo(socket); |
72 CipherTestUtils.printInfo(socket); |
75 InputStream in = socket.getInputStream(); |
73 InputStream in = socket.getInputStream(); |