Path: blob/master/test/jdk/sun/security/ssl/X509KeyManager/NullCases.java
41152 views
/*1* Copyright (c) 2005, 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 6302126 6302321 6302271 630230426* @summary KeyManagerFactory.init method throws unspecified exception27* for NewSunX509 algorithm28* X509KeyManager implementation for NewSunX509 throws unspecified29* ProviderException30* X509KeyManager implementation for NewSunX509 algorithm returns empty31* arrays instead of null32* X509KeyManager implementation for NewSunX509 throws unspecified33* NullPointerException34*/35import java.io.*;36import java.net.*;37import java.security.*;38import javax.net.ssl.*;39import java.security.cert.X509Certificate;4041import java.util.*;424344public class NullCases {45public static void main(String[] args) throws Exception {46KeyManagerFactory kmf;47X509KeyManager km;48char [] password = {' '};4950// check for bug 630212651kmf = KeyManagerFactory.getInstance("NewSunX509");52kmf.init((KeyStore)null, password);5354// check for 630232155km = (X509KeyManager) kmf.getKeyManagers()[0];56X509Certificate[] certs = km.getCertificateChain("doesnotexist");57PrivateKey priv = km.getPrivateKey("doesnotexist");58if (certs != null || priv != null) {59throw new Exception("Should return null if the alias can't be found");60}6162// check for 630227163String[] clis = km.getClientAliases("doesnotexist", null);64if (clis != null && clis.length == 0) {65throw new Exception("Should return null instead of empty array");66}67String[] srvs = km.getServerAliases("doesnotexist", null);68if (srvs != null && srvs.length == 0) {69throw new Exception("Should return null instead of empty array");70}7172// check for 630230473km.getServerAliases(null, null);74km.getClientAliases(null, null);75km.getCertificateChain(null);76km.getPrivateKey(null);77km.chooseServerAlias(null, null, null);78km.chooseClientAlias(null, null, null);79}80}818283