Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/HasExpiringCertTest.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 hasExpiringCert warning31* @library /lib/testlibrary ../32* @run main HasExpiringCertTest33*/34public class HasExpiringCertTest extends Test {3536static final int SHORT_VALIDITY = 90; // less than 6 month3738/**39* The test signs and verifies a jar that contains entries40* whose signer certificate will expire within six months (hasExpiringCert).41* Warning message is expected.42*/43public static void main(String[] args) throws Throwable {44HasExpiringCertTest test = new HasExpiringCertTest();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 key pair for jar signing54createAlias(CA_KEY_ALIAS, "-ext", "bc:c");55createAlias(KEY_ALIAS);5657issueCert(58KEY_ALIAS,59"-validity", Integer.toString(SHORT_VALIDITY));6061// sign jar62OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,63"-keystore", KEYSTORE,64"-verbose",65"-storepass", PASSWORD,66"-keypass", PASSWORD,67"-signedjar", SIGNED_JARFILE,68UNSIGNED_JARFILE,69KEY_ALIAS);7071checkSigning(analyzer, HAS_EXPIRING_CERT_SIGNING_WARNING);7273// verify signed jar74analyzer = ProcessTools.executeCommand(JARSIGNER,75"-verify",76"-verbose",77"-keystore", KEYSTORE,78"-storepass", PASSWORD,79"-keypass", PASSWORD,80SIGNED_JARFILE,81KEY_ALIAS);8283checkVerifying(analyzer, 0, HAS_EXPIRING_CERT_VERIFYING_WARNING);8485// verify signed jar in strict mode86analyzer = ProcessTools.executeCommand(JARSIGNER,87"-verify",88"-verbose",89"-strict",90"-keystore", KEYSTORE,91"-storepass", PASSWORD,92"-keypass", PASSWORD,93SIGNED_JARFILE,94KEY_ALIAS);9596checkVerifying(analyzer, 0, HAS_EXPIRING_CERT_VERIFYING_WARNING);9798System.out.println("Test passed");99}100101}102103104