test/jdk/sun/security/mscapi/ShortRSAKeyWithinTLS.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 39344 jdk/test/sun/security/mscapi/ShortRSAKeyWithinTLS.java@7a2263aa5b3d
child 49548 8bdf2b5f472d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     1
/*
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     4
 *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     8
 *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    13
 * accompanied this code).
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    14
 *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    18
 *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    21
 * questions.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    22
 */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    23
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    24
import java.io.*;
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    25
import java.net.*;
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    26
import java.util.*;
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    27
import java.security.*;
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    28
import java.security.cert.*;
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    29
import javax.net.*;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    30
import javax.net.ssl.*;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    31
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 11521
diff changeset
    32
import sun.security.util.KeyUtil;
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    33
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    34
public class ShortRSAKeyWithinTLS {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    35
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    36
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    37
     * =============================================================
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    38
     * Set the various variables needed for the tests, then
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    39
     * specify what tests to run on each side.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    40
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    41
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    42
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    43
     * Should we run the client or server in a separate thread?
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    44
     * Both sides can throw exceptions, but do you have a preference
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    45
     * as to which side should be the main thread.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    46
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    47
    static boolean separateServerThread = false;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    48
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    49
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    50
     * Is the server ready to serve?
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    51
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    52
    volatile static boolean serverReady = false;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    53
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    54
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    55
     * Turn on SSL debugging?
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    56
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    57
    static boolean debug = false;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    58
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    59
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    60
     * If the client or server is doing some kind of object creation
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    61
     * that the other side depends on, and that thread prematurely
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    62
     * exits, you may experience a hang.  The test harness will
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    63
     * terminate all hung threads after its timeout has expired,
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    64
     * currently 3 minutes by default, but you might try to be
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    65
     * smart about it....
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    66
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    67
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    68
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    69
     * Define the server side of the test.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    70
     *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    71
     * If the server prematurely exits, serverReady will be set to true
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    72
     * to avoid infinite hangs.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    73
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    74
    void doServerSide() throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    75
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    76
        // load the key store
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    77
        serverKS = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    78
        serverKS.load(null, null);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    79
        System.out.println("Loaded keystore: Windows-MY");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    80
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    81
        // check key size
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    82
        checkKeySize(serverKS);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    83
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    84
        // initialize the SSLContext
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    85
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    86
        kmf.init(serverKS, null);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    87
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
    88
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    89
        tmf.init(serverKS);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    90
        TrustManager[] tms = tmf.getTrustManagers();
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    91
        if (tms == null || tms.length == 0) {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    92
            throw new Exception("unexpected trust manager implementation");
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    93
        } else {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    94
            if (!(tms[0] instanceof X509TrustManager)) {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    95
                throw new Exception("unexpected trust manager" +
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    96
                        " implementation: " +
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    97
                        tms[0].getClass().getCanonicalName());
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    98
            }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
    99
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   100
        serverTM = new MyExtendedX509TM((X509TrustManager)tms[0]);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   101
        tms = new TrustManager[] {serverTM};
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   102
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   103
        SSLContext ctx = SSLContext.getInstance("TLS");
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   104
        ctx.init(kmf.getKeyManagers(), tms, null);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   105
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   106
        ServerSocketFactory ssf = ctx.getServerSocketFactory();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   107
        SSLServerSocket sslServerSocket = (SSLServerSocket)
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   108
                                ssf.createServerSocket(serverPort);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   109
        sslServerSocket.setNeedClientAuth(true);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   110
        serverPort = sslServerSocket.getLocalPort();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   111
        System.out.println("serverPort = " + serverPort);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   112
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   113
        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   114
         * Signal Client, we're ready for his connect.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   115
         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   116
        serverReady = true;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   117
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   118
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   119
        InputStream sslIS = sslSocket.getInputStream();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   120
        OutputStream sslOS = sslSocket.getOutputStream();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   121
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   122
        sslIS.read();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   123
        sslOS.write(85);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   124
        sslOS.flush();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   125
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   126
        sslSocket.close();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   127
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   128
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   129
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   130
     * Define the client side of the test.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   131
     *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   132
     * If the server prematurely exits, serverReady will be set to true
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   133
     * to avoid infinite hangs.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   134
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   135
    void doClientSide() throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   136
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   137
        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   138
         * Wait for server to get started.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   139
         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   140
        while (!serverReady) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   141
            Thread.sleep(50);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   142
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   143
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   144
        // load the key store
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   145
        KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   146
        ks.load(null, null);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   147
        System.out.println("Loaded keystore: Windows-MY");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   148
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   149
        // initialize the SSLContext
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   150
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   151
        kmf.init(ks, null);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   152
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   153
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   154
        tmf.init(ks);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   155
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   156
        SSLContext ctx = SSLContext.getInstance("TLS");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   157
        ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   158
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   159
        SSLSocketFactory sslsf = ctx.getSocketFactory();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   160
        SSLSocket sslSocket = (SSLSocket)
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   161
            sslsf.createSocket("localhost", serverPort);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   162
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   163
        if (clientProtocol != null) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   164
            sslSocket.setEnabledProtocols(new String[] {clientProtocol});
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   165
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   166
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   167
        if (clientCiperSuite != null) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   168
            sslSocket.setEnabledCipherSuites(new String[] {clientCiperSuite});
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   169
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   170
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   171
        InputStream sslIS = sslSocket.getInputStream();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   172
        OutputStream sslOS = sslSocket.getOutputStream();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   173
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   174
        sslOS.write(280);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   175
        sslOS.flush();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   176
        sslIS.read();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   177
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   178
        sslSocket.close();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   179
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   180
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   181
    private void checkKeySize(KeyStore ks) throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   182
        PrivateKey privateKey = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   183
        PublicKey publicKey = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   184
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   185
        if (ks.containsAlias(keyAlias)) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   186
            System.out.println("Loaded entry: " + keyAlias);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   187
            privateKey = (PrivateKey)ks.getKey(keyAlias, null);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   188
            publicKey = (PublicKey)ks.getCertificate(keyAlias).getPublicKey();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   189
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 11521
diff changeset
   190
            int privateKeySize = KeyUtil.getKeySize(privateKey);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   191
            if (privateKeySize != keySize) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   192
                throw new Exception("Expected key size is " + keySize +
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   193
                        ", but the private key size is " + privateKeySize);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   194
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   195
16080
0e6266b88242 7192392: Better validation of client keys
xuelei
parents: 11521
diff changeset
   196
            int publicKeySize = KeyUtil.getKeySize(publicKey);
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   197
            if (publicKeySize != keySize) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   198
                throw new Exception("Expected key size is " + keySize +
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   199
                        ", but the public key size is " + publicKeySize);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   200
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   201
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   202
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   203
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   204
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   205
     * =============================================================
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   206
     * The remainder is just support stuff
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   207
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   208
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   209
    // use any free port by default
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   210
    volatile int serverPort = 0;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   211
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   212
    volatile Exception serverException = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   213
    volatile Exception clientException = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   214
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   215
    private static String keyAlias;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   216
    private static int keySize;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   217
    private static String clientProtocol = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   218
    private static String clientCiperSuite = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   219
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   220
    private static void parseArguments(String[] args) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   221
        keyAlias = args[0];
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   222
        keySize = Integer.parseInt(args[1]);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   223
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   224
        if (args.length > 2) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   225
            clientProtocol = args[2];
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   226
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   227
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   228
        if (args.length > 3) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   229
            clientCiperSuite = args[3];
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   230
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   231
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   232
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   233
    public static void main(String[] args) throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   234
        if (debug) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   235
            System.setProperty("javax.net.debug", "all");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   236
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   237
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   238
        // Get the customized arguments.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   239
        parseArguments(args);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   240
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   241
        new ShortRSAKeyWithinTLS();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   242
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   243
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   244
    Thread clientThread = null;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   245
    Thread serverThread = null;
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   246
    KeyStore serverKS;
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   247
    MyExtendedX509TM serverTM;
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   248
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   249
    /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   250
     * Primary constructor, used to drive remainder of the test.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   251
     *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   252
     * Fork off the other side, then do your work.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   253
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   254
    ShortRSAKeyWithinTLS() throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   255
        try {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   256
            if (separateServerThread) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   257
                startServer(true);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   258
                startClient(false);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   259
            } else {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   260
                startClient(true);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   261
                startServer(false);
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   262
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   263
        } catch (Exception e) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   264
            // swallow for now.  Show later
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   265
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   266
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   267
        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   268
         * Wait for other side to close down.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   269
         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   270
        if (separateServerThread) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   271
            serverThread.join();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   272
        } else {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   273
            clientThread.join();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   274
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   275
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   276
        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   277
         * When we get here, the test is pretty much over.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   278
         * Which side threw the error?
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   279
         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   280
        Exception local;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   281
        Exception remote;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   282
        String whichRemote;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   283
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   284
        if (separateServerThread) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   285
            remote = serverException;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   286
            local = clientException;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   287
            whichRemote = "server";
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   288
        } else {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   289
            remote = clientException;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   290
            local = serverException;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   291
            whichRemote = "client";
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   292
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   293
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   294
        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   295
         * If both failed, return the curthread's exception, but also
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   296
         * print the remote side Exception
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   297
         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   298
        if ((local != null) && (remote != null)) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   299
            System.out.println(whichRemote + " also threw:");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   300
            remote.printStackTrace();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   301
            System.out.println();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   302
            throw local;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   303
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   304
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   305
        if (remote != null) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   306
            throw remote;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   307
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   308
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   309
        if (local != null) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   310
            throw local;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   311
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   312
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   313
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   314
    void startServer(boolean newThread) throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   315
        if (newThread) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   316
            serverThread = new Thread() {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   317
                public void run() {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   318
                    try {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   319
                        doServerSide();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   320
                    } catch (Exception e) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   321
                        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   322
                         * Our server thread just died.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   323
                         *
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   324
                         * Release the client, if not active already...
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   325
                         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   326
                        System.err.println("Server died...");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   327
                        serverReady = true;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   328
                        serverException = e;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   329
                    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   330
                }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   331
            };
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   332
            serverThread.start();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   333
        } else {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   334
            try {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   335
                doServerSide();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   336
            } catch (Exception e) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   337
                serverException = e;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   338
            } finally {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   339
                serverReady = true;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   340
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   341
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   342
    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   343
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   344
    void startClient(boolean newThread) throws Exception {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   345
        if (newThread) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   346
            clientThread = new Thread() {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   347
                public void run() {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   348
                    try {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   349
                        doClientSide();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   350
                    } catch (Exception e) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   351
                        /*
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   352
                         * Our client thread just died.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   353
                         */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   354
                        System.err.println("Client died...");
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   355
                        clientException = e;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   356
                    }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   357
                }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   358
            };
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   359
            clientThread.start();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   360
        } else {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   361
            try {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   362
                doClientSide();
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   363
            } catch (Exception e) {
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   364
                clientException = e;
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   365
            }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   366
        }
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   367
    }
