test/sun/security/ssl/javax/net/ssl/NewAPIs/SSLEngine/ConnectionTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, 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 
  38 import javax.net.ssl.*;
  39 import javax.net.ssl.SSLEngineResult.*;
  40 import java.io.*;
  41 import java.security.*;
  42 import java.nio.*;
  43 
  44 public class ConnectionTest {
  45 
  46     private SSLContext sslc;
  47     private SSLEngine ssle1;
  48     private SSLEngine ssle2;
  49 
  50     private static String pathToStores = "../../../../../etc";
  51     private static String keyStoreFile = "keystore";
  52     private static String trustStoreFile = "truststore";
  53     private static String passwd = "passphrase";
  54 
  55     private static String keyFilename =


 652 
 653         if (!cert1.equals(cert2)) {
 654             throw new Exception("certs not equal");
 655         }
 656 
 657         if (!ciphersuite1.equals(ciphersuite2)) {
 658             throw new Exception("ciphersuites not equal");
 659         }
 660 
 661         System.out.println("\nSession Info for SSLEngine3");
 662         System.out.println(ssls3);
 663         System.out.println("\nSession Info for SSLEngine4");
 664         System.out.println(ssls4);
 665 
 666         if (ssls3.equals(ssls1) || ssls4.equals(ssls2)) {
 667             throw new Exception("sessions should not be equals");
 668         }
 669     }
 670 
 671     public static void main(String args[]) throws Exception {




 672         ConnectionTest ct = new ConnectionTest();
 673         ct.test();
 674     }
 675 }
   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 =


 654 
 655         if (!cert1.equals(cert2)) {
 656             throw new Exception("certs not equal");
 657         }
 658 
 659         if (!ciphersuite1.equals(ciphersuite2)) {
 660             throw new Exception("ciphersuites not equal");
 661         }
 662 
 663         System.out.println("\nSession Info for SSLEngine3");
 664         System.out.println(ssls3);
 665         System.out.println("\nSession Info for SSLEngine4");
 666         System.out.println(ssls4);
 667 
 668         if (ssls3.equals(ssls1) || ssls4.equals(ssls2)) {
 669             throw new Exception("sessions should not be equals");
 670         }
 671     }
 672 
 673     public static void main(String args[]) throws Exception {
 674         // reset the security property to make sure that the algorithms
 675         // and keys used in this test are not disabled.
 676         Security.setProperty("jdk.tls.disabledAlgorithms", "");
 677 
 678         ConnectionTest ct = new ConnectionTest();
 679         ct.test();
 680     }
 681 }