Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/BadKeyUsageTest.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 badKeyUsage warning31* @library /lib/testlibrary ../32* @ignore until 8026393 is fixed33* @run main BadKeyUsageTest34*/35public class BadKeyUsageTest extends Test {3637/**38* The test signs and verifies a jar that contains entries39* whose signer certificate's KeyUsage extension40* doesn't allow code signing (badKeyUsage).41* Warning message is expected.42*/43public static void main(String[] args) throws Throwable {44BadKeyUsageTest test = new BadKeyUsageTest();45test.start();46}4748private void start() throws Throwable {49// create a jar file that contains one class file50Utils.createFiles(FIRST_FILE);51JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5253// create a certificate whose signer certificate's KeyUsage extension54// doesn't allow code signing55createAlias(CA_KEY_ALIAS, "-ext", "bc:c");56createAlias(KEY_ALIAS);5758issueCert(59KEY_ALIAS,60"-ext", "KeyUsage=keyAgreement",61"-validity", Integer.toString(VALIDITY));6263// sign jar64OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,65"-verbose",66"-keystore", KEYSTORE,67"-storepass", PASSWORD,68"-keypass", PASSWORD,69"-signedjar", SIGNED_JARFILE,70UNSIGNED_JARFILE,71KEY_ALIAS);7273checkSigning(analyzer, BAD_KEY_USAGE_SIGNING_WARNING);7475// verify signed jar76analyzer = ProcessTools.executeCommand(JARSIGNER,77"-verify",78"-verbose",79"-keystore", KEYSTORE,80"-storepass", PASSWORD,81"-keypass", PASSWORD,82SIGNED_JARFILE);8384checkVerifying(analyzer, 0, BAD_KEY_USAGE_VERIFYING_WARNING);8586// verify signed jar in strict mode87analyzer = ProcessTools.executeCommand(JARSIGNER,88"-verify",89"-verbose",90"-strict",91"-keystore", KEYSTORE,92"-storepass", PASSWORD,93"-keypass", PASSWORD,94SIGNED_JARFILE);9596checkVerifying(analyzer, BAD_KEY_USAGE_EXIT_CODE,97BAD_KEY_USAGE_VERIFYING_WARNING);9899System.out.println("Test passed");100}101102}103104105