jdk/test/javax/net/ssl/SSLSession/KeyManagerTrustManager.java
author prr
Thu, 18 Dec 2014 10:45:45 -0800
changeset 29908 83e2c403fefd
parent 23052 241885315119
permissions -rw-r--r--
8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4387949 4302197 4396290 4395286
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary A compile test to make sure some of the new functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *      is there.  It doesn't actually call anything, just compiles it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 4387949: Need to add Sockets and key arrays to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *      X509KeyManager.choose*Alias() methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *      chooseServerAlias method is reverted back to accept a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *      keytype as a parameter, please see RFE: 4501014
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * 4302197: There's no mechanism to select one key out of many in a keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * 4396290: Need a way to pass algorithm specific parameters to TM's and KM's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * 4395286: The property for setting the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *      KeyManagerFactory/TrustManagerFactory algorithms needs real name
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    38
 * @run main/othervm KeyManagerTrustManager
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    39
 *
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    40
 *     SunJSSE does not support dynamic system properties, no way to re-use
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    41
 *     system properties in samevm/agentvm mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Brad Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class KeyManagerTrustManager implements X509KeyManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public String[] getServerAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public String[] getClientAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public String chooseServerAlias(String keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public String chooseClientAlias(String [] keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public PrivateKey getPrivateKey(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public X509Certificate[] getCertificateChain(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public void doit(KeyManagerFactory kmf, TrustManagerFactory tmf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            ManagerFactoryParameters mfp) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        kmf.init(mfp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        tmf.init(mfp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        String kmfAlg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String tmfAlg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    84
        // reserve the security properties
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    85
        String reservedKMFacAlg =
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    86
            Security.getProperty("ssl.KeyManagerFactory.algorithm");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    87
        String reservedTMFacAlg =
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    88
            Security.getProperty("ssl.TrustManagerFactory.algorithm");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    90
        try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    91
            Security.setProperty("ssl.KeyManagerFactory.algorithm", "hello");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    92
            Security.setProperty("ssl.TrustManagerFactory.algorithm",
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    93
                                                                "goodbye");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    94
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    95
            kmfAlg = KeyManagerFactory.getDefaultAlgorithm();
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    96
            tmfAlg = TrustManagerFactory.getDefaultAlgorithm();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    98
            if (!kmfAlg.equals("hello")) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    99
                throw new Exception("ssl.KeyManagerFactory.algorithm not set");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   100
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   101
            if (!tmfAlg.equals("goodbye")) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   102
                throw new Exception(
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   103
                        "ssl.TrustManagerFactory.algorithm not set");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   104
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   105
        } finally {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   106
            // restore the security properties
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   107
            if (reservedKMFacAlg == null) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   108
                reservedKMFacAlg = "";
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   109
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   110
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   111
            if (reservedTMFacAlg == null) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   112
                reservedTMFacAlg = "";
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   113
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   114
            Security.setProperty("ssl.KeyManagerFactory.algorithm",
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   115
                                                            reservedKMFacAlg);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   116
            Security.setProperty("ssl.TrustManagerFactory.algorithm",
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   117
                                                            reservedTMFacAlg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}