Path: blob/master/test/jdk/sun/security/tools/jarsigner/OnlyManifest.java
41152 views
/*1* Copyright (c) 2010, 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 700403526* @summary signed jar with only META-INF/* inside is not verifiable27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;3233import java.nio.file.Files;34import java.nio.file.Path;35import java.util.List;3637public class OnlyManifest {38static OutputAnalyzer kt(String cmd) throws Exception {39return SecurityTools.keytool("-storepass changeit -keypass changeit "40+ "-keystore ks -keyalg rsa " + cmd);41}4243static void gencert(String owner, String cmd) throws Exception {44kt("-certreq -alias " + owner + " -file tmp.req");45kt("-gencert -infile tmp.req -outfile tmp.cert " + cmd);46kt("-import -alias " + owner + " -file tmp.cert");47}4849public static void main(String[] args) throws Exception {50// Create an empty jar file with only MANIFEST.MF51Files.write(Path.of("manifest"), List.of("Key: Value"));52SecurityTools.jar("cvfm a.jar manifest");5354kt("-alias ca -dname CN=ca -genkey -validity 300 -ext bc:c")55.shouldHaveExitValue(0);56kt("-alias a -dname CN=a -genkey -validity 300")57.shouldHaveExitValue(0);58gencert("a", "-alias ca -validity 300");5960SecurityTools.jarsigner("-keystore ks -storepass changeit"61+ " a.jar a -debug -strict")62.shouldHaveExitValue(0);63SecurityTools.jarsigner("-keystore ks -storepass changeit"64+ " -verify a.jar a -debug -strict")65.shouldHaveExitValue(0)66.shouldNotContain("unsigned");67}68}697071