Path: blob/master/test/jdk/sun/security/mscapi/nonUniqueAliases/NonUniqueAliases.java
41155 views
/*1* Copyright (c) 2018, 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 6483657 815411326* @requires os.family == "windows"27* @library /test/lib28* @summary Test "keytool -list" displays correctly same named certificates29* @ignore Uses certutil.exe that isn't guaranteed to be installed30*/3132import jdk.test.lib.process.ProcessTools;3334import java.security.KeyStore;35import java.util.Collections;3637public class NonUniqueAliases {38public static void main(String[] args) throws Throwable {3940try {41String testSrc = System.getProperty("test.src", ".");4243// removing the alias NonUniqueName if it already exists44ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",45"NonUniqueName");4647// Importing 1st certificate into MY keystore using certutil tool48ProcessTools.executeCommand("certutil", "-user", "-addstore", "MY",49testSrc + "/nonUniq1.pem");5051// Importing 2nd certificate into MY keystore using certutil tool52ProcessTools.executeCommand("certutil", "-user", "-addstore", "MY",53testSrc + "/nonUniq2.pem");5455// Now we have 256checkCount(1, 1);5758ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",59"NonUniqueName");6061// Now we have 262checkCount(0, 0);63} finally {64ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",65"NonUniqueName");66}67}6869static void checkCount(int c0, int c1) throws Exception {7071KeyStore ks = KeyStore.getInstance("Windows-MY");72ks.load(null, null);7374int count0 = 0, count1 = 0;75for (String alias : Collections.list(ks.aliases())) {76if (alias.equals("NonUniqueName")) {77count0++;78}79if (alias.equals("NonUniqueName (1)")) {80count1++;81}82}83if (count0 != c0) {84throw new Exception("error: unexpected number of entries ("85+ count0 + ") in the Windows-MY store");86}87if (count1 != c1) {88throw new Exception("error: unexpected number of entries ("89+ count1 + ") in the Windows-MY store");90}91}92}939495