Path: blob/master/test/jdk/sun/security/tools/jarsigner/AlgOptions.java
41152 views
/*1* Copyright (c) 2005, 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*/2223/*24* @test25* @bug 5094028 621952226* @summary test new jarsigner -sigalg and -digestalg options27* @author Sean Mullan28* @library /test/lib29*/3031import jdk.test.lib.SecurityTools;32import jdk.test.lib.process.OutputAnalyzer;3334import java.nio.file.Files;35import java.nio.file.Path;36import java.util.ArrayList;37import java.util.List;3839public class AlgOptions {40public static void main(String[] args) throws Exception {4142// copy jar file into writeable location43Files.copy(Path.of(System.getProperty("test.src"), "AlgOptions.jar"),44Path.of("AlgOptionsTmp.jar"));4546// test missing signature algorithm arg47sign("-sigalg").shouldNotHaveExitValue(0);4849// test missing digest algorithm arg50sign("-digestalg").shouldNotHaveExitValue(0);5152// test BOGUS signature algorithm53sign("-sigalg", "BOGUS").shouldNotHaveExitValue(0);5455// test BOGUS digest algorithm56sign("-digestalg", "BOGUS").shouldNotHaveExitValue(0);5758// test incompatible signature algorithm59sign("-sigalg", "SHA1withDSA").shouldNotHaveExitValue(0);6061// test compatible signature algorithm62sign("-sigalg", "SHA512withRSA").shouldHaveExitValue(0);63verify();6465// test non-default digest algorithm66sign("-digestalg", "SHA-1").shouldHaveExitValue(0);67verify();6869// test SHA-512 digest algorithm (creates long lines)70sign("-digestalg", "SHA-512", "-sigalg", "SHA512withRSA")71.shouldHaveExitValue(0);72verify();73}7475static OutputAnalyzer sign(String... options) throws Exception {76List<String> args = new ArrayList<>();77args.add("-keystore");78args.add(Path.of(System.getProperty("test.src"), "JarSigning.keystore")79.toString());80args.add("-storepass");81args.add("bbbbbb");82for (String option : options) {83args.add(option);84}85args.add("AlgOptionsTmp.jar");86args.add("c");87return SecurityTools.jarsigner(args);88}8990static void verify() throws Exception {91SecurityTools.jarsigner(92"-verify", "AlgOptionsTmp.jar")93.shouldHaveExitValue(0);94}95}969798