test/jdk/sun/security/ssl/SSLEngineImpl/EngineEnforceUseClientMode.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 51141 2dd2d73c52f6
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
   105             ssle3.wrap(appOut1, oneToTwo);
   105             ssle3.wrap(appOut1, oneToTwo);
   106             throw new RuntimeException(
   106             throw new RuntimeException(
   107                 "wrap():  Didn't catch the exception properly");
   107                 "wrap():  Didn't catch the exception properly");
   108         } catch (IllegalStateException e) {
   108         } catch (IllegalStateException e) {
   109             System.out.println("Caught the correct exception.");
   109             System.out.println("Caught the correct exception.");
   110             ssle3.wrap(appOut1, oneToTwo);
       
   111             oneToTwo.flip();
   110             oneToTwo.flip();
   112             if (oneToTwo.hasRemaining()) {
   111             if (oneToTwo.hasRemaining()) {
   113                 throw new Exception("wrap1 generated data");
   112                 throw new Exception("wrap generated data");
   114             }
   113             }
   115             oneToTwo.clear();
   114             oneToTwo.clear();
   116         }
   115         }
   117 
   116 
   118         try {
   117         try {
   120             ssle4.unwrap(oneToTwo, appIn1);
   119             ssle4.unwrap(oneToTwo, appIn1);
   121             throw new RuntimeException(
   120             throw new RuntimeException(
   122                 "unwrap():  Didn't catch the exception properly");
   121                 "unwrap():  Didn't catch the exception properly");
   123         } catch (IllegalStateException e) {
   122         } catch (IllegalStateException e) {
   124             System.out.println("Caught the correct exception.");
   123             System.out.println("Caught the correct exception.");
   125             ssle4.wrap(appOut1, oneToTwo);
   124             appIn1.flip();
   126             oneToTwo.flip();
   125             if (appIn1.hasRemaining()) {
   127             if (oneToTwo.hasRemaining()) {
   126                 throw new Exception("unwrap generated data");
   128                 throw new Exception("wrap2 generated data");
       
   129             }
   127             }
   130             oneToTwo.clear();
   128             appIn1.clear();
   131         }
   129         }
   132 
   130 
   133         try {
   131         try {
   134             System.out.println("Testing beginHandshake()");
   132             System.out.println("Testing beginHandshake()");
   135             ssle5.beginHandshake();
   133             ssle5.beginHandshake();
   136             throw new RuntimeException(
   134             throw new RuntimeException(
   137                 "unwrap():  Didn't catch the exception properly");
   135                 "unwrap():  Didn't catch the exception properly");
   138         } catch (IllegalStateException e) {
   136         } catch (IllegalStateException e) {
   139             System.out.println("Caught the correct exception.");
   137             System.out.println("Caught the correct exception.");
   140             ssle5.wrap(appOut1, oneToTwo);
       
   141             oneToTwo.flip();
       
   142             if (oneToTwo.hasRemaining()) {
       
   143                 throw new Exception("wrap3 generated data");
       
   144             }
       
   145             oneToTwo.clear();
       
   146         }
   138         }
   147 
   139 
   148         boolean dataDone = false;
   140         boolean dataDone = false;
   149 
   141 
   150         SSLEngineResult result1;        // ssle1's results from last operation
   142         SSLEngineResult result1;        // ssle1's results from last operation
   198                 checkTransfer(appOut1, appIn2);
   190                 checkTransfer(appOut1, appIn2);
   199                 checkTransfer(appOut2, appIn1);
   191                 checkTransfer(appOut2, appIn1);
   200 
   192 
   201                 System.out.println("Try changing modes...");
   193                 System.out.println("Try changing modes...");
   202                 try {
   194                 try {
   203                     ssle2.setUseClientMode(false);
   195                     ssle2.setUseClientMode(true);
   204                     throw new RuntimeException(
   196                     throw new RuntimeException(
   205                         "setUseClientMode():  " +
   197                         "setUseClientMode():  " +
   206                         "Didn't catch the exception properly");
   198                         "Didn't catch the exception properly");
   207                 } catch (IllegalArgumentException e) {
   199                 } catch (IllegalArgumentException e) {
   208                     System.out.println("Caught the correct exception.");
   200                     System.out.println("Caught the correct exception.");
   309             throw new Exception("Data didn't transfer cleanly");
   301             throw new Exception("Data didn't transfer cleanly");
   310         } else {
   302         } else {
   311             log("Data transferred cleanly");
   303             log("Data transferred cleanly");
   312         }
   304         }
   313 
   305 
   314         a.clear();
   306         a.position(a.limit());
   315         b.clear();
   307         b.position(b.limit());
       
   308         a.limit(a.capacity());
       
   309         b.limit(b.capacity());
   316     }
   310     }
   317 
   311 
   318     private static void log(String str) {
   312     private static void log(String str) {
   319         if (debug) {
   313         if (debug) {
   320             System.out.println(str);
   314             System.out.println(str);