Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/warnings/NoTimestampTest.java
38862 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 java.util.Date;24import jdk.testlibrary.OutputAnalyzer;25import jdk.testlibrary.ProcessTools;26import jdk.testlibrary.JarUtils;2728/**29* @test30* @bug 8024302 802603731* @summary Checks warnings if -tsa and -tsacert options are not specified32* @library /lib/testlibrary ../33* @run main NoTimestampTest34*/35public class NoTimestampTest extends Test {3637/**38* The test signs and verifies a jar file without -tsa and -tsacert options,39* and checks that proper warnings are shown.40*/41public static void main(String[] args) throws Throwable {42NoTimestampTest test = new NoTimestampTest();43test.start();44}4546private void start() throws Throwable {47String timezone = System.getProperty("user.timezone");48System.out.println(String.format("Timezone = %s", timezone));4950// create a jar file that contains one class file51Utils.createFiles(FIRST_FILE);52JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);5354// calculate certificate expiration date55Date expirationDate = new Date(System.currentTimeMillis() + VALIDITY56* 24 * 60 * 60 * 1000L);5758// create key pair59createAlias(CA_KEY_ALIAS, "-ext", "bc:c");60createAlias(KEY_ALIAS);61issueCert(KEY_ALIAS,62"-validity", Integer.toString(VALIDITY));6364// sign jar file65OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,66"-J-Duser.timezone=" + timezone,67"-keystore", KEYSTORE,68"-storepass", PASSWORD,69"-keypass", PASSWORD,70"-signedjar", SIGNED_JARFILE,71UNSIGNED_JARFILE,72KEY_ALIAS);7374String warning = String.format(NO_TIMESTAMP_SIGNING_WARN_TEMPLATE,75expirationDate);76checkSigning(analyzer, warning);7778// verify signed jar79analyzer = ProcessTools.executeCommand(JARSIGNER,80"-J-Duser.timezone=" + timezone,81"-verify",82"-keystore", KEYSTORE,83"-storepass", PASSWORD,84"-keypass", PASSWORD,85SIGNED_JARFILE,86KEY_ALIAS);8788warning = String.format(NO_TIMESTAMP_VERIFYING_WARN_TEMPLATE, expirationDate);89checkVerifying(analyzer, 0, warning);9091// verify signed jar in strict mode92analyzer = ProcessTools.executeCommand(JARSIGNER,93"-J-Duser.timezone=" + timezone,94"-verify",95"-strict",96"-keystore", KEYSTORE,97"-storepass", PASSWORD,98"-keypass", PASSWORD,99SIGNED_JARFILE,100KEY_ALIAS);101102checkVerifying(analyzer, 0, warning);103104System.out.println("Test passed");105}106107}108109110