test/jdk/sun/security/ssl/CipherSuite/SSL_NULL.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 4854838
    26  * @bug 4854838
    27  * @summary Verify that SSL_NULL_WITH_NULL_NULL is returned as ciphersuite if the handshake fails
    27  * @summary Verify that SSL_NULL_WITH_NULL_NULL is returned as ciphersuite
       
    28  *      if the handshake fails
    28  * @author Andreas Sterbenz
    29  * @author Andreas Sterbenz
    29  */
    30  */
    30 
    31 
    31 import java.io.*;
    32 import java.io.*;
    32 import java.net.ServerSocket;
    33 import java.net.ServerSocket;
    33 import java.net.Socket;
    34 import java.net.Socket;
    34 import javax.net.ssl.*;
    35 import javax.net.ssl.*;
    35 
    36 
    36 public class SSL_NULL {
    37 public class SSL_NULL {
    37 
       
    38     private static volatile Boolean result;
    38     private static volatile Boolean result;
    39 
    39 
    40     public static void main(String[] args) throws Exception {
    40     public static void main(String[] args) throws Exception {
    41         final SSLServerSocket serverSocket = (SSLServerSocket)
    41         final SSLServerSocket serverSocket = (SSLServerSocket)
    42             SSLServerSocketFactory.getDefault().createServerSocket(0);
    42             SSLServerSocketFactory.getDefault().createServerSocket(0);
    69 
    69 
    70         SSLSocket socket = (SSLSocket)
    70         SSLSocket socket = (SSLSocket)
    71             SSLSocketFactory.getDefault().createSocket(
    71             SSLSocketFactory.getDefault().createSocket(
    72                 "localhost", serverSocket.getLocalPort());
    72                 "localhost", serverSocket.getLocalPort());
    73         socket.setEnabledCipherSuites(
    73         socket.setEnabledCipherSuites(
    74             new String[] { "SSL_RSA_WITH_RC4_128_MD5" });
    74             new String[] { "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" });
    75         try {
    75         try {
    76             OutputStream out = socket.getOutputStream();
    76             OutputStream out = socket.getOutputStream();
    77             out.write(0);
    77             out.write(0);
    78             out.flush();
    78             out.flush();
    79             throw new RuntimeException("No exception received");
    79             throw new RuntimeException("No exception received");
    80         } catch (SSLHandshakeException e) {
    80         } catch (SSLHandshakeException e) {
       
    81             System.out.println("Expected handshake exception: " + e);
    81         }
    82         }
       
    83 
    82         System.out.println("client: " + socket.getSession().getCipherSuite());
    84         System.out.println("client: " + socket.getSession().getCipherSuite());
       
    85 
    83         // wait for other thread to set result
    86         // wait for other thread to set result
    84         while (result == null) {
    87         while (result == null) {
    85             Thread.sleep(50);
    88             Thread.sleep(50);
    86         }
    89         }
    87         if (result.booleanValue()) {
    90         if (result.booleanValue()) {