122 private ByteBuffer sTOc; // "reliable" transport server->client 123 124 /* 125 * The following is to set up the keystores/trust material. 126 */ 127 private static final String pathToStores = "../etc"; 128 private static final String keyStoreFile = "keystore"; 129 private static final String trustStoreFile = "truststore"; 130 private static final String passwd = "passphrase"; 131 private static String keyFilename = 132 System.getProperty("test.src", ".") + "/" + pathToStores 133 + "/" + keyStoreFile; 134 private static String trustFilename = 135 System.getProperty("test.src", ".") + "/" + pathToStores 136 + "/" + trustStoreFile; 137 138 /* 139 * Main entry point for this test. 140 */ 141 public static void main(String args[]) throws Exception { 142 if (debug) { 143 System.setProperty("javax.net.debug", "all"); 144 } 145 146 String [] protocols = new String [] { 147 "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" }; 148 149 for (String protocol : protocols) { 150 log("Testing " + protocol); 151 /* 152 * Run the tests with direct and indirect buffers. 153 */ 154 SSLSocketSSLEngineTemplate test = 155 new SSLSocketSSLEngineTemplate(protocol); 156 test.runTest(true); 157 test.runTest(false); 158 } 159 160 System.out.println("Test Passed."); 161 } 162 163 /* 164 * Create an initialized SSLContext to use for these tests. 165 */ 166 public SSLSocketSSLEngineTemplate(String protocol) throws Exception { 167 168 KeyStore ks = KeyStore.getInstance("JKS"); 169 KeyStore ts = KeyStore.getInstance("JKS"); 170 171 char[] passphrase = "passphrase".toCharArray(); 172 173 ks.load(new FileInputStream(keyFilename), passphrase); 174 ts.load(new FileInputStream(trustFilename), passphrase); 175 176 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 312 if (clientMsg[i] != serverIn.get()) { 313 throw new Exception("Client: Data content error"); 314 } 315 } 316 serverIn.compact(); 317 } 318 } 319 return; 320 } catch (Exception e) { 321 serverException = e; 322 } finally { 323 if (socket != null) { 324 socket.close(); 325 } 326 327 // Wait for the client to join up with us. 328 if (thread != null) { 329 thread.join(); 330 } 331 332 if (serverException != null) { 333 if (clientException != null) { 334 serverException.initCause(clientException); 335 } 336 throw serverException; 337 } 338 if (clientException != null) { 339 if (serverException != null) { 340 clientException.initCause(serverException); 341 } 342 throw clientException; 343 } 344 } 345 } 346 347 /* 348 * Create a client thread which does simple SSLSocket operations. 349 * We'll write and read one data packet. 350 */ 351 private Thread createClientThread(final int port, | 122 private ByteBuffer sTOc; // "reliable" transport server->client 123 124 /* 125 * The following is to set up the keystores/trust material. 126 */ 127 private static final String pathToStores = "../etc"; 128 private static final String keyStoreFile = "keystore"; 129 private static final String trustStoreFile = "truststore"; 130 private static final String passwd = "passphrase"; 131 private static String keyFilename = 132 System.getProperty("test.src", ".") + "/" + pathToStores 133 + "/" + keyStoreFile; 134 private static String trustFilename = 135 System.getProperty("test.src", ".") + "/" + pathToStores 136 + "/" + trustStoreFile; 137 138 /* 139 * Main entry point for this test. 140 */ 141 public static void main(String args[]) throws Exception { 142 // reset security properties to make sure that the algorithms 143 // and keys used in this test are not disabled. 144 Security.setProperty("jdk.tls.disabledAlgorithms", ""); 145 Security.setProperty("jdk.certpath.disabledAlgorithms", ""); 146 147 if (debug) { 148 System.setProperty("javax.net.debug", "all"); 149 } 150 151 String [] protocols = new String [] { 152 "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" }; 153 154 for (String protocol : protocols) { 155 log("Testing " + protocol); 156 /* 157 * Run the tests with direct and indirect buffers. 158 */ 159 SSLSocketSSLEngineTemplate test = 160 new SSLSocketSSLEngineTemplate(protocol); 161 log("-------------------------------------"); 162 log("Testing " + protocol + " for direct buffers ..."); 163 test.runTest(true); 164 165 log("---------------------------------------"); 166 log("Testing " + protocol + " for indirect buffers ..."); 167 test.runTest(false); 168 } 169 170 System.out.println("Test Passed."); 171 } 172 173 /* 174 * Create an initialized SSLContext to use for these tests. 175 */ 176 public SSLSocketSSLEngineTemplate(String protocol) throws Exception { 177 178 KeyStore ks = KeyStore.getInstance("JKS"); 179 KeyStore ts = KeyStore.getInstance("JKS"); 180 181 char[] passphrase = "passphrase".toCharArray(); 182 183 ks.load(new FileInputStream(keyFilename), passphrase); 184 ts.load(new FileInputStream(trustFilename), passphrase); 185 186 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 322 if (clientMsg[i] != serverIn.get()) { 323 throw new Exception("Client: Data content error"); 324 } 325 } 326 serverIn.compact(); 327 } 328 } 329 return; 330 } catch (Exception e) { 331 serverException = e; 332 } finally { 333 if (socket != null) { 334 socket.close(); 335 } 336 337 // Wait for the client to join up with us. 338 if (thread != null) { 339 thread.join(); 340 } 341 342 if (sslSocket != null) { 343 sslSocket.close(); 344 } 345 346 if (serverException != null) { 347 if (clientException != null) { 348 serverException.initCause(clientException); 349 } 350 throw serverException; 351 } 352 if (clientException != null) { 353 if (serverException != null) { 354 clientException.initCause(serverException); 355 } 356 throw clientException; 357 } 358 } 359 } 360 361 /* 362 * Create a client thread which does simple SSLSocket operations. 363 * We'll write and read one data packet. 364 */ 365 private Thread createClientThread(final int port, |