1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4495742 27 * @summary Add non-blocking SSL/TLS functionality, usable with any 28 * I/O abstraction 29 * 30 * This is a bit hacky, meant to test various conditions. The main 31 * thing I wanted to do with this was to do buffer reads/writes 32 * when buffers were not empty. (buffer.position() = 10) 33 * The code could certainly be tightened up a lot. 34 * 35 * @author Brad Wetmore 36 * 37 * @run main/othervm ConnectionTest 38 */ 39 40 import javax.net.ssl.*; 41 import javax.net.ssl.SSLEngineResult.*; 42 import java.io.*; 43 import java.security.*; 44 import java.nio.*; 45 46 public class ConnectionTest { 47 48 private SSLContext sslc; 49 private SSLEngine ssle1; 50 private SSLEngine ssle2; 51 52 private static String pathToStores = "../etc"; 53 private static String keyStoreFile = "keystore"; 54 private static String trustStoreFile = "truststore"; 55 private static String passwd = "passphrase"; 56 57 private static String keyFilename = 58 System.getProperty("test.src", "./") + "/" + pathToStores + 59 "/" + keyStoreFile; 60 private static String trustFilename = 61 System.getProperty("test.src", "./") + "/" + pathToStores + 62 "/" + trustStoreFile; 63 64 private ByteBuffer appIn1, appOut1; 65 private ByteBuffer appIn2, appOut2; 66 private ByteBuffer oneToTwo, twoToOne; 67 private ByteBuffer emptyBuffer; 68 69 private ByteBuffer oneToTwoShifter, twoToOneShifter; 70 71 private String hostname = "hostname"; 72 private int portNumber = 77; 73 74 public ConnectionTest() 75 throws Exception { 76 77 sslc = getSSLContext(); 78 ssle1 = sslc.createSSLEngine(hostname, portNumber); 79 ssle2 = sslc.createSSLEngine(); 80 81 ssle1.setEnabledCipherSuites(new String [] { 82 "SSL_RSA_WITH_RC4_128_MD5"}); 83 84 ssle2.setEnabledCipherSuites(new String [] { 85 "SSL_RSA_WITH_RC4_128_MD5"}); 86 87 createBuffers(); 88 } 89 90 private SSLContext getSSLContext() throws Exception { 91 KeyStore ks = KeyStore.getInstance("JKS"); 92 KeyStore ts = KeyStore.getInstance("JKS"); 93 char[] passphrase = "passphrase".toCharArray(); 94 95 ks.load(new FileInputStream(keyFilename), passphrase); 96 ts.load(new FileInputStream(trustFilename), passphrase); 97 98 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 99 kmf.init(ks, passphrase); 100 101 TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 102 tmf.init(ts); 103 104 SSLContext sslCtx = SSLContext.getInstance("TLS"); 105 106 sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); 107 108 return sslCtx; 109 } 110 111 private void createBuffers() { 112 // Size the buffers as appropriate. 113 SSLSession session = ssle1.getSession(); 114 int appBufferMax = session.getApplicationBufferSize(); 115 int netBufferMax = session.getPacketBufferSize(); 116 117 appIn1 = ByteBuffer.allocateDirect(appBufferMax + 10); 118 appIn2 = ByteBuffer.allocateDirect(appBufferMax + 10); 119 120 appIn1.position(10); 121 appIn2.position(10); 122 123 oneToTwo = ByteBuffer.allocateDirect(netBufferMax + 10); 124 twoToOne = ByteBuffer.allocateDirect(netBufferMax + 10); 125 126 oneToTwo.position(10); 127 twoToOne.position(10); 128 oneToTwoShifter = oneToTwo.slice(); 129 twoToOneShifter = twoToOne.slice(); 130 131 appOut1 = ByteBuffer.wrap("Hi Engine2, I'm SSLEngine1".getBytes()); 132 appOut2 = ByteBuffer.wrap("Hello Engine1, I'm SSLEngine2".getBytes()); 133 134 emptyBuffer = ByteBuffer.allocate(10); 135 emptyBuffer.limit(5); 136 emptyBuffer.position(emptyBuffer.limit()); 137 138 System.out.println("AppOut1 = " + appOut1); 139 System.out.println("AppOut2 = " + appOut2); 140 System.out.println(); 141 } 142 143 private void checkResult(SSLEngineResult result, Status status, 144 HandshakeStatus hsStatus, int consumed, int produced, 145 boolean done) throws Exception { 146 147 if ((status != null) && (result.getStatus() != status)) { 148 throw new Exception("Unexpected Status: need = " + status + 149 " got = " + result.getStatus()); 150 } 151 152 if ((hsStatus != null) && (result.getHandshakeStatus() != hsStatus)) { 153 throw new Exception("Unexpected hsStatus: need = " + hsStatus + 154 " got = " + result.getHandshakeStatus()); 155 } 156 157 if ((consumed != -1) && (consumed != result.bytesConsumed())) { 158 throw new Exception("Unexpected consumed: need = " + consumed + 159 " got = " + result.bytesConsumed()); 160 } 161 162 if ((produced != -1) && (produced != result.bytesProduced())) { 163 throw new Exception("Unexpected produced: need = " + produced + 164 " got = " + result.bytesProduced()); 165 } 166 167 if (done && (hsStatus == HandshakeStatus.FINISHED)) { 168 throw new Exception( 169 "Handshake already reported finished"); 170 } 171 172 } 173 174 private boolean isHandshaking(SSLEngine e) { 175 return (e.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING); 176 } 177 178 private void test() throws Exception { 179 ssle1.setUseClientMode(true); 180 ssle2.setUseClientMode(false); 181 ssle2.setNeedClientAuth(true); 182 183 System.out.println("Testing for early unwrap/wrap"); 184 SSLEngineResult result1 = ssle1.unwrap(twoToOne, appIn1); 185 SSLEngineResult result2 = ssle2.wrap(appOut2, oneToTwo); 186 187 /* 188 * These should not consume/produce data, because they 189 * are client and server, respectively, and don't 190 * start handshaking this way. 191 */ 192 checkResult(result1, Status.OK, HandshakeStatus.NEED_WRAP, 193 0, 0, false); 194 checkResult(result2, Status.OK, HandshakeStatus.NEED_UNWRAP, 195 0, 0, false); 196 197 System.out.println("Doing Initial Handshake"); 198 199 boolean done1 = false; 200 boolean done2 = false; 201 202 /* 203 * Do initial handshaking 204 */ 205 while (isHandshaking(ssle1) || 206 isHandshaking(ssle2)) { 207 208 System.out.println("================"); 209 210 result1 = ssle1.wrap(emptyBuffer, oneToTwo); 211 checkResult(result1, null, null, 0, -1, done1); 212 result2 = ssle2.wrap(emptyBuffer, twoToOne); 213 checkResult(result2, null, null, 0, -1, done2); 214 215 if (result1.getHandshakeStatus() == HandshakeStatus.FINISHED) { 216 done1 = true; 217 } 218 219 if (result2.getHandshakeStatus() == HandshakeStatus.FINISHED) { 220 done2 = true; 221 } 222 223 System.out.println("wrap1 = " + result1); 224 System.out.println("wrap2 = " + result2); 225 226 if (result1.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 227 Runnable runnable; 228 while ((runnable = ssle1.getDelegatedTask()) != null) { 229 runnable.run(); 230 } 231 } 232 233 if (result2.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 234 Runnable runnable; 235 while ((runnable = ssle2.getDelegatedTask()) != null) { 236 runnable.run(); 237 } 238 } 239 240 oneToTwo.flip(); 241 twoToOne.flip(); 242 243 oneToTwo.position(10); 244 twoToOne.position(10); 245 246 System.out.println("----"); 247 248 result1 = ssle1.unwrap(twoToOne, appIn1); 249 checkResult(result1, null, null, -1, 0, done1); 250 result2 = ssle2.unwrap(oneToTwo, appIn2); 251 checkResult(result2, null, null, -1, 0, done2); 252 253 if (result1.getHandshakeStatus() == HandshakeStatus.FINISHED) { 254 done1 = true; 255 } 256 257 if (result2.getHandshakeStatus() == HandshakeStatus.FINISHED) { 258 done2 = true; 259 } 260 261 if (result1.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 262 Runnable runnable; 263 while ((runnable = ssle1.getDelegatedTask()) != null) { 264 runnable.run(); 265 } 266 } 267 268 if (result2.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 269 Runnable runnable; 270 while ((runnable = ssle2.getDelegatedTask()) != null) { 271 runnable.run(); 272 } 273 } 274 275 System.out.println("unwrap1 = " + result1); 276 System.out.println("unwrap2 = " + result2); 277 278 oneToTwoShifter.position(oneToTwo.position() - 10); 279 oneToTwoShifter.limit(oneToTwo.limit() - 10); 280 twoToOneShifter.position(twoToOne.position() - 10); 281 twoToOneShifter.limit(twoToOne.limit() - 10); 282 oneToTwoShifter.compact(); 283 twoToOneShifter.compact(); 284 oneToTwo.position(oneToTwoShifter.position() + 10); 285 oneToTwo.limit(oneToTwoShifter.limit() + 10); 286 twoToOne.position(twoToOneShifter.position() + 10); 287 twoToOne.limit(twoToOneShifter.limit() + 10); 288 } 289 290 System.out.println("\nDONE HANDSHAKING"); 291 System.out.println("================"); 292 293 if (!done1 || !done2) { 294 throw new Exception("Both should be true:\n" + 295 " done1 = " + done1 + " done2 = " + done2); 296 } 297 298 String host = ssle1.getPeerHost(); 299 int port = ssle1.getPeerPort(); 300 if (!host.equals(hostname) || (port != portNumber)) { 301 throw new Exception("unexpected host/port " + host + ":" + port); 302 } 303 304 host = ssle2.getPeerHost(); 305 port = ssle2.getPeerPort(); 306 if ((host != null) || (port != -1)) { 307 throw new Exception("unexpected host/port " + host + ":" + port); 308 } 309 310 SSLSession ssls1 = ssle1.getSession(); 311 312 host = ssls1.getPeerHost(); 313 port = ssls1.getPeerPort(); 314 if (!host.equals(hostname) || (port != portNumber)) { 315 throw new Exception("unexpected host/port " + host + ":" + port); 316 } 317 318 SSLSession ssls2 = ssle2.getSession(); 319 320 host = ssls2.getPeerHost(); 321 port = ssls2.getPeerPort(); 322 if ((host != null) || (port != -1)) { 323 throw new Exception("unexpected host/port " + host + ":" + port); 324 } 325 326 /* 327 * Should be able to write/read a small buffer like this. 328 */ 329 int appOut1Len = appOut1.remaining(); 330 int appOut2Len = appOut2.remaining(); 331 int net1Len; 332 int net2Len; 333 334 result1 = ssle1.wrap(appOut1, oneToTwo); 335 checkResult(result1, Status.OK, HandshakeStatus.NOT_HANDSHAKING, 336 appOut1Len, -1, false); 337 result2 = ssle2.wrap(appOut2, twoToOne); 338 checkResult(result2, Status.OK, HandshakeStatus.NOT_HANDSHAKING, 339 appOut2Len, -1, false); 340 net1Len = result1.bytesProduced(); 341 net2Len = result2.bytesProduced(); 342 343 System.out.println("wrap1 = " + result1); 344 System.out.println("wrap2 = " + result2); 345 346 oneToTwo.flip(); 347 twoToOne.flip(); 348 349 oneToTwo.position(10); 350 twoToOne.position(10); 351 352 System.out.println("----"); 353 354 result1 = ssle1.unwrap(twoToOne, appIn1); 355 checkResult(result1, Status.OK, HandshakeStatus.NOT_HANDSHAKING, 356 net2Len, appOut2Len, false); 357 result2 = ssle2.unwrap(oneToTwo, appIn2); 358 checkResult(result2, Status.OK, HandshakeStatus.NOT_HANDSHAKING, 359 net1Len, appOut1Len, false); 360 361 System.out.println("unwrap1 = " + result1); 362 System.out.println("unwrap2 = " + result2); 363 364 oneToTwoShifter.position(oneToTwo.position() - 10); 365 oneToTwoShifter.limit(oneToTwo.limit() - 10); 366 twoToOneShifter.position(twoToOne.position() - 10); 367 twoToOneShifter.limit(twoToOne.limit() - 10); 368 oneToTwoShifter.compact(); 369 twoToOneShifter.compact(); 370 oneToTwo.position(oneToTwoShifter.position() + 10); 371 oneToTwo.limit(oneToTwoShifter.limit() + 10); 372 twoToOne.position(twoToOneShifter.position() + 10); 373 twoToOne.limit(twoToOneShifter.limit() + 10); 374 375 ssls2.invalidate(); 376 ssle2.beginHandshake(); 377 378 System.out.println("\nRENEGOTIATING"); 379 System.out.println("============="); 380 381 done1 = false; 382 done2 = false; 383 384 appIn1.clear(); 385 appIn2.clear(); 386 387 /* 388 * Do a quick test to see if this can do a switch 389 * into client mode, at this point, you shouldn't be able 390 * to switch back. 391 */ 392 try { 393 System.out.println("Try to change client mode"); 394 ssle2.setUseClientMode(true); 395 throw new Exception("Should have thrown IllegalArgumentException"); 396 } catch (IllegalArgumentException e) { 397 System.out.println("Caught correct IllegalArgumentException"); 398 } 399 400 while (isHandshaking(ssle1) || 401 isHandshaking(ssle2)) { 402 403 System.out.println("================"); 404 405 result1 = ssle1.wrap(emptyBuffer, oneToTwo); 406 checkResult(result1, null, null, 0, -1, done1); 407 result2 = ssle2.wrap(emptyBuffer, twoToOne); 408 checkResult(result2, null, null, 0, -1, done2); 409 410 if (result1.getHandshakeStatus() == HandshakeStatus.FINISHED) { 411 done1 = true; 412 } 413 414 if (result2.getHandshakeStatus() == HandshakeStatus.FINISHED) { 415 done2 = true; 416 } 417 418 System.out.println("wrap1 = " + result1); 419 System.out.println("wrap2 = " + result2); 420 421 if (result1.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 422 Runnable runnable; 423 while ((runnable = ssle1.getDelegatedTask()) != null) { 424 runnable.run(); 425 } 426 } 427 428 if (result2.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 429 Runnable runnable; 430 while ((runnable = ssle2.getDelegatedTask()) != null) { 431 runnable.run(); 432 } 433 } 434 435 oneToTwo.flip(); 436 twoToOne.flip(); 437 438 oneToTwo.position(10); 439 twoToOne.position(10); 440 441 System.out.println("----"); 442 443 result1 = ssle1.unwrap(twoToOne, appIn1); 444 checkResult(result1, null, null, -1, 0, done1); 445 result2 = ssle2.unwrap(oneToTwo, appIn2); 446 checkResult(result2, null, null, -1, 0, done2); 447 448 if (result1.getHandshakeStatus() == HandshakeStatus.FINISHED) { 449 done1 = true; 450 } 451 452 if (result2.getHandshakeStatus() == HandshakeStatus.FINISHED) { 453 done2 = true; 454 } 455 456 System.out.println("unwrap1 = " + result1); 457 System.out.println("unwrap2 = " + result2); 458 459 if (result1.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 460 Runnable runnable; 461 while ((runnable = ssle1.getDelegatedTask()) != null) { 462 runnable.run(); 463 } 464 } 465 466 if (result2.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { 467 Runnable runnable; 468 while ((runnable = ssle2.getDelegatedTask()) != null) { 469 runnable.run(); 470 } 471 } 472 473 oneToTwoShifter.position(oneToTwo.position() - 10); 474 oneToTwoShifter.limit(oneToTwo.limit() - 10); 475 twoToOneShifter.position(twoToOne.position() - 10); 476 twoToOneShifter.limit(twoToOne.limit() - 10); 477 oneToTwoShifter.compact(); 478 twoToOneShifter.compact(); 479 oneToTwo.position(oneToTwoShifter.position() + 10); 480 oneToTwo.limit(oneToTwoShifter.limit() + 10); 481 twoToOne.position(twoToOneShifter.position() + 10); 482 twoToOne.limit(twoToOneShifter.limit() + 10); 483 } 484 485 host = ssle1.getPeerHost(); 486 port = ssle1.getPeerPort(); 487 if (!host.equals(hostname) || (port != portNumber)) { 488 throw new Exception("unexpected host/port " + host + ":" + port); 489 } 490 491 host = ssle2.getPeerHost(); 492 port = ssle2.getPeerPort(); 493 if ((host != null) || (port != -1)) { 494 throw new Exception("unexpected host/port " + host + ":" + port); 495 } 496 497 SSLSession ssls3 = ssle2.getSession(); 498 499 host = ssls1.getPeerHost(); 500 port = ssls1.getPeerPort(); 501 if (!host.equals(hostname) || (port != portNumber)) { 502 throw new Exception("unexpected host/port " + host + ":" + port); 503 } 504 505 SSLSession ssls4 = ssle2.getSession(); 506 507 host = ssls2.getPeerHost(); 508 port = ssls2.getPeerPort(); 509 if ((host != null) || (port != -1)) { 510 throw new Exception("unexpected host/port " + host + ":" + port); 511 } 512 513 System.out.println("\nDoing close"); 514 System.out.println("==========="); 515 516 ssle1.closeOutbound(); 517 ssle2.closeOutbound(); 518 519 oneToTwo.flip(); 520 twoToOne.flip(); 521 oneToTwo.position(10); 522 twoToOne.position(10); 523 524 appIn1.clear(); 525 appIn2.clear(); 526 527 System.out.println("LAST UNWRAP"); 528 result1 = ssle1.unwrap(twoToOne, appIn1); 529 checkResult(result1, Status.BUFFER_UNDERFLOW, 530 HandshakeStatus.NEED_WRAP, 0, 0, false); 531 result2 = ssle2.unwrap(oneToTwo, appIn2); 532 checkResult(result2, Status.BUFFER_UNDERFLOW, 533 HandshakeStatus.NEED_WRAP, 0, 0, false); 534 535 System.out.println("unwrap1 = " + result1); 536 System.out.println("unwrap2 = " + result2); 537 538 oneToTwoShifter.position(oneToTwo.position() - 10); 539 oneToTwoShifter.limit(oneToTwo.limit() - 10); 540 twoToOneShifter.position(twoToOne.position() - 10); 541 twoToOneShifter.limit(twoToOne.limit() - 10); 542 oneToTwoShifter.compact(); 543 twoToOneShifter.compact(); 544 oneToTwo.position(oneToTwoShifter.position() + 10); 545 oneToTwo.limit(oneToTwoShifter.limit() + 10); 546 twoToOne.position(twoToOneShifter.position() + 10); 547 twoToOne.limit(twoToOneShifter.limit() + 10); 548 549 System.out.println("LAST WRAP"); 550 result1 = ssle1.wrap(appOut1, oneToTwo); 551 checkResult(result1, Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 552 0, -1, false); 553 result2 = ssle2.wrap(appOut2, twoToOne); 554 checkResult(result2, Status.CLOSED, HandshakeStatus.NEED_UNWRAP, 555 0, -1, false); 556 557 System.out.println("wrap1 = " + result1); 558 System.out.println("wrap2 = " + result2); 559 560 net1Len = result1.bytesProduced(); 561 net2Len = result2.bytesProduced(); 562 563 oneToTwo.flip(); 564 twoToOne.flip(); 565 566 oneToTwo.position(10); 567 twoToOne.position(10); 568 569 result1 = ssle1.unwrap(twoToOne, appIn1); 570 checkResult(result1, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 571 net1Len, 0, false); 572 result2 = ssle2.unwrap(oneToTwo, appIn2); 573 checkResult(result2, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 574 net2Len, 0, false); 575 576 System.out.println("unwrap1 = " + result1); 577 System.out.println("unwrap2 = " + result2); 578 579 oneToTwoShifter.position(oneToTwo.position() - 10); 580 oneToTwoShifter.limit(oneToTwo.limit() - 10); 581 twoToOneShifter.position(twoToOne.position() - 10); 582 twoToOneShifter.limit(twoToOne.limit() - 10); 583 oneToTwoShifter.compact(); 584 twoToOneShifter.compact(); 585 oneToTwo.position(oneToTwoShifter.position() + 10); 586 oneToTwo.limit(oneToTwoShifter.limit() + 10); 587 twoToOne.position(twoToOneShifter.position() + 10); 588 twoToOne.limit(twoToOneShifter.limit() + 10); 589 590 System.out.println("EXTRA WRAP"); 591 result1 = ssle1.wrap(appOut1, oneToTwo); 592 checkResult(result1, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 593 0, 0, false); 594 result2 = ssle2.wrap(appOut2, twoToOne); 595 checkResult(result2, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 596 0, 0, false); 597 598 System.out.println("wrap1 = " + result1); 599 System.out.println("wrap2 = " + result2); 600 601 oneToTwo.flip(); 602 twoToOne.flip(); 603 oneToTwo.position(10); 604 twoToOne.position(10); 605 606 System.out.println("EXTRA UNWRAP"); 607 result1 = ssle1.unwrap(twoToOne, appIn1); 608 checkResult(result1, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 609 0, 0, false); 610 result2 = ssle2.unwrap(oneToTwo, appIn2); 611 checkResult(result2, Status.CLOSED, HandshakeStatus.NOT_HANDSHAKING, 612 0, 0, false); 613 614 System.out.println("unwrap1 = " + result1); 615 System.out.println("unwrap2 = " + result2); 616 617 checkSession(ssls1, ssls2, ssls3, ssls4); 618 System.out.println(ssle1); 619 System.out.println(ssle2); 620 } 621 622 private static void checkSession(SSLSession ssls1, SSLSession ssls2, 623 SSLSession ssls3, SSLSession ssls4) throws Exception { 624 System.out.println("\nSession Info for SSLEngine1"); 625 System.out.println(ssls1); 626 System.out.println(ssls1.getCreationTime()); 627 String peer1 = ssls1.getPeerHost(); 628 System.out.println(peer1); 629 String protocol1 = ssls1.getProtocol(); 630 System.out.println(protocol1); 631 java.security.cert.Certificate cert1 = ssls1.getPeerCertificates()[0]; 632 System.out.println(cert1); 633 String ciphersuite1 = ssls1.getCipherSuite(); 634 System.out.println(ciphersuite1); 635 System.out.println(); 636 637 System.out.println("\nSession Info for SSLEngine2"); 638 System.out.println(ssls2); 639 System.out.println(ssls2.getCreationTime()); 640 String peer2 = ssls2.getPeerHost(); 641 System.out.println(peer2); 642 String protocol2 = ssls2.getProtocol(); 643 System.out.println(protocol2); 644 java.security.cert.Certificate cert2 = ssls2.getPeerCertificates()[0]; 645 System.out.println(cert2); 646 String ciphersuite2 = ssls2.getCipherSuite(); 647 System.out.println(ciphersuite2); 648 System.out.println(); 649 650 if (peer1.equals(peer2)) { 651 throw new Exception("peer hostnames not equal"); 652 } 653 654 if (!protocol1.equals(protocol2)) { 655 throw new Exception("protocols not equal"); 656 } 657 658 if (!cert1.equals(cert2)) { 659 throw new Exception("certs not equal"); 660 } 661 662 if (!ciphersuite1.equals(ciphersuite2)) { 663 throw new Exception("ciphersuites not equal"); 664 } 665 666 System.out.println("\nSession Info for SSLEngine3"); 667 System.out.println(ssls3); 668 System.out.println("\nSession Info for SSLEngine4"); 669 System.out.println(ssls4); 670 671 if (ssls3.equals(ssls1) || ssls4.equals(ssls2)) { 672 throw new Exception("sessions should not be equals"); 673 } 674 } 675 676 public static void main(String args[]) throws Exception { 677 // reset the security property to make sure that the algorithms 678 // and keys used in this test are not disabled. 679 Security.setProperty("jdk.tls.disabledAlgorithms", ""); 680 681 ConnectionTest ct = new ConnectionTest(); 682 ct.test(); 683 } 684 }