Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/TLSCommon/RehandshakeWithDataExTest.java
38853 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.net.ssl.SSLContext;24import javax.net.ssl.SSLEngine;25import javax.net.ssl.SSLEngineResult;26import javax.net.ssl.SSLException;2728/**29* Testing SSLEngines re-handshaking using each of the supported cipher suites30* with application data exchange before and after re-handshake and closing of31* the engines.32*/33public class RehandshakeWithDataExTest extends SSLEngineTestCase {3435public static void main(String[] args) {36RehandshakeWithDataExTest test = new RehandshakeWithDataExTest();37setUpAndStartKDCIfNeeded();38test.runTests();39}4041@Override42protected void testOneCipher(String cipher) throws SSLException {43SSLContext context = getContext();44int maxPacketSize = getMaxPacketSize();45boolean useSNI = !TEST_MODE.equals("norm");46SSLEngine clientEngine = getClientSSLEngine(context, useSNI);47SSLEngine serverEngine = getServerSSLEngine(context, useSNI);48clientEngine.setEnabledCipherSuites(new String[]{cipher});49serverEngine.setEnabledCipherSuites(new String[]{cipher});50serverEngine.setNeedClientAuth(!cipher.contains("anon"));51long initialEpoch = 0;52long secondEpoch = 0;53long thirdEpoch = 0;54SSLEngineResult r;55doHandshake(clientEngine, serverEngine, maxPacketSize,56HandshakeMode.INITIAL_HANDSHAKE);57sendApplicationData(clientEngine, serverEngine);58r = sendApplicationData(serverEngine, clientEngine);59doHandshake(clientEngine, serverEngine, maxPacketSize,60HandshakeMode.REHANDSHAKE_BEGIN_CLIENT);61sendApplicationData(clientEngine, serverEngine);62r = sendApplicationData(serverEngine, clientEngine);63AssertionError epochError = new AssertionError("Epoch number"64+ " did not grow after re-handshake! "65+ " Was " + initialEpoch + ", now " + secondEpoch + ".");66doHandshake(clientEngine, serverEngine, maxPacketSize,67HandshakeMode.REHANDSHAKE_BEGIN_SERVER);68sendApplicationData(clientEngine, serverEngine);69r = sendApplicationData(serverEngine, clientEngine);70closeEngines(clientEngine, serverEngine);71}7273}747576