test/jdk/sun/security/ssl/SSLContextImpl/TrustTrustedCert.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     4
 *
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    10
 *
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    15
 * accompanied this code).
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    16
 *
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    20
 *
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    23
 * questions.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    24
 */
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    25
22268
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
    26
//
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
    27
// SunJSSE does not support dynamic system properties, no way to re-use
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
    28
// system properties in samevm/agentvm mode.
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
    29
//
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
    30
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    31
/*
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    32
 * @test
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    33
 * @bug 7113275 8164846
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    34
 * @summary compatibility issue with MD2 trust anchor and old X509TrustManager
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
    35
 * @library /javax/net/ssl/templates
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    36
 * @run main/othervm TrustTrustedCert PKIX TLSv1.1 true
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    37
 * @run main/othervm TrustTrustedCert PKIX TLSv1.1 false
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    38
 * @run main/othervm TrustTrustedCert SunX509 TLSv1.1 false
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    39
 * @run main/othervm TrustTrustedCert PKIX TLSv1.2 false
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
    40
 * @run main/othervm TrustTrustedCert SunX509 TLSv1.2 false
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    41
 */
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    42
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    43
import java.net.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    44
import java.io.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    45
import javax.net.ssl.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    46
import java.security.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    47
import java.security.cert.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    48
import java.security.spec.*;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    49
import java.security.interfaces.*;
16020
b57c48f16179 8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents: 11037
diff changeset
    50
import java.util.Base64;
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    51
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
    52
public class TrustTrustedCert extends SSLSocketTemplate {
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    53
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    54
    /*
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    55
     * Certificates and key used in the test.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    56
     */
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    57
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    58
    // It's a trust anchor signed with MD2 hash function.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    59
    static String trustedCertStr =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    60
        "-----BEGIN CERTIFICATE-----\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    61
        "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJVUzEN\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    62
        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    63
        "MTExMTE4MTExNDA0WhcNMzIxMDI4MTExNDA0WjA7MQswCQYDVQQGEwJVUzENMAsG\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    64
        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    65
        "KoZIhvcNAQEBBQADgY0AMIGJAoGBAPGyB9tugUGgxtdeqe0qJEwf9x1Gy4BOi1yR\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    66
        "wzDZY4H5LquvIfQ2V3J9X1MQENVsFvkvp65ZcFcy+ObOucXUUPFcd/iw2DVb5QXA\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    67
        "ffyeVqWD56GPi8Qe37wrJO3L6fBhN9oxp/BbdRLgjU81zx8qLEyPODhPMxV4OkcA\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    68
        "SDwZTSxxAgMBAAGjgaUwgaIwHQYDVR0OBBYEFLOAtr/YrYj9H04EDLA0fd14jisF\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    69
        "MGMGA1UdIwRcMFqAFLOAtr/YrYj9H04EDLA0fd14jisFoT+kPTA7MQswCQYDVQQG\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    70
        "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    71
        "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEC\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    72
        "BQADgYEAr8ExpXu/FTIRiMzPm0ubqwME4lniilwQUiEOD/4DbksNjEIcUyS2hIk1\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    73
        "qsmjJz3SHBnwhxl9dhJVwk2tZLkPGW86Zn0TPVRsttK4inTgCC9GFGeqQBdrU/uf\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    74
        "lipBzXWljrfbg4N/kK8m2LabtKUMMnGysM8rN0Fx2PYm5xxGvtM=\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    75
        "-----END CERTIFICATE-----";
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    76
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    77
    // The certificate issued by above trust anchor, signed with MD5
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    78
    static String targetCertStr =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    79
        "-----BEGIN CERTIFICATE-----\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    80
        "MIICeDCCAeGgAwIBAgIBAjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    81
        "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    82
        "MTExMTE4MTExNDA2WhcNMzEwODA1MTExNDA2WjBPMQswCQYDVQQGEwJVUzENMAsG\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    83
        "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEjAQBgNV\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    84
        "BAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwDnm96mw\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    85
        "fXCH4bgXk1US0VcJsQVxUtGMyncAveMuzBzNzOmKZPeqyYX1Fuh4q+cuza03WTJd\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    86
        "G9nOkNr364e3Rn1aaHjCMcBmFflObnGnhhufNmIGYogJ9dJPmhUVPEVAXrMG+Ces\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    87
        "NKy2E8woGnLMrqu6yiuTClbLBPK8fWzTXrECAwEAAaN4MHYwCwYDVR0PBAQDAgPo\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    88
        "MB0GA1UdDgQWBBSdRrpocLPJXyGfDmMWJrcEf29WGDAfBgNVHSMEGDAWgBSzgLa/\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    89
        "2K2I/R9OBAywNH3deI4rBTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIG\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    90
        "CCsGAQUFBwMDMA0GCSqGSIb3DQEBBAUAA4GBAKJ71ZiCUykkJrCLYUxlFlhvUcr9\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    91
        "sTcOc67QdroW5f412NI15SXWDiley/JOasIiuIFPjaJBjOKoHOvTjG/snVu9wEgq\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    92
        "YNR8dPsO+NM8r79C6jO+Jx5fYAC7os2XxS75h3NX0ElJcbwIXGBJ6xRrsFh/BGYH\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    93
        "yvudOlX4BkVR0l1K\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    94
        "-----END CERTIFICATE-----";
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    95
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    96
    // Private key in the format of PKCS#8.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    97
    static String targetPrivateKey =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    98
        "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMA55vepsH1wh+G4\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
    99
        "F5NVEtFXCbEFcVLRjMp3AL3jLswczczpimT3qsmF9RboeKvnLs2tN1kyXRvZzpDa\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   100
        "9+uHt0Z9Wmh4wjHAZhX5Tm5xp4YbnzZiBmKICfXST5oVFTxFQF6zBvgnrDSsthPM\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   101
        "KBpyzK6rusorkwpWywTyvH1s016xAgMBAAECgYEAn9bF3oRkdDoBU0i/mcww5I+K\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   102
        "SH9tFt+WQbiojjz9ac49trkvUfu7MO1Jui2+QbrvaSkyj+HYGFOJd1wMsPXeB7ck\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   103
        "5mOIYV4uZK8jfNMSQ8v0tFEeIPp5lKdw1XnrQfSe+abo2eL5Lwso437Y4s3w37+H\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   104
        "aY3d76hR5qly+Ys+Ww0CQQDjeOoX89d/xhRqGXKjCx8ImE/dPmsI8O27cwtKrDYJ\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   105
        "6t0v/xryVIdvOYcRBvKnqEogOH7T1kI+LnWKUTJ2ehJ7AkEA2FVloPVqCehXcc7e\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   106
        "z3TDpU9w1B0JXklcV5HddYsRqp9RukN/VK4szKE7F1yoarIUtfE9Lr9082Jwyp3M\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   107
        "L11xwwJBAKsZ+Hur3x0tUY29No2Nf/pnFyvEF57SGwA0uPmiL8Ol9lpz+UDudDEl\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   108
        "hIM6Rqv12kwCMuQE9i7vo1o3WU3k5KECQEqhg1L49yD935TqiiFFpe0Ur9btQXse\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   109
        "kdXAA4d2d5zGI7q/aGD9SYU6phkUJSHR16VA2RuUfzMrpb+wmm1IrmMCQFtLoKRT\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   110
        "A5kokFb+E3Gplu29tJvCUpfwgBFRS+wmkvtiaU/tiyDcVgDO+An5DwedxxdVzqiE\n" +
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   111
        "njWHoKY3axDQ8OU=\n";
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   112
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   113
    static char passphrase[] = "passphrase".toCharArray();
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   114
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   115
    @Override
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   116
    protected SSLContext createServerSSLContext() throws Exception {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   117
        return generateSSLContext();
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   118
    }
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   119
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   120
    @Override
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   121
    protected void configureServerSocket(SSLServerSocket socket) {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   122
        socket.setNeedClientAuth(true);
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   123
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   124
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   125
    @Override
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   126
    protected void runServerApplication(SSLSocket socket) throws Exception {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   127
        InputStream sslIS = socket.getInputStream();
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   128
        OutputStream sslOS = socket.getOutputStream();
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   129
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   130
        try {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   131
            sslIS.read();
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   132
            sslOS.write('A');
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   133
            sslOS.flush();
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   134
        } catch (SSLException ssle) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   135
            if (!expectFail) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   136
                throw ssle;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   137
            }   // Otherwise, ignore.
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   138
        }
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   139
    }
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   140
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   141
    @Override
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   142
    protected SSLContext createClientSSLContext() throws Exception {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   143
        return generateSSLContext();
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   144
    }
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   145
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   146
    @Override
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   147
    protected void runClientApplication(SSLSocket socket) throws Exception {
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   148
        // enable the specified TLS protocol
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   149
        socket.setEnabledProtocols(new String[] { tlsProtocol });
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   150
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   151
        InputStream sslIS = socket.getInputStream();
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   152
        OutputStream sslOS = socket.getOutputStream();
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   153
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   154
        try {
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   155
            sslOS.write('B');
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   156
            sslOS.flush();
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   157
            sslIS.read();
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   158
        } catch (SSLHandshakeException e) {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   159
            if (expectFail) {
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   160
            // focus on the CertPathValidatorException
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   161
                Throwable t = e.getCause().getCause();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   162
                if (t == null || !t.toString().contains("MD5withRSA")) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   163
                    throw new RuntimeException(
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   164
                        "Expected to see MD5withRSA in exception output", t);
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   165
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   166
            } else {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   167
                throw e;
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   168
            }
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   169
        }
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   170
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   171
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   172
    /*
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   173
     * =============================================================
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   174
     * The remainder is just support stuff
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   175
     */
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   176
    private static String tmAlgorithm;        // trust manager
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   177
    private static String tlsProtocol;        // trust manager
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   178
    // set this flag to test context of CertificateException
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   179
    private static boolean expectFail;
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   180
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   181
    private static void parseArguments(String[] args) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   182
        tmAlgorithm = args[0];
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   183
        tlsProtocol = args[1];
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   184
        expectFail = Boolean.parseBoolean(args[2]);
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   185
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   186
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   187
    private static SSLContext generateSSLContext() throws Exception {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   188
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   189
        // generate certificate from cert string
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   190
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   191
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   192
        // create a key store
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   193
        KeyStore ks = KeyStore.getInstance("JKS");
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   194
        ks.load(null, null);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   195
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   196
        // import the trused cert
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   197
        X509Certificate trusedCert = null;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   198
        ByteArrayInputStream is =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   199
                new ByteArrayInputStream(trustedCertStr.getBytes());
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   200
        trusedCert = (X509Certificate)cf.generateCertificate(is);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   201
        is.close();
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   202
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   203
        ks.setCertificateEntry("Trusted RSA Signer", trusedCert);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   204
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   205
        // generate the private key.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   206
        PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   207
                            Base64.getMimeDecoder().decode(targetPrivateKey));
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   208
        KeyFactory kf = KeyFactory.getInstance("RSA");
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   209
        RSAPrivateKey priKey =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   210
                (RSAPrivateKey)kf.generatePrivate(priKeySpec);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   211
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   212
        // generate certificate chain
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   213
        is = new ByteArrayInputStream(targetCertStr.getBytes());
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   214
        X509Certificate keyCert = (X509Certificate)cf.generateCertificate(is);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   215
        is.close();
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   216
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   217
        X509Certificate[] chain = new X509Certificate[2];
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   218
        chain[0] = keyCert;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   219
        chain[1] = trusedCert;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   220
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   221
        // import the key entry and the chain
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   222
        ks.setKeyEntry("TheKey", priKey, passphrase, chain);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   223
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   224
        // create SSL context
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   225
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   226
        tmf.init(ks);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   227
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   228
        // create the customized KM and TM
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   229
        NoneExtendedX509TM myTM =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   230
            new NoneExtendedX509TM(tmf.getTrustManagers()[0]);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   231
        NoneExtendedX509KM myKM =
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   232
            new NoneExtendedX509KM("TheKey", chain, priKey);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   233
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   234
        SSLContext ctx = SSLContext.getInstance(tlsProtocol);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   235
        // KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   236
        // kmf.init(ks, passphrase);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   237
        // ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   238
        ctx.init(new KeyManager[]{myKM}, new TrustManager[]{myTM}, null);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   239
        ks = null;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   240
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   241
        return ctx;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   242
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   243
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   244
    static class NoneExtendedX509TM implements X509TrustManager {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   245
        X509TrustManager tm;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   246
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   247
        NoneExtendedX509TM(TrustManager tm) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   248
            this.tm = (X509TrustManager)tm;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   249
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   250
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   251
        public void checkClientTrusted(X509Certificate chain[], String authType)
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   252
                throws CertificateException {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   253
            tm.checkClientTrusted(chain, authType);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   254
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   255
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   256
        public void checkServerTrusted(X509Certificate chain[], String authType)
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   257
                throws CertificateException {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   258
            tm.checkServerTrusted(chain, authType);
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   259
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   260
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   261
        public X509Certificate[] getAcceptedIssuers() {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   262
            return tm.getAcceptedIssuers();
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   263
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   264
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   265
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   266
    static class NoneExtendedX509KM implements X509KeyManager {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   267
        private String keyAlias;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   268
        private X509Certificate[] chain;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   269
        private PrivateKey privateKey;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   270
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   271
        NoneExtendedX509KM(String keyAlias, X509Certificate[] chain,
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   272
                PrivateKey privateKey) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   273
            this.keyAlias = keyAlias;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   274
            this.chain = chain;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   275
            this.privateKey = privateKey;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   276
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   277
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   278
        public String[] getClientAliases(String keyType, Principal[] issuers) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   279
            return new String[] {keyAlias};
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   280
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   281
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   282
        public String chooseClientAlias(String[] keyType, Principal[] issuers,
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   283
                Socket socket) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   284
            return keyAlias;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   285
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   286
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   287
        public String[] getServerAliases(String keyType, Principal[] issuers) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   288
            return new String[] {keyAlias};
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   289
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   290
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   291
        public String chooseServerAlias(String keyType, Principal[] issuers,
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   292
                Socket socket) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   293
            return keyAlias;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   294
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   295
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   296
        public X509Certificate[] getCertificateChain(String alias) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   297
            return chain;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   298
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   299
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   300
        public PrivateKey getPrivateKey(String alias) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   301
            return privateKey;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   302
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   303
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   304
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   305
    public static void main(String[] args) throws Exception {
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   306
        /*
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   307
         * Get the customized arguments.
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   308
         */
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   309
        parseArguments(args);
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   310
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   311
        /*
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   312
         * MD5 is used in this test case, don't disable MD5 algorithm.
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   313
         * if expectFail is set, we're testing exception message
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   314
         */
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   315
        if (!expectFail) {
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   316
            Security.setProperty("jdk.certpath.disabledAlgorithms",
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 23052
diff changeset
   317
                "MD2, RSA keySize < 1024");
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 35298
diff changeset
   318
        }
35298
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 23052
diff changeset
   319
        Security.setProperty("jdk.tls.disabledAlgorithms",
9f93cbce8c44 8144773: Further reduce use of MD5
xuelei
parents: 23052
diff changeset
   320
                "SSLv3, RC4, DH keySize < 768");
22268
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16020
diff changeset
   321
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   322
        /*
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   323
         * Start the tests.
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   324
         */
42920
781f5e69910b 8168935: sun/security/ssl/SSLContextImpl/TrustTrustedCert.java failed Intermittently
mli
parents: 40700
diff changeset
   325
        new TrustTrustedCert().run();
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   326
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
diff changeset
   327
}