Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/HasUnsignedEntryTest.java
38860 views
/*1* Copyright (c) 2013, 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.testlibrary.OutputAnalyzer;24import jdk.testlibrary.ProcessTools;25import jdk.testlibrary.JarUtils;2627/**28* @test29* @bug 8024302 802603730* @summary Test for hasUnsignedEntry warning31* @library /lib/testlibrary ../32* @run main HasUnsignedEntryTest33*/34public class HasUnsignedEntryTest extends Test {3536/**37* The test signs and verifies a jar that contains unsigned entries38* which have not been integrity-checked (hasUnsignedEntry).39* Warning message is expected.40*/41public static void main(String[] args) throws Throwable {42HasUnsignedEntryTest test = new HasUnsignedEntryTest();43test.start();44}4546private void start() throws Throwable {47System.out.println(String.format("Create a %s that contains %s",48UNSIGNED_JARFILE, FIRST_FILE));49Utils.createFiles(FIRST_FILE, SECOND_FILE);50JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5152// create key pair for signing53createAlias(CA_KEY_ALIAS, "-ext", "bc:c");54createAlias(KEY_ALIAS);55issueCert(56KEY_ALIAS,57"-validity", Integer.toString(VALIDITY));5859// sign jar60OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,61"-verbose",62"-keystore", KEYSTORE,63"-storepass", PASSWORD,64"-keypass", PASSWORD,65"-signedjar", SIGNED_JARFILE,66UNSIGNED_JARFILE,67KEY_ALIAS);6869checkSigning(analyzer);7071System.out.println(String.format("Copy %s to %s, and add %s.class, "72+ "so it contains unsigned entry",73new Object[]{SIGNED_JARFILE, UPDATED_SIGNED_JARFILE,74SECOND_FILE}));7576JarUtils.updateJar(SIGNED_JARFILE, UPDATED_SIGNED_JARFILE, SECOND_FILE);7778// verify jar79analyzer = ProcessTools.executeCommand(JARSIGNER,80"-verify",81"-verbose",82"-keystore", KEYSTORE,83"-storepass", PASSWORD,84"-keypass", PASSWORD,85UPDATED_SIGNED_JARFILE);8687checkVerifying(analyzer, 0, HAS_UNSIGNED_ENTRY_VERIFYING_WARNING);8889// verify jar in strict mode90analyzer = ProcessTools.executeCommand(JARSIGNER,91"-verify",92"-verbose",93"-strict",94"-keystore", KEYSTORE,95"-storepass", PASSWORD,96"-keypass", PASSWORD,97UPDATED_SIGNED_JARFILE);9899checkVerifying(analyzer, HAS_UNSIGNED_ENTRY_EXIT_CODE,100HAS_UNSIGNED_ENTRY_VERIFYING_WARNING);101102System.out.println("Test passed");103}104105}106107108