< prev index next >

test/jdk/javax/net/ssl/ServerName/SSLSocketExplorer.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2014, 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 7068321
  32  * @summary Support TLS Server Name Indication (SNI) Extension in JSSE Server
  33  * @library ../templates
  34  * @build SSLCapabilities SSLExplorer
  35  * @run main/othervm SSLSocketExplorer SSLv2Hello,SSLv3
  36  * @run main/othervm SSLSocketExplorer SSLv3
  37  * @run main/othervm SSLSocketExplorer TLSv1
  38  * @run main/othervm SSLSocketExplorer TLSv1.1
  39  * @run main/othervm SSLSocketExplorer TLSv1.2
  40  */
  41 
  42 import java.io.*;
  43 import java.nio.*;
  44 import java.nio.channels.*;
  45 import java.util.*;
  46 import java.net.*;
  47 import javax.net.ssl.*;
  48 import java.security.Security;
  49 
  50 public class SSLSocketExplorer {
  51 


 131             if (n < 0) {
 132                 throw new Exception("unexpected end of stream!");
 133             }
 134             position += n;
 135         }
 136 
 137         capabilities = SSLExplorer.explore(buffer, 0, recordLength);;
 138         if (capabilities != null) {
 139             System.out.println("Record version: " +
 140                     capabilities.getRecordVersion());
 141             System.out.println("Hello version: " +
 142                     capabilities.getHelloVersion());
 143         }
 144 
 145         SSLSocketFactory sslsf =
 146             (SSLSocketFactory) SSLSocketFactory.getDefault();
 147         ByteArrayInputStream bais =
 148             new ByteArrayInputStream(buffer, 0, position);
 149         SSLSocket sslSocket = (SSLSocket)sslsf.createSocket(socket, bais, true);
 150 



 151         InputStream sslIS = sslSocket.getInputStream();
 152         OutputStream sslOS = sslSocket.getOutputStream();
 153 
 154         sslIS.read();
 155         sslOS.write(85);
 156         sslOS.flush();
 157 
 158         ExtendedSSLSession session = (ExtendedSSLSession)sslSocket.getSession();
 159         checkCapabilities(capabilities, session);
 160 
 161         sslSocket.close();
 162         serverSocket.close();
 163     }
 164 
 165 
 166     /*
 167      * Define the client side of the test.
 168      *
 169      * If the server prematurely exits, serverReady will be set to true
 170      * to avoid infinite hangs.


   1 /*
   2  * Copyright (c) 2012, 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 7068321 8190492
  32  * @summary Support TLS Server Name Indication (SNI) Extension in JSSE Server
  33  * @library ../templates
  34  * @build SSLCapabilities SSLExplorer
  35  * @run main/othervm SSLSocketExplorer SSLv2Hello,SSLv3
  36  * @run main/othervm SSLSocketExplorer SSLv3
  37  * @run main/othervm SSLSocketExplorer TLSv1
  38  * @run main/othervm SSLSocketExplorer TLSv1.1
  39  * @run main/othervm SSLSocketExplorer TLSv1.2
  40  */
  41 
  42 import java.io.*;
  43 import java.nio.*;
  44 import java.nio.channels.*;
  45 import java.util.*;
  46 import java.net.*;
  47 import javax.net.ssl.*;
  48 import java.security.Security;
  49 
  50 public class SSLSocketExplorer {
  51 


 131             if (n < 0) {
 132                 throw new Exception("unexpected end of stream!");
 133             }
 134             position += n;
 135         }
 136 
 137         capabilities = SSLExplorer.explore(buffer, 0, recordLength);;
 138         if (capabilities != null) {
 139             System.out.println("Record version: " +
 140                     capabilities.getRecordVersion());
 141             System.out.println("Hello version: " +
 142                     capabilities.getHelloVersion());
 143         }
 144 
 145         SSLSocketFactory sslsf =
 146             (SSLSocketFactory) SSLSocketFactory.getDefault();
 147         ByteArrayInputStream bais =
 148             new ByteArrayInputStream(buffer, 0, position);
 149         SSLSocket sslSocket = (SSLSocket)sslsf.createSocket(socket, bais, true);
 150 
 151         // Enable all supported protocols on server side to test SSLv3
 152         sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
 153 
 154         InputStream sslIS = sslSocket.getInputStream();
 155         OutputStream sslOS = sslSocket.getOutputStream();
 156 
 157         sslIS.read();
 158         sslOS.write(85);
 159         sslOS.flush();
 160 
 161         ExtendedSSLSession session = (ExtendedSSLSession)sslSocket.getSession();
 162         checkCapabilities(capabilities, session);
 163 
 164         sslSocket.close();
 165         serverSocket.close();
 166     }
 167 
 168 
 169     /*
 170      * Define the client side of the test.
 171      *
 172      * If the server prematurely exits, serverReady will be set to true
 173      * to avoid infinite hangs.


< prev index next >