< prev index next >

test/sun/security/ssl/ClientHandshaker/LengthCheckTest.java

Print this page
rev 14346 : 8202343: Disable TLS 1.0 and 1.1
Reviewed-by: xuelei, dfuchs, coffeys, sgehwolf
   1 /*
   2  * Copyright (c) 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 8044860
  27  * @summary Vectors and fixed length fields should be verified
  28  *          for allowed sizes.

  29  * @run main/othervm LengthCheckTest
  30  * @key randomness
  31  */
  32 
  33 /**
  34  * A SSLEngine usage example which simplifies the presentation
  35  * by removing the I/O and multi-threading concerns.
  36  *
  37  * The test creates two SSLEngines, simulating a client and server.
  38  * The "transport" layer consists two byte buffers:  think of them
  39  * as directly connected pipes.
  40  *
  41  * Note, this is a *very* simple example: real code will be much more
  42  * involved.  For example, different threading and I/O models could be
  43  * used, transport mechanisms could close unexpectedly, and so on.
  44  *
  45  * When this application runs, notice that several messages
  46  * (wrap/unwrap) pass before any application data is consumed or
  47  * produced.  (For more information, please see the SSL/TLS
  48  * specifications.)  There may several steps for a successful handshake,


 282             sTOc.flip();
 283             dumpByteBuffer("SERVER-TO-CLIENT", sTOc);
 284 
 285             // At this point we can verify that both an exception
 286             // was thrown and the proper action (a TLS alert) was
 287             // sent back to the client.
 288             if (gotException == false ||
 289                     !isTlsMessage(sTOc, TLS_RECTYPE_ALERT, TLS_ALERT_LVL_FATAL,
 290                         TLS_ALERT_ILLEGAL_PARAMETER)) {
 291                 throw new SSLException(
 292                     "Server failed to throw Alert:fatal:internal_error");
 293             }
 294         }
 295     };
 296 
 297 
 298     /*
 299      * Main entry point for this test.
 300      */
 301     public static void main(String args[]) throws Exception {



 302         List<LengthCheckTest> ccsTests = new ArrayList<>();
 303 
 304         if (debug) {
 305             System.setProperty("javax.net.debug", "ssl");
 306         }
 307 
 308         ccsTests.add(new LengthCheckTest("ServSendLongID"));
 309         ccsTests.add(new LengthCheckTest("ClientSendLongID"));
 310 
 311         for (LengthCheckTest test : ccsTests) {
 312             test.runTest();
 313         }
 314 
 315         System.out.println("Test Passed.");
 316     }
 317 
 318     /*
 319      * Create an initialized SSLContext to use for these tests.
 320      */
 321     public LengthCheckTest(String testName) throws Exception {


   1 /*
   2  * Copyright (c) 2015, 2020, 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 8044860
  27  * @summary Vectors and fixed length fields should be verified
  28  *          for allowed sizes.
  29  * @library /lib/security
  30  * @run main/othervm LengthCheckTest
  31  * @key randomness
  32  */
  33 
  34 /**
  35  * A SSLEngine usage example which simplifies the presentation
  36  * by removing the I/O and multi-threading concerns.
  37  *
  38  * The test creates two SSLEngines, simulating a client and server.
  39  * The "transport" layer consists two byte buffers:  think of them
  40  * as directly connected pipes.
  41  *
  42  * Note, this is a *very* simple example: real code will be much more
  43  * involved.  For example, different threading and I/O models could be
  44  * used, transport mechanisms could close unexpectedly, and so on.
  45  *
  46  * When this application runs, notice that several messages
  47  * (wrap/unwrap) pass before any application data is consumed or
  48  * produced.  (For more information, please see the SSL/TLS
  49  * specifications.)  There may several steps for a successful handshake,


 283             sTOc.flip();
 284             dumpByteBuffer("SERVER-TO-CLIENT", sTOc);
 285 
 286             // At this point we can verify that both an exception
 287             // was thrown and the proper action (a TLS alert) was
 288             // sent back to the client.
 289             if (gotException == false ||
 290                     !isTlsMessage(sTOc, TLS_RECTYPE_ALERT, TLS_ALERT_LVL_FATAL,
 291                         TLS_ALERT_ILLEGAL_PARAMETER)) {
 292                 throw new SSLException(
 293                     "Server failed to throw Alert:fatal:internal_error");
 294             }
 295         }
 296     };
 297 
 298 
 299     /*
 300      * Main entry point for this test.
 301      */
 302     public static void main(String args[]) throws Exception {
 303         // Re-enable TLSv1 since test depends on it.
 304         SecurityUtils.removeFromDisabledTlsAlgs("TLSv1");
 305 
 306         List<LengthCheckTest> ccsTests = new ArrayList<>();
 307 
 308         if (debug) {
 309             System.setProperty("javax.net.debug", "ssl");
 310         }
 311 
 312         ccsTests.add(new LengthCheckTest("ServSendLongID"));
 313         ccsTests.add(new LengthCheckTest("ClientSendLongID"));
 314 
 315         for (LengthCheckTest test : ccsTests) {
 316             test.runTest();
 317         }
 318 
 319         System.out.println("Test Passed.");
 320     }
 321 
 322     /*
 323      * Create an initialized SSLContext to use for these tests.
 324      */
 325     public LengthCheckTest(String testName) throws Exception {


< prev index next >