39344
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   368
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   369
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   370
    class MyExtendedX509TM extends X509ExtendedTrustManager
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   371
            implements X509TrustManager {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   372
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   373
        X509TrustManager tm;
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   374
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   375
        MyExtendedX509TM(X509TrustManager tm) {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   376
            this.tm = tm;
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   377
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   378
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   379
        public void checkClientTrusted(X509Certificate chain[], String authType)
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   380
                throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   381
            tm.checkClientTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   382
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   383
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   384
        public void checkServerTrusted(X509Certificate chain[], String authType)
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   385
                throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   386
            tm.checkServerTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   387
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   388
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   389
        public X509Certificate[] getAcceptedIssuers() {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   390
            List<X509Certificate> certs = new ArrayList<>();
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   391
            try {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   392
                for (X509Certificate c : tm.getAcceptedIssuers()) {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   393
                    if (serverKS.getCertificateAlias(c).equals(keyAlias))
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   394
                        certs.add(c);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   395
                }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   396
            } catch (KeyStoreException kse) {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   397
                throw new RuntimeException(kse);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   398
            }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   399
            return certs.toArray(new X509Certificate[certs.size()]);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   400
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   401
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   402
        public void checkClientTrusted(X509Certificate[] chain, String authType,
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   403
                Socket socket) throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   404
            tm.checkClientTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   405
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   406
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   407
        public void checkServerTrusted(X509Certificate[] chain, String authType,
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   408
                Socket socket) throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   409
            tm.checkServerTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   410
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   411
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   412
        public void checkClientTrusted(X509Certificate[] chain, String authType,
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   413
            SSLEngine engine) throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   414
            tm.checkClientTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   415
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   416
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   417
        public void checkServerTrusted(X509Certificate[] chain, String authType,
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   418
            SSLEngine engine) throws CertificateException {
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   419
            tm.checkServerTrusted(chain, authType);
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   420
        }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   421
    }
7a2263aa5b3d 8153948: sun/security/mscapi/ShortRSAKey1024.sh fails with "Field length overflow"
igerasim
parents: 33868
diff changeset
   422
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   423
}
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents:
diff changeset
   424