Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/BadExtendedKeyUsageTest.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 badExtendedKeyUsage warning31* @library /lib/testlibrary ../32* @run main BadExtendedKeyUsageTest33*/34public class BadExtendedKeyUsageTest extends Test {3536/**37* The test signs and verifies a jar that contains entries38* whose signer certificate's ExtendedKeyUsage extension39* doesn't allow code signing (badExtendedKeyUsage).40* Warning message is expected.41*/42public static void main(String[] args) throws Throwable {43BadExtendedKeyUsageTest test = new BadExtendedKeyUsageTest();44test.start();45}4647private void start() throws Throwable {48// create a jar file that contains one class file49Utils.createFiles(FIRST_FILE);50JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5152// create a certificate whose signer certificate's53// ExtendedKeyUsage extension doesn't allow code signing54// create key pair for jar signing55createAlias(CA_KEY_ALIAS, "-ext", "bc:c");56createAlias(KEY_ALIAS);5758issueCert(59KEY_ALIAS,60"-ext", "ExtendedkeyUsage=serverAuth",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_EXTENDED_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_EXTENDED_KEY_USAGE_VERIFYING_WARNING);8586// verity 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_EXTENDED_KEY_USAGE_EXIT_CODE,97BAD_EXTENDED_KEY_USAGE_VERIFYING_WARNING);9899System.out.println("Test passed");100}101102}103104105