Path: blob/master/test/jdk/javax/net/ssl/FixingJavadocs/KMTMGetNothing.java
41153 views
/*1* Copyright (c) 2001, 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 438788226* @summary Need to revisit the javadocs for JSSE, especially the27* promoted classes28* @author Brad Wetmore29*/3031import java.net.*;32import java.io.*;33import javax.net.ssl.*;34import java.security.*;353637/*38* Tests that the null argument changes made it in ok.39*/4041public class KMTMGetNothing {4243KMTMGetNothing() throws Exception {44char[] passphrase = "none".toCharArray();45KeyStore ks = KeyStore.getInstance("JKS");46ks.load(null, passphrase);4748KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");49kmf.init(ks, passphrase);5051X509KeyManager km = (X509KeyManager) kmf.getKeyManagers()[0];5253if (km.getCertificateChain(null) != null) {54throw new Exception("km.getCertificateChain(null) != null");55}5657if (km.getCertificateChain("fubar") != null) {58throw new Exception("km.getCertificateChain(\"fubar\") != null");59}6061if (km.getPrivateKey(null) != null) {62throw new Exception("km.getPrivateKey(null) != null");63}6465if (km.getPrivateKey("fubar") != null) {66throw new Exception("km.getPrivateKey(\"fubar\") != null");67}68System.out.println("KM TESTS PASSED");6970TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");71tmf.init(ks);7273X509TrustManager tm = (X509TrustManager) tmf.getTrustManagers()[0];7475if ((tm.getAcceptedIssuers() == null) ||76(tm.getAcceptedIssuers().length != 0)) {77throw new Exception("tm.getAcceptedIssuers() != null");78}79System.out.println("TM TESTS PASSED");8081System.out.println("ALL TESTS PASSED");82}8384public static void main(String[] args) throws Exception {85new KMTMGetNothing();86}87}888990