Path: blob/master/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java
41152 views
/*1* Copyright (c) 2013, 2014, 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 802799126* @summary InputStream should be closed in sun.security.tools.jarsigner.Main27* @modules java.base/sun.security.tools.keytool28* jdk.jartool/sun.security.tools.jarsigner29* @run main/othervm CertChainUnclosed30*/3132import java.nio.file.Files;33import java.nio.file.Paths;34import java.security.AccessController;35import java.security.PrivilegedAction;36import java.util.Locale;3738public class CertChainUnclosed {3940public static void main(String[] args) throws Exception {41String os = AccessController.doPrivileged(42(PrivilegedAction<String>)() -> System.getProperty("os.name"));43if (!os.toUpperCase(Locale.US).contains("WINDOWS")) {44System.out.println("Not Windows. Skip test.");45return;46}4748kt("-genkeypair -alias a -dname CN=A");49kt("-exportcert -file a.crt -alias a");50Files.copy(Paths.get(System.getProperty("test.src"), "AlgOptions.jar"),51Paths.get("test.jar"));52sun.security.tools.jarsigner.Main.main(53"-storepass changeit -keystore jks -certchain a.crt test.jar a"54.split(" "));5556// On Windows, if the file is still opened (or not if GC was57// performed) and the next line would fail58Files.delete(Paths.get("a.crt"));59}6061static void kt(String args) throws Exception {62sun.security.tools.keytool.Main.main(63("-keystore jks -storepass changeit -keypass changeit -keyalg rsa "64+ args).split(" "));65}66}676869