Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/NotSignedByAliasTest.java
38861 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 notSignedByAlias warning31* @library /lib/testlibrary ../32* @run main NotSignedByAliasTest33*/34public class NotSignedByAliasTest extends Test {3536/**37* The test signs and verifies a jar that contains signed entries38* which are not signed by the specified alias(es) (notSignedByAlias).39* Warning message is expected.40*/41public static void main(String[] args) throws Throwable {42NotSignedByAliasTest test = new NotSignedByAliasTest();43test.start();44}4546protected void start() throws Throwable {47// create a jar file that contains one class file48Utils.createFiles(FIRST_FILE);49JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5051createAlias(CA_KEY_ALIAS, "-ext", "bc:c");5253// create first key pair for signing54createAlias(FIRST_KEY_ALIAS);55issueCert(56FIRST_KEY_ALIAS,57"-validity", Integer.toString(VALIDITY));5859// create first key pair for signing60createAlias(SECOND_KEY_ALIAS);61issueCert(62SECOND_KEY_ALIAS,63"-validity", Integer.toString(VALIDITY));6465// sign jar with first key66OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,67"-keystore", KEYSTORE,68"-storepass", PASSWORD,69"-keypass", PASSWORD,70"-signedjar", SIGNED_JARFILE,71UNSIGNED_JARFILE,72FIRST_KEY_ALIAS);7374checkSigning(analyzer);7576// verify jar with second key77analyzer = ProcessTools.executeCommand(JARSIGNER,78"-verify",79"-keystore", KEYSTORE,80"-storepass", PASSWORD,81"-keypass", PASSWORD,82SIGNED_JARFILE,83SECOND_KEY_ALIAS);8485checkVerifying(analyzer, 0, NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING);8687// verify jar with second key in strict mode88analyzer = ProcessTools.executeCommand(JARSIGNER,89"-verify",90"-strict",91"-keystore", KEYSTORE,92"-storepass", PASSWORD,93"-keypass", PASSWORD,94SIGNED_JARFILE,95SECOND_KEY_ALIAS);9697checkVerifying(analyzer, NOT_SIGNED_BY_ALIAS_EXIT_CODE,98NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING);99100// verify jar with non-existing alias101analyzer = ProcessTools.executeCommand(JARSIGNER,102"-verify",103"-keystore", KEYSTORE,104"-storepass", PASSWORD,105"-keypass", PASSWORD,106SIGNED_JARFILE,107"bogus");108109checkVerifying(analyzer, 0, NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING);110111// verify jar with non-existing alias in strict mode112analyzer = ProcessTools.executeCommand(JARSIGNER,113"-verify",114"-strict",115"-keystore", KEYSTORE,116"-storepass", PASSWORD,117"-keypass", PASSWORD,118SIGNED_JARFILE,119"bogus");120121checkVerifying(analyzer, NOT_SIGNED_BY_ALIAS_EXIT_CODE,122NOT_SIGNED_BY_ALIAS_VERIFYING_WARNING);123124System.out.println("Test passed");125}126127}128129130