Path: blob/master/test/jdk/sun/security/mscapi/KeytoolChangeAlias.java
41152 views
/*1* Copyright (c) 2018, 2019, 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*/2223import jdk.test.lib.SecurityTools;24import jdk.test.lib.security.CertUtils;2526import java.security.KeyStore;2728/*29* @test30* @bug 6415696 6931562 818057031* @requires os.family == "windows"32* @library /test/lib33* @summary Test "keytool -changealias" using the Microsoft CryptoAPI provider.34*/35public class KeytoolChangeAlias {36public static void main(String[] args) throws Exception {3738KeyStore ks = KeyStore.getInstance("Windows-MY");39ks.load(null, null);4041try {42ks.setCertificateEntry("246810", CertUtils.getCertFromFile("246810.cer"));4344if (ks.containsAlias("13579")) {45ks.deleteEntry("13579");46}4748int before = ks.size();4950ks.store(null, null); // no-op, but let's do it before a keytool command5152SecurityTools.keytool("-changealias",53"-storetype", "Windows-My",54"-alias", "246810",55"-destalias", "13579").shouldHaveExitValue(0);5657ks.load(null, null);5859if (ks.size() != before) {60throw new Exception("error: unexpected number of entries in the "61+ "Windows-MY store. Before: " + before62+ ". After: " + ks.size());63}6465if (!ks.containsAlias("13579")) {66throw new Exception("error: cannot find the new alias name"67+ " in the Windows-MY store");68}69} finally {70ks.deleteEntry("13579");71ks.deleteEntry("246810");72ks.store(null, null);73}74}75}767778