Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/AliasNotInStoreTest.java
38861 views
/*1* Copyright (c) 2013, 2015, 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 aliasNotInStore warning31* @library /lib/testlibrary ../32* @run main AliasNotInStoreTest33*/34public class AliasNotInStoreTest extends Test {3536/**37* The test signs and verifies a jar that contains signed entries38* that are not signed by any alias in keystore (aliasNotInStore).39* Warning message is expected.40*/41public static void main(String[] args) throws Throwable {42AliasNotInStoreTest test = new AliasNotInStoreTest();43test.start();44}4546private void start() throws Throwable {47Utils.createFiles(FIRST_FILE, SECOND_FILE);48System.out.println(String.format("Create a %s that contains %s",49new Object[]{UNSIGNED_JARFILE, FIRST_FILE}));50JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5152// create first key pair for signing53createAlias(FIRST_KEY_ALIAS);54createAlias(SECOND_KEY_ALIAS);5556// sign jar with first key57OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,58"-keystore", KEYSTORE,59"-storepass", PASSWORD,60"-keypass", PASSWORD,61"-signedjar", SIGNED_JARFILE,62UNSIGNED_JARFILE,63FIRST_KEY_ALIAS);6465checkSigning(analyzer);6667System.out.println(String.format("Copy %s to %s, and add %s",68new Object[] {SIGNED_JARFILE, UPDATED_SIGNED_JARFILE,69SECOND_FILE}));7071JarUtils.updateJar(SIGNED_JARFILE, UPDATED_SIGNED_JARFILE, SECOND_FILE);7273// sign jar with second key74analyzer = ProcessTools.executeCommand(JARSIGNER,75"-keystore", KEYSTORE,76"-storepass", PASSWORD,77"-keypass", PASSWORD,78UPDATED_SIGNED_JARFILE,79SECOND_KEY_ALIAS);8081checkSigning(analyzer);8283// create keystore that contains only first key84ProcessTools.executeCommand(KEYTOOL,85"-importkeystore",86"-srckeystore", KEYSTORE,87"-srcalias", FIRST_KEY_ALIAS,88"-srcstorepass", PASSWORD,89"-srckeypass", PASSWORD,90"-destkeystore", FIRST_KEY_KEYSTORE,91"-destalias", FIRST_KEY_ALIAS,92"-deststorepass", PASSWORD,93"-destkeypass", PASSWORD).shouldHaveExitValue(0);9495// verify jar with keystore that contains only first key,96// so there is signed entry (FirstClass.class) that is not signed97// by any alias in the keystore98analyzer = ProcessTools.executeCommand(JARSIGNER,99"-verify",100"-verbose",101"-keystore", FIRST_KEY_KEYSTORE,102"-storepass", PASSWORD,103"-keypass", PASSWORD,104UPDATED_SIGNED_JARFILE);105106checkVerifying(analyzer, 0, CHAIN_NOT_VALIDATED_VERIFYING_WARNING,107ALIAS_NOT_IN_STORE_VERIFYING_WARNING);108109// verify jar with keystore that contains only first key in strict mode110analyzer = ProcessTools.executeCommand(JARSIGNER,111"-verify",112"-verbose",113"-strict",114"-keystore", FIRST_KEY_KEYSTORE,115"-storepass", PASSWORD,116"-keypass", PASSWORD,117UPDATED_SIGNED_JARFILE);118119int expectedExitCode = ALIAS_NOT_IN_STORE_EXIT_CODE120+ CHAIN_NOT_VALIDATED_EXIT_CODE;121checkVerifying(analyzer, expectedExitCode,122CHAIN_NOT_VALIDATED_VERIFYING_WARNING,123ALIAS_NOT_IN_STORE_VERIFYING_WARNING);124125System.out.println("Test passed");126}127128}129130131