Path: blob/master/test/jdk/javax/net/ssl/SSLSession/KeyManagerTrustManager.java
41152 views
/*1* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4387949 4302197 4396290 439528626* @summary A compile test to make sure some of the new functionality27* is there. It doesn't actually call anything, just compiles it.28*29* 4387949: Need to add Sockets and key arrays to the30* X509KeyManager.choose*Alias() methods31* chooseServerAlias method is reverted back to accept a single32* keytype as a parameter, please see RFE: 450101433* 4302197: There's no mechanism to select one key out of many in a keystore.34* 4396290: Need a way to pass algorithm specific parameters to TM's and KM's35* 4395286: The property for setting the default36* KeyManagerFactory/TrustManagerFactory algorithms needs real name37* @run main/othervm KeyManagerTrustManager38*39* SunJSSE does not support dynamic system properties, no way to re-use40* system properties in samevm/agentvm mode.41* @author Brad Wetmore42*/4344import java.net.*;45import java.security.*;46import java.security.cert.*;47import java.security.spec.*;48import javax.net.ssl.*;4950public class KeyManagerTrustManager implements X509KeyManager {5152public String[] getServerAliases(String keyType, Principal[] issuers) {53return null;54}55public String[] getClientAliases(String keyType, Principal[] issuers) {56return null;57}58public String chooseServerAlias(String keyType, Principal[] issuers,59Socket socket) {60return null;61}62public String chooseClientAlias(String [] keyType, Principal[] issuers,63Socket socket) {64return null;65}66public PrivateKey getPrivateKey(String alias) {67return null;68}69public X509Certificate[] getCertificateChain(String alias) {70return null;71}7273public void doit(KeyManagerFactory kmf, TrustManagerFactory tmf,74ManagerFactoryParameters mfp) throws Exception {75kmf.init(mfp);76tmf.init(mfp);77}7879public static void main(String args[]) throws Exception {80String kmfAlg = null;81String tmfAlg = null;8283// reserve the security properties84String reservedKMFacAlg =85Security.getProperty("ssl.KeyManagerFactory.algorithm");86String reservedTMFacAlg =87Security.getProperty("ssl.TrustManagerFactory.algorithm");8889try {90Security.setProperty("ssl.KeyManagerFactory.algorithm", "hello");91Security.setProperty("ssl.TrustManagerFactory.algorithm",92"goodbye");9394kmfAlg = KeyManagerFactory.getDefaultAlgorithm();95tmfAlg = TrustManagerFactory.getDefaultAlgorithm();9697if (!kmfAlg.equals("hello")) {98throw new Exception("ssl.KeyManagerFactory.algorithm not set");99}100if (!tmfAlg.equals("goodbye")) {101throw new Exception(102"ssl.TrustManagerFactory.algorithm not set");103}104} finally {105// restore the security properties106if (reservedKMFacAlg == null) {107reservedKMFacAlg = "";108}109110if (reservedTMFacAlg == null) {111reservedTMFacAlg = "";112}113Security.setProperty("ssl.KeyManagerFactory.algorithm",114reservedKMFacAlg);115Security.setProperty("ssl.TrustManagerFactory.algorithm",116reservedTMFacAlg);117}118}119}120121122