1/* 2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 4387882 27 * @summary Need to revisit the javadocs for JSSE, especially the 28 * promoted classes 29 * @author Brad Wetmore 30 */ 31 32import java.net.*; 33import java.io.*; 34import javax.net.ssl.*; 35import java.security.*; 36 37 38/* 39 * Tests that the null argument changes made it in ok. 40 */ 41 42public class KMTMGetNothing { 43 44 KMTMGetNothing() throws Exception { 45 char[] passphrase = "none".toCharArray(); 46 KeyStore ks = KeyStore.getInstance("JKS"); 47 ks.load(null, passphrase); 48 49 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 50 kmf.init(ks, passphrase); 51 52 X509KeyManager km = (X509KeyManager) kmf.getKeyManagers()[0]; 53 54 if (km.getCertificateChain(null) != null) { 55 throw new Exception("km.getCertificateChain(null) != null"); 56 } 57 58 if (km.getCertificateChain("fubar") != null) { 59 throw new Exception("km.getCertificateChain(\"fubar\") != null"); 60 } 61 62 if (km.getPrivateKey(null) != null) { 63 throw new Exception("km.getPrivateKey(null) != null"); 64 } 65 66 if (km.getPrivateKey("fubar") != null) { 67 throw new Exception("km.getPrivateKey(\"fubar\") != null"); 68 } 69 System.out.println("KM TESTS PASSED"); 70 71 TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 72 tmf.init(ks); 73 74 X509TrustManager tm = (X509TrustManager) tmf.getTrustManagers()[0]; 75 76 if ((tm.getAcceptedIssuers() == null) || 77 (tm.getAcceptedIssuers().length != 0)) { 78 throw new Exception("tm.getAcceptedIssuers() != null"); 79 } 80 System.out.println("TM TESTS PASSED"); 81 82 System.out.println("ALL TESTS PASSED"); 83 } 84 85 public static void main(String[] args) throws Exception { 86 new KMTMGetNothing(); 87 } 88} 89