< prev index next >

test/jdk/sun/security/ssl/SSLSocketImpl/InvalidateServerSessionRenegotiate.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2011, 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 // SunJSSE does not support dynamic system properties, no way to re-use
  26 // system properties in samevm/agentvm mode.
  27 //
  28 
  29 /*
  30  * @test
  31  * @bug 4403428
  32  * @summary Invalidating JSSE session on server causes SSLProtocolException
  33  * @run main/othervm InvalidateServerSessionRenegotiate SSLv3
  34  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1
  35  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1.1
  36  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1.2
  37  * @author Brad Wetmore
  38  */
  39 
  40 import java.io.*;
  41 import java.net.*;
  42 import java.security.Security;
  43 import javax.net.ssl.*;
  44 
  45 public class InvalidateServerSessionRenegotiate implements
  46         HandshakeCompletedListener {
  47 
  48     static byte handshakesCompleted = 0;
  49 
  50     /*
  51      * Define what happens when handshaking is completed


 103      * Define the server side of the test.
 104      *
 105      * If the server prematurely exits, serverReady will be set to true
 106      * to avoid infinite hangs.
 107      */
 108     void doServerSide() throws Exception {
 109         SSLServerSocketFactory sslssf =
 110             (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
 111         SSLServerSocket sslServerSocket =
 112             (SSLServerSocket) sslssf.createServerSocket(serverPort);
 113 
 114         serverPort = sslServerSocket.getLocalPort();
 115 
 116         /*
 117          * Signal Client, we're ready for his connect.
 118          */
 119         serverReady = true;
 120 
 121         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
 122         sslSocket.addHandshakeCompletedListener(this);






 123         InputStream sslIS = sslSocket.getInputStream();
 124         OutputStream sslOS = sslSocket.getOutputStream();
 125 
 126         for (int i = 0; i < 10; i++) {
 127             sslIS.read();
 128             sslOS.write(85);
 129             sslOS.flush();
 130         }
 131 
 132         System.out.println("invalidating");
 133         sslSocket.getSession().invalidate();
 134         System.out.println("starting new handshake");
 135         sslSocket.startHandshake();
 136 
 137         for (int i = 0; i < 10; i++) {
 138             System.out.println("sending/receiving data, iteration: " + i);
 139             sslIS.read();
 140             sslOS.write(85);
 141             sslOS.flush();
 142         }


   1 /*
   2  * Copyright (c) 2001, 2019, 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 // SunJSSE does not support dynamic system properties, no way to re-use
  26 // system properties in samevm/agentvm mode.
  27 //
  28 
  29 /*
  30  * @test
  31  * @bug 4403428 8190492
  32  * @summary Invalidating JSSE session on server causes SSLProtocolException
  33  * @run main/othervm InvalidateServerSessionRenegotiate SSLv3
  34  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1
  35  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1.1
  36  * @run main/othervm InvalidateServerSessionRenegotiate TLSv1.2
  37  * @author Brad Wetmore
  38  */
  39 
  40 import java.io.*;
  41 import java.net.*;
  42 import java.security.Security;
  43 import javax.net.ssl.*;
  44 
  45 public class InvalidateServerSessionRenegotiate implements
  46         HandshakeCompletedListener {
  47 
  48     static byte handshakesCompleted = 0;
  49 
  50     /*
  51      * Define what happens when handshaking is completed


 103      * Define the server side of the test.
 104      *
 105      * If the server prematurely exits, serverReady will be set to true
 106      * to avoid infinite hangs.
 107      */
 108     void doServerSide() throws Exception {
 109         SSLServerSocketFactory sslssf =
 110             (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
 111         SSLServerSocket sslServerSocket =
 112             (SSLServerSocket) sslssf.createServerSocket(serverPort);
 113 
 114         serverPort = sslServerSocket.getLocalPort();
 115 
 116         /*
 117          * Signal Client, we're ready for his connect.
 118          */
 119         serverReady = true;
 120 
 121         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
 122         sslSocket.addHandshakeCompletedListener(this);
 123 
 124         // Enable all supported protocols on server side to test SSLv3
 125         if ("SSLv3".equals(tlsProtocol)) {
 126             sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
 127         }
 128 
 129         InputStream sslIS = sslSocket.getInputStream();
 130         OutputStream sslOS = sslSocket.getOutputStream();
 131 
 132         for (int i = 0; i < 10; i++) {
 133             sslIS.read();
 134             sslOS.write(85);
 135             sslOS.flush();
 136         }
 137 
 138         System.out.println("invalidating");
 139         sslSocket.getSession().invalidate();
 140         System.out.println("starting new handshake");
 141         sslSocket.startHandshake();
 142 
 143         for (int i = 0; i < 10; i++) {
 144             System.out.println("sending/receiving data, iteration: " + i);
 145             sslIS.read();
 146             sslOS.write(85);
 147             sslOS.flush();
 148         }


< prev index next >