test/jdk/javax/net/ssl/SSLEngine/Arrays.java
changeset 51407 910f7b56592f
parent 47216 71c04702a3d5
equal deleted inserted replaced
51406:f4b4dfac45b1 51407:910f7b56592f
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 5019096
    26  * @bug 5019096
    27  * @summary Add scatter/gather APIs for SSLEngine
    27  * @summary Add scatter/gather APIs for SSLEngine
    28  *
    28  * @run main/othervm Arrays SSL
       
    29  * @run main/othervm Arrays TLS
       
    30  * @run main/othervm Arrays SSLv3
       
    31  * @run main/othervm Arrays TLSv1
       
    32  * @run main/othervm Arrays TLSv1.1
       
    33  * @run main/othervm Arrays TLSv1.2
       
    34  * @run main/othervm Arrays TLSv1.3
       
    35  * @run main/othervm -Djdk.tls.acknowledgeCloseNotify=true Arrays TLSv1.3
    29  */
    36  */
    30 
    37 
    31 import javax.net.ssl.*;
    38 import javax.net.ssl.*;
    32 import javax.net.ssl.SSLEngineResult.*;
    39 import javax.net.ssl.SSLEngineResult.*;
    33 import java.io.*;
    40 import java.io.*;
    35 import java.nio.*;
    42 import java.nio.*;
    36 
    43 
    37 public class Arrays {
    44 public class Arrays {
    38 
    45 
    39     private static boolean debug = false;
    46     private static boolean debug = false;
       
    47     private static boolean acknowledgeCloseNotify =
       
    48         "true".equals(System.getProperty("jdk.tls.acknowledgeCloseNotify"));
    40 
    49 
    41     private SSLContext sslc;
    50     private SSLContext sslc;
    42     private SSLEngine ssle1;    // client
    51     private SSLEngine ssle1;    // client
    43     private SSLEngine ssle2;    // server
    52     private SSLEngine ssle2;    // server
    44 
    53 
   129             if (!dataDone) {
   138             if (!dataDone) {
   130                 boolean done = true;
   139                 boolean done = true;
   131 
   140 
   132                 for (int i = 0; i < appOutArray1.length; i++) {
   141                 for (int i = 0; i < appOutArray1.length; i++) {
   133                     if (appOutArray1[i].remaining() != 0) {
   142                     if (appOutArray1[i].remaining() != 0) {
       
   143                         log("1st out not done");
   134                         done = false;
   144                         done = false;
   135                     }
   145                     }
   136                 }
   146                 }
   137 
   147 
   138                 if (appOut2.remaining() != 0) {
   148                 if (appOut2.remaining() != 0) {
       
   149                     log("2nd out not done");
   139                     done = false;
   150                     done = false;
   140                 }
   151                 }
   141 
   152 
   142                 if (done) {
   153                 if (done) {
   143                     log("Closing ssle1's *OUTBOUND*...");
   154                     log("Closing ssle1's *OUTBOUND*...");
   144                     for (int i = 0; i < appOutArray1.length; i++) {
   155                     for (int i = 0; i < appOutArray1.length; i++) {
   145                         appOutArray1[i].rewind();
   156                         appOutArray1[i].rewind();
   146                     }
   157                     }
   147                     ssle1.closeOutbound();
   158                     ssle1.closeOutbound();
       
   159                     String protocol = ssle2.getSession().getProtocol();
       
   160                     if (!acknowledgeCloseNotify) {
       
   161                         switch (ssle2.getSession().getProtocol()) {
       
   162                             case "SSLv3":
       
   163                             case "TLSv1":
       
   164                             case "TLSv1.1":
       
   165                             case "TLSv1.2":
       
   166                                 break;
       
   167                             default:    // TLSv1.3
       
   168                                 // TLS 1.3, half-close only.
       
   169                                 ssle2.closeOutbound();
       
   170                         }
       
   171                     }
   148                     dataDone = true;
   172                     dataDone = true;
   149                 }
   173                 }
   150             }
   174             }
   151         }
   175         }
   152         checkTransfer(appOutArray1,  appIn2);
   176         checkTransfer(appOutArray1,  appIn2);
   153         appInArray1[appInArray1.length - 1].limit(
   177         appInArray1[appInArray1.length - 1].limit(
   154             appInArray1[appInArray1.length - 1].position());
   178             appInArray1[appInArray1.length - 1].position());
   155         checkTransfer(appInArray1, appOut2);
   179         checkTransfer(appInArray1, appOut2);
   156     }
   180     }
   157 
   181 
       
   182     private static String contextVersion;
   158     public static void main(String args[]) throws Exception {
   183     public static void main(String args[]) throws Exception {
       
   184         contextVersion = args[0];
   159 
   185 
   160         Arrays test;
   186         Arrays test;
   161 
   187 
   162         test = new Arrays();
   188         test = new Arrays();
   163 
   189 
   164         test.createSSLEngines();
   190         test.createSSLEngines();
   165 
   191 
   166         test.runTest();
   192         test.runTest();
   167 
   193 
   168         System.out.println("Test Passed.");
   194         System.err.println("Test Passed.");
   169     }
   195     }
   170 
   196 
   171     /*
   197     /*
   172      * **********************************************************
   198      * **********************************************************
   173      * Majority of the test case is above, below is just setup stuff
   199      * Majority of the test case is above, below is just setup stuff
   196         kmf.init(ks, passphrase);
   222         kmf.init(ks, passphrase);
   197 
   223 
   198         TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
   224         TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
   199         tmf.init(ts);
   225         tmf.init(ts);
   200 
   226 
   201         SSLContext sslCtx = SSLContext.getInstance("TLS");
   227         SSLContext sslCtx = SSLContext.getInstance(contextVersion);
   202 
   228 
   203         sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
   229         sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
   204 
   230 
   205         return sslCtx;
   231         return sslCtx;
   206     }
   232     }
   286         log("Data transferred cleanly");
   312         log("Data transferred cleanly");
   287     }
   313     }
   288 
   314 
   289     private static void log(String str) {
   315     private static void log(String str) {
   290         if (debug) {
   316         if (debug) {
   291             System.out.println(str);
   317             System.err.println(str);
   292         }
   318         }
   293     }
   319     }
   294 }
   320 }