Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/HasExpiredCertTest.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 hasExpiredCert warning31* @library /lib/testlibrary ../32* @run main HasExpiredCertTest33*/34public class HasExpiredCertTest extends Test {3536static final int SHORT_VALIDITY = 365;3738/**39* The test signs and verifies a jar that contains entries40* whose signer certificate has expired (hasExpiredCert).41* Warning message is expected.42*/43public static void main(String[] args) throws Throwable {44HasExpiredCertTest test = new HasExpiredCertTest();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"-startdate", "-" + SHORT_VALIDITY * 2 + "d",60"-validity", Integer.toString(SHORT_VALIDITY));6162// sign jar63OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,64"-keystore", KEYSTORE,65"-storepass", PASSWORD,66"-keypass", PASSWORD,67"-signedjar", SIGNED_JARFILE,68UNSIGNED_JARFILE,69KEY_ALIAS);7071checkSigning(analyzer, HAS_EXPIRED_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);8182checkVerifying(analyzer, 0, HAS_EXPIRED_CERT_VERIFYING_WARNING);8384analyzer = ProcessTools.executeCommand(JARSIGNER,85"-verify",86"-strict",87"-keystore", KEYSTORE,88"-storepass", PASSWORD,89"-keypass", PASSWORD,90SIGNED_JARFILE);9192checkVerifying(analyzer, HAS_EXPIRED_CERT_EXIT_CODE,93HAS_EXPIRED_CERT_VERIFYING_WARNING);9495System.out.println("Test passed");96}9798}99100101