jdk/test/sun/security/ssl/SSLContextImpl/NullGetAcceptedIssuers.java
author xuelei
Wed, 05 Mar 2014 07:24:34 +0000
changeset 23052 241885315119
parent 12302 jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLContextImpl/NullGetAcceptedIssuers.java@0c8557ba0b8f
permissions -rw-r--r--
8032473: Restructure JSSE regression test hierarchy in jdk test Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12302
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     1
/*
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     4
 *
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     8
 *
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    13
 * accompanied this code).
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    14
 *
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    18
 *
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    21
 * questions.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    22
 */
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    23
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    24
/*
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    25
 * @test
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    26
 * @bug 7142172
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    27
 * @summary Custom TrustManagers that return null for getAcceptedIssuers
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    28
 *          will NPE.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    29
 *     SunJSSE does not support dynamic system properties, no way to
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    30
 *     re-use system properties in samevm/agentvm mode.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    31
 * @run main/othervm NullGetAcceptedIssuers
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    32
 */
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    33
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    34
import javax.net.ssl.*;
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    35
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    36
public class NullGetAcceptedIssuers {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    37
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    39
        SSLContext sslContext;
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    40
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    41
        // Create a trust manager that does not validate certificate chains
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    42
        TrustManager[] trustAllCerts =
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    43
            new TrustManager[] {new X509TrustManager() {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    44
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    45
                public void checkClientTrusted(
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    46
                        java.security.cert.X509Certificate[] certs,
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    47
                        String authType) {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    48
                }
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    49
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    50
                public void checkServerTrusted(
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    51
                        java.security.cert.X509Certificate[] certs,
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    52
                        String authType) {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    53
                }
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    54
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    55
                // API says empty array, but some custom TMs are
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    56
                // returning null.
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    57
                public java.security.cert.X509Certificate[]
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    58
                        getAcceptedIssuers() {
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    59
                    return null;
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    60
                }
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    61
            }};
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    62
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    63
        sslContext = javax.net.ssl.SSLContext.getInstance("SSL");
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    64
        sslContext.init(null, trustAllCerts, null);
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    65
    }
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
diff changeset
    66
}