Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/NotYetValidCertTest.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 notYetValidCert warning31* @library /lib/testlibrary ../32* @run main NotYetValidCertTest33*/34public class NotYetValidCertTest extends Test {3536/**37* The test signs and verifies a jar that contains entries38* whose signer certificate is not yet valid (notYetValidCert).39* Warning message is expected.40*/41public static void main(String[] args) throws Throwable {42NotYetValidCertTest test = new NotYetValidCertTest();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);5051// create certificate that will be valid only tomorrow52createAlias(CA_KEY_ALIAS, "-ext", "bc:c");53createAlias(KEY_ALIAS);5455issueCert(56KEY_ALIAS,57"-startdate", "+1d",58"-validity", Integer.toString(VALIDITY));5960// sign jar61OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,62"-keystore", KEYSTORE,63"-storepass", PASSWORD,64"-keypass", PASSWORD,65"-signedjar", SIGNED_JARFILE,66UNSIGNED_JARFILE,67KEY_ALIAS);6869checkSigning(analyzer, NOT_YET_VALID_CERT_SIGNING_WARNING);7071// verify signed jar72analyzer = ProcessTools.executeCommand(JARSIGNER,73"-verify",74"-verbose",75"-keystore", KEYSTORE,76"-storepass", PASSWORD,77"-keypass", PASSWORD,78SIGNED_JARFILE,79KEY_ALIAS);8081checkVerifying(analyzer, 0, NOT_YET_VALID_CERT_VERIFYING_WARNING);8283// verify jar in strict mode84analyzer = ProcessTools.executeCommand(JARSIGNER,85"-verify",86"-verbose",87"-strict",88"-keystore", KEYSTORE,89"-storepass", PASSWORD,90"-keypass", PASSWORD,91SIGNED_JARFILE,92KEY_ALIAS);9394checkVerifying(analyzer, HAS_EXPIRED_CERT_EXIT_CODE,95NOT_YET_VALID_CERT_VERIFYING_WARNING);9697System.out.println("Test passed");98}99100}101102103