Path: blob/master/test/jdk/javax/net/ssl/TLSCommon/RehandshakeWithDataExTest.java
41152 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);59if (TESTED_SECURITY_PROTOCOL.contains("DTLS")) {60initialEpoch = r.sequenceNumber() >> 48;61}62doHandshake(clientEngine, serverEngine, maxPacketSize,63HandshakeMode.REHANDSHAKE_BEGIN_CLIENT);64sendApplicationData(clientEngine, serverEngine);65r = sendApplicationData(serverEngine, clientEngine);66AssertionError epochError = new AssertionError("Epoch number"67+ " did not grow after re-handshake! "68+ " Was " + initialEpoch + ", now " + secondEpoch + ".");69if (TESTED_SECURITY_PROTOCOL.contains("DTLS")) {70secondEpoch = r.sequenceNumber() >> 48;71if (Long.compareUnsigned(secondEpoch, initialEpoch) <= 0) {72throw epochError;73}74}75doHandshake(clientEngine, serverEngine, maxPacketSize,76HandshakeMode.REHANDSHAKE_BEGIN_SERVER);77sendApplicationData(clientEngine, serverEngine);78r = sendApplicationData(serverEngine, clientEngine);79if (TESTED_SECURITY_PROTOCOL.contains("DTLS")) {80thirdEpoch = r.sequenceNumber() >> 48;81if (Long.compareUnsigned(thirdEpoch, secondEpoch) <= 0) {82throw epochError;83}84}85closeEngines(clientEngine, serverEngine);86}8788}899091