jdk/test/sun/security/tools/jarsigner/compatibility/Compatibility.java
author mli
Tue, 15 Aug 2017 19:19:50 -0700
changeset 46156 79e8a865c5b8
permissions -rw-r--r--
8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases Summary: A test on checking the compatibility on jarsigner cross different JDK releases Reviewed-by: mullan Contributed-by: John Jiang <sha.jiang@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     1
/*
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     4
 *
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     8
 *
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    13
 * accompanied this code).
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    14
 *
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    18
 *
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    21
 * questions.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    22
 */
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    23
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    24
/*
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    25
 * @test
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    26
 * @summary This test is used to verify the compatibility on jarsigner cross
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    27
 *     different JDK releases. It also can be used to check jar signing (w/
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    28
 *     and w/o TSA) and verifying on some specific key algorithms and digest
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    29
 *     algorithms.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    30
 *     Note that, this is a manual test. For more details about the test and
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    31
 *     its usages, please look through README.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    32
 *
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    33
 * @modules java.base/sun.security.pkcs
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    34
 *          java.base/sun.security.timestamp
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    35
 *          java.base/sun.security.tools.keytool
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    36
 *          java.base/sun.security.util
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    37
 *          java.base/sun.security.x509
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    38
 * @library /test/lib /lib/testlibrary ../warnings
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    39
 * @compile -source 1.6 -target 1.6 JdkUtils.java
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    40
 * @run main/manual/othervm Compatibility
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    41
 */
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    42
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    43
import java.io.BufferedReader;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    44
import java.io.File;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    45
import java.io.FileReader;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    46
import java.io.FileWriter;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    47
import java.io.IOException;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    48
import java.io.PrintStream;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    49
import java.text.DateFormat;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    50
import java.text.SimpleDateFormat;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    51
import java.util.ArrayList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    52
import java.util.Calendar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    53
import java.util.Date;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    54
import java.util.HashMap;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    55
import java.util.HashSet;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    56
import java.util.List;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    57
import java.util.Map;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    58
import java.util.Set;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    59
import java.util.concurrent.TimeUnit;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    60
import java.util.regex.Matcher;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    61
import java.util.regex.Pattern;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    62
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    63
import jdk.test.lib.process.OutputAnalyzer;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    64
import jdk.test.lib.process.ProcessTools;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    65
import jdk.test.lib.util.JarUtils;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    66
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    67
public class Compatibility {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    68
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    69
    private static final String TEST_JAR_NAME = "test.jar";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    70
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    71
    private static final String TEST_SRC = System.getProperty("test.src");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    72
    private static final String TEST_CLASSES = System.getProperty("test.classes");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    73
    private static final String TEST_JDK = System.getProperty("test.jdk");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    74
    private static final String TEST_JARSIGNER = jarsignerPath(TEST_JDK);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    75
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    76
    private static final String PROXY_HOST = System.getProperty("proxyHost");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    77
    private static final String PROXY_PORT = System.getProperty("proxyPort", "80");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    78
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    79
    // An alternative security properties file.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    80
    // The test provides a default one, which only contains two lines:
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    81
    // jdk.certpath.disabledAlgorithms=MD2, MD5
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    82
    // jdk.jar.disabledAlgorithms=MD2, MD5
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    83
    private static final String JAVA_SECURITY = System.getProperty(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    84
            "javaSecurityFile", TEST_SRC + "/java.security");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    85
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    86
    private static final String PASSWORD = "testpass";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    87
    private static final String KEYSTORE = "testKeystore";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    88
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    89
    private static final String RSA = "RSA";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    90
    private static final String DSA = "DSA";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    91
    private static final String EC = "EC";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    92
    private static final String[] KEY_ALGORITHMS = new String[] {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    93
            RSA,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    94
            DSA,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    95
            EC};
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    96
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    97
    private static final String SHA1 = "SHA-1";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    98
    private static final String SHA256 = "SHA-256";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    99
    private static final String SHA512 = "SHA-512";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   100
    private static final String DEFAULT = "DEFAULT";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   101
    private static final String[] DIGEST_ALGORITHMS = new String[] {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   102
            SHA1,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   103
            SHA256,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   104
            SHA512,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   105
            DEFAULT};
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   106
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   107
    private static final boolean[] EXPIRED = new boolean[] {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   108
            false,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   109
            true};
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   110
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   111
    private static final Calendar CALENDAR = Calendar.getInstance();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   112
    private static final DateFormat DATE_FORMAT
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   113
            = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   114
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   115
    // The certificate validity period in minutes. The default value is 1440
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   116
    // minutes, namely 1 day.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   117
    private static final int CERT_VALIDITY
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   118
            = Integer.valueOf(System.getProperty("certValidity", "1440"));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   119
    static {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   120
        if (CERT_VALIDITY < 1 || CERT_VALIDITY > 1440) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   121
            throw new RuntimeException(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   122
                    "certValidity if out of range [1, 1440]: " + CERT_VALIDITY);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   123
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   124
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   125
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   126
    // If true, an additional verifying will be triggered after all of
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   127
    // valid certificates expire. The default value is false.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   128
    public static final boolean DELAY_VERIFY
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   129
            = Boolean.valueOf(System.getProperty("delayVerify", "false"));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   130
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   131
    private static long lastCertStartTime;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   132
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   133
    private static DetailsOutputStream detailsOutput;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   134
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   135
    public static void main(String[] args) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   136
        // Backups stdout and stderr.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   137
        PrintStream origStdOut = System.out;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   138
        PrintStream origStdErr = System.err;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   139
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   140
        detailsOutput = new DetailsOutputStream();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   141
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   142
        // Redirects the system output to a custom one.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   143
        PrintStream printStream = new PrintStream(detailsOutput);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   144
        System.setOut(printStream);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   145
        System.setErr(printStream);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   146
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   147
        List<TsaInfo> tsaList = tsaInfoList();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   148
        if (tsaList.size() == 0) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   149
            throw new RuntimeException("TSA service is mandatory.");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   150
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   151
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   152
        List<JdkInfo> jdkInfoList = jdkInfoList();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   153
        List<CertInfo> certList = createCertificates(jdkInfoList);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   154
        createJar();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   155
        List<SignItem> signItems = test(jdkInfoList, tsaList, certList);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   157
        boolean failed = generateReport(tsaList, signItems);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   158
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   159
        // Restores the original stdout and stderr.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   160
        System.setOut(origStdOut);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   161
        System.setErr(origStdErr);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   162
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   163
        if (failed) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   164
            throw new RuntimeException("At least one test case failed. "
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   165
                    + "Please check the failed row(s) in report.html "
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   166
                    + "or failedReport.html.");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   167
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   168
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   169
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   170
    // Creates a jar file that contains an empty file.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   171
    private static void createJar() throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   172
        String testFile = "test";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   173
        new File(testFile).createNewFile();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   174
        JarUtils.createJar(TEST_JAR_NAME, testFile);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   175
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   176
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   177
    // Creates a key store that includes a set of valid/expired certificates
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   178
    // with various algorithms.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   179
    private static List<CertInfo> createCertificates(List<JdkInfo> jdkInfoList)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   180
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   181
        List<CertInfo> certList = new ArrayList<CertInfo>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   182
        Set<String> expiredCertFilter = new HashSet<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   183
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   184
        for(JdkInfo jdkInfo : jdkInfoList) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   185
            for(String keyAlgorithm : KEY_ALGORITHMS) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   186
                for(String digestAlgorithm : DIGEST_ALGORITHMS) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   187
                    for(int keySize : keySizes(keyAlgorithm)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   188
                        for(boolean expired : EXPIRED) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   189
                            // It creates only one expired certificate for one
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   190
                            // key algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   191
                            if (expired
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   192
                                    && !expiredCertFilter.add(keyAlgorithm)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   193
                                continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   194
                            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   195
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   196
                            CertInfo certInfo = new CertInfo(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   197
                                    jdkInfo.version,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   198
                                    keyAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   199
                                    digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   200
                                    keySize,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   201
                                    expired);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   202
                            if (!certList.contains(certInfo)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   203
                                String alias = createCertificate(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   204
                                        jdkInfo.jdkPath, certInfo);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   205
                                if (alias != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   206
                                    certList.add(certInfo);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   207
                                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   208
                            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   209
                        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   210
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   211
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   212
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   213
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   214
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   215
        return certList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   216
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   217
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   218
    // Creates/Updates a key store that adds a certificate with specific algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   219
    private static String createCertificate(String jdkPath, CertInfo certInfo)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   220
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   221
        String alias = certInfo.alias();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   222
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   223
        List<String> arguments = new ArrayList<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   224
        arguments.add("-J-Djava.security.properties=" + JAVA_SECURITY);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   225
        arguments.add("-v");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   226
        arguments.add("-storetype");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   227
        arguments.add("jks");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   228
        arguments.add("-genkey");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   229
        arguments.add("-keyalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   230
        arguments.add(certInfo.keyAlgorithm);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   231
        String sigalg = sigalg(certInfo.digestAlgorithm, certInfo.keyAlgorithm);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   232
        if (sigalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   233
            arguments.add("-sigalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   234
            arguments.add(sigalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   235
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   236
        if (certInfo.keySize != 0) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   237
            arguments.add("-keysize");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   238
            arguments.add(certInfo.keySize + "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   239
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   240
        arguments.add("-dname");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   241
        arguments.add("CN=Test");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   242
        arguments.add("-alias");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   243
        arguments.add(alias);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   244
        arguments.add("-keypass");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   245
        arguments.add(PASSWORD);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   246
        arguments.add("-storepass");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   247
        arguments.add(PASSWORD);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   248
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   249
        arguments.add("-startdate");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   250
        arguments.add(startDate(certInfo.expired));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   251
        arguments.add("-validity");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   252
        arguments.add("1");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   253
        arguments.add("-keystore");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   254
        arguments.add(KEYSTORE);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   255
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   256
        OutputAnalyzer outputAnalyzer = execTool(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   257
                jdkPath + "/bin/keytool",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   258
                arguments.toArray(new String[arguments.size()]));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   259
        if (outputAnalyzer.getExitValue() == 0
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   260
                && !outputAnalyzer.getOutput().matches("[Ee]xception")) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   261
            return alias;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   262
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   263
            return null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   264
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   265
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   266
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   267
    private static String sigalg(String digestAlgorithm, String keyAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   268
        if (digestAlgorithm == DEFAULT) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   269
            return null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   270
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   271
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   272
        String keyName = keyAlgorithm == EC ? "ECDSA" : keyAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   273
        return digestAlgorithm.replace("-", "") + "with" + keyName;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   274
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   275
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   276
    // The validity period of a certificate always be 1 day. For creating an
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   277
    // expired certificate, the start date is the time before 1 day, then the
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   278
    // certificate expires immediately. And for creating a valid certificate,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   279
    // the start date is the time before (1 day - CERT_VALIDITY minutes), then
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   280
    // the certificate will expires in CERT_VALIDITY minutes.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   281
    private static String startDate(boolean expiredCert) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   282
        CALENDAR.setTime(new Date());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   283
        CALENDAR.add(Calendar.DAY_OF_MONTH, -1);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   284
        if (!expiredCert) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   285
            CALENDAR.add(Calendar.MINUTE, CERT_VALIDITY);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   286
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   287
        Date startDate = CALENDAR.getTime();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   288
        lastCertStartTime = startDate.getTime();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   289
        return DATE_FORMAT.format(startDate);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   290
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   291
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   292
    // Retrieves JDK info from the file which is specified by property jdkListFile,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   293
    // or from property jdkList if jdkListFile is not available.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   294
    private static List<JdkInfo> jdkInfoList() throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   295
        String[] jdkList = list("jdkList");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   296
        if (jdkList.length == 0) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   297
            jdkList = new String[] { TEST_JDK };
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   298
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   299
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   300
        List<JdkInfo> jdkInfoList = new ArrayList<JdkInfo>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   301
        for (String jdkPath : jdkList) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   302
            JdkInfo jdkInfo = new JdkInfo(jdkPath);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   303
            // The JDK version must be unique.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   304
            if (!jdkInfoList.contains(jdkInfo)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   305
                jdkInfoList.add(jdkInfo);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   306
            } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   307
                System.out.println("The JDK version is duplicate: " + jdkPath);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   308
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   309
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   310
        return jdkInfoList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   311
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   312
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   313
    // Retrieves TSA info from the file which is specified by property tsaListFile,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   314
    // or from property tsaList if tsaListFile is not available.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   315
    private static List<TsaInfo> tsaInfoList() throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   316
        String[] tsaList = list("tsaList");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   317
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   318
        List<TsaInfo> tsaInfoList = new ArrayList<TsaInfo>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   319
        for (int i = 0; i < tsaList.length; i++) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   320
            String[] values = tsaList[i].split(";digests=");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   321
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   322
            String[] digests = new String[0];
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   323
            if (values.length == 2) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   324
                digests = values[1].split(",");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   325
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   326
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   327
            TsaInfo bufTsa = new TsaInfo(i, values[0]);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   328
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   329
            for (String digest : digests) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   330
                bufTsa.addDigest(digest);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   331
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   332
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   333
            tsaInfoList.add(bufTsa);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   334
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   335
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   336
        return tsaInfoList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   337
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   338
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   339
    private static String[] list(String listProp)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   340
            throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   341
        String listFileProp = listProp + "File";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   342
        String listFile = System.getProperty(listFileProp);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   343
        if (!isEmpty(listFile)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   344
            System.out.println(listFileProp + "=" + listFile);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   345
            List<String> list = new ArrayList<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   346
            BufferedReader reader = new BufferedReader(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   347
                    new FileReader(listFile));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   348
            String line;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   349
            while ((line = reader.readLine()) != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   350
                String item = line.trim();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   351
                if (!item.isEmpty()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   352
                    list.add(item);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   353
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   354
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   355
            reader.close();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   356
            return list.toArray(new String[list.size()]);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   357
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   358
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   359
        String list = System.getProperty(listProp);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   360
        System.out.println(listProp + "=" + list);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   361
        return !isEmpty(list) ? list.split("#") : new String[0];
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   362
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   363
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   364
    private static boolean isEmpty(String str) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   365
        return str == null || str.isEmpty();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   366
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   367
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   368
    // A JDK (signer) signs a jar with a variety of algorithms, and then all of
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   369
    // JDKs (verifiers), including the signer itself, try to verify the signed
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   370
    // jars respectively.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   371
    private static List<SignItem> test(List<JdkInfo> jdkInfoList,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   372
            List<TsaInfo> tsaInfoList, List<CertInfo> certList)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   373
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   374
        detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   375
        List<SignItem> signItems = signing(jdkInfoList, tsaInfoList, certList);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   376
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   377
        detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   378
        for (SignItem signItem : signItems) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   379
            for (JdkInfo verifierInfo : jdkInfoList) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   380
                // JDK 6 doesn't support EC
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   381
                if (!verifierInfo.isJdk6()
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   382
                        || signItem.certInfo.keyAlgorithm != EC) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   383
                    verifying(signItem, VerifyItem.build(verifierInfo));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   384
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   385
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   386
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   387
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   388
        if (DELAY_VERIFY) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   389
            detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   390
            System.out.print("Waiting for delay verifying");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   391
            long lastCertExpirationTime = lastCertStartTime + 24 * 60 * 60 * 1000;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   392
            while (System.currentTimeMillis() < lastCertExpirationTime) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   393
                TimeUnit.SECONDS.sleep(30);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   394
                System.out.print(".");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   395
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   396
            System.out.println();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   397
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   398
            System.out.println("Delay verifying starts");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   399
            for (SignItem signItem : signItems) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   400
                for (VerifyItem verifyItem : signItem.verifyItems) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   401
                    verifying(signItem, verifyItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   402
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   403
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   404
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   405
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   406
        detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   407
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   408
        return signItems;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   409
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   410
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   411
    private static List<SignItem> signing(List<JdkInfo> jdkInfos,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   412
            List<TsaInfo> tsaList, List<CertInfo> certList) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   413
        List<SignItem> signItems = new ArrayList<SignItem>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   414
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   415
        Set<String> signFilter = new HashSet<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   416
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   417
        for (JdkInfo signerInfo : jdkInfos) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   418
            for (String keyAlgorithm : KEY_ALGORITHMS) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   419
                // JDK 6 doesn't support EC
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   420
                if (signerInfo.isJdk6() && keyAlgorithm == EC) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   421
                    continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   422
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   423
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   424
                for (String digestAlgorithm : DIGEST_ALGORITHMS) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   425
                    String sigalg = sigalg(digestAlgorithm, keyAlgorithm);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   426
                    // If the signature algorithm is not supported by the JDK,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   427
                    // it cannot try to sign jar with this algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   428
                    if (sigalg != null && !signerInfo.isSupportedSigalg(sigalg)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   429
                        continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   430
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   431
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   432
                    // If the JDK doesn't support option -tsadigestalg, the
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   433
                    // associated cases just be ignored.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   434
                    if (digestAlgorithm != DEFAULT
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   435
                            && !signerInfo.supportsTsadigestalg) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   436
                        continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   437
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   438
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   439
                    for (int keySize : keySizes(keyAlgorithm)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   440
                        for (boolean expired : EXPIRED) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   441
                            CertInfo certInfo = new CertInfo(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   442
                                    signerInfo.version,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   443
                                    keyAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   444
                                    digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   445
                                    keySize,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   446
                                    expired);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   447
                            if (!certList.contains(certInfo)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   448
                                continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   449
                            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   450
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   451
                            String tsadigestalg = digestAlgorithm != DEFAULT
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   452
                                                ? digestAlgorithm
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   453
                                                : null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   454
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   455
                            for (TsaInfo tsaInfo : tsaList) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   456
                                // It has to ignore the digest algorithm, which
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   457
                                // is not supported by the TSA server.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   458
                                if(!tsaInfo.isDigestSupported(tsadigestalg)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   459
                                    continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   460
                                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   461
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   462
                                String tsaUrl = tsaInfo.tsaUrl;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   463
                                if (TsaFilter.filter(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   464
                                        signerInfo.version,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   465
                                        digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   466
                                        expired,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   467
                                        tsaInfo.index)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   468
                                    tsaUrl = null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   469
                                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   470
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   471
                                String signedJar = "JDK_"
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   472
                                        + signerInfo.version + "-CERT_"
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   473
                                        + certInfo
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   474
                                        + (tsaUrl == null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   475
                                           ? ""
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   476
                                           : "-TSA_" + tsaInfo.index);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   477
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   478
                                // It has to ignore the same jar signing.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   479
                                if (!signFilter.add(signedJar)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   480
                                    continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   481
                                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   482
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   483
                                SignItem signItem = SignItem.build()
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   484
                                        .certInfo(certInfo)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   485
                                        .version(signerInfo.version)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   486
                                        .signatureAlgorithm(sigalg)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   487
                                        .tsaDigestAlgorithm(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   488
                                                tsaUrl == null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   489
                                                ? null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   490
                                                : tsadigestalg)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   491
                                        .tsaIndex(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   492
                                                tsaUrl == null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   493
                                                ? -1
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   494
                                                : tsaInfo.index)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   495
                                        .signedJar(signedJar);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   496
                                String signingId = signingId(signItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   497
                                detailsOutput.writeAnchorName(signingId,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   498
                                        "Signing: " + signingId);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   499
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   500
                                OutputAnalyzer signOA = signJar(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   501
                                        signerInfo.jarsignerPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   502
                                        sigalg,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   503
                                        tsadigestalg,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   504
                                        tsaUrl,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   505
                                        certInfo.alias(),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   506
                                        signedJar);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   507
                                Status signingStatus = signingStatus(signOA);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   508
                                signItem.status(signingStatus);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   509
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   510
                                if (signingStatus != Status.ERROR) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   511
                                    // Using the testing JDK, which is specified
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   512
                                    // by jtreg option "-jdk", to verify the
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   513
                                    // signed jar and extract the signature
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   514
                                    // algorithm and timestamp digest algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   515
                                    String output = verifyJar(TEST_JARSIGNER,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   516
                                            signedJar).getOutput();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   517
                                    signItem.extractedSignatureAlgorithm(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   518
                                            extract(output,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   519
                                                    " *Signature algorithm.*",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   520
                                                    ".*: |,.*"));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   521
                                    signItem.extractedTsaDigestAlgorithm(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   522
                                            extract(output,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   523
                                                    " *Timestamp digest algorithm.*",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   524
                                                    ".*: "));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   525
                                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   526
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   527
                                signItems.add(signItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   528
                            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   529
                        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   530
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   531
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   532
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   533
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   534
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   535
        return signItems;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   536
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   537
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   538
    private static void verifying(SignItem signItem, VerifyItem verifyItem)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   539
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   540
        boolean delayVerify = verifyItem.status == Status.NONE;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   541
        String verifyingId = verifyingId(signItem, verifyItem, !delayVerify);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   542
        detailsOutput.writeAnchorName(verifyingId, "Verifying: " + verifyingId);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   543
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   544
        OutputAnalyzer verifyOA = verifyJar(verifyItem.jdkInfo.jarsignerPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   545
                signItem.signedJar);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   546
        Status verifyingStatus = verifyingStatus(verifyOA);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   547
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   548
        // It checks if the default timestamp digest algorithm is SHA-256.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   549
        if (verifyingStatus != Status.ERROR
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   550
                && signItem.tsaDigestAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   551
            verifyingStatus = signItem.extractedTsaDigestAlgorithm != null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   552
                                    && !signItem.extractedTsaDigestAlgorithm.matches("SHA-?256")
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   553
                            ? Status.ERROR
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   554
                            : verifyingStatus;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   555
            if (verifyingStatus == Status.ERROR) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   556
                System.out.println("The default tsa digest is not SHA-256: "
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   557
                    + signItem.extractedTsaDigestAlgorithm);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   558
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   559
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   560
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   561
        if (delayVerify) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   562
            signItem.addVerifyItem(verifyItem.status(verifyingStatus));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   563
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   564
            verifyItem.delayStatus(verifyingStatus);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   565
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   566
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   567
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   568
    // Return key sizes according to the specified key algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   569
    private static int[] keySizes(String keyAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   570
        if (keyAlgorithm == RSA || keyAlgorithm == DSA) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   571
            return new int[] { 1024, 2048, 0 };
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   572
        } else if (keyAlgorithm == EC) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   573
            return new int[] { 384, 571, 0 };
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   574
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   575
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   576
        return null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   577
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   578
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   579
    // Determines the status of signing.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   580
    private static Status signingStatus(OutputAnalyzer outputAnalyzer) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   581
        if (outputAnalyzer.getExitValue() == 0) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   582
            if (outputAnalyzer.getOutput().contains(Test.WARNING)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   583
                return Status.WARNING;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   584
            } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   585
                return Status.NORMAL;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   586
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   587
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   588
            return Status.ERROR;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   589
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   590
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   591
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   592
    // Determines the status of verifying.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   593
    private static Status verifyingStatus(OutputAnalyzer outputAnalyzer) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   594
        if (outputAnalyzer.getExitValue() == 0) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   595
            String output = outputAnalyzer.getOutput();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   596
            if (!output.contains(Test.JAR_VERIFIED)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   597
                return Status.ERROR;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   598
            } else if (output.contains(Test.WARNING)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   599
                return Status.WARNING;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   600
            } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   601
                return Status.NORMAL;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   602
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   603
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   604
            return Status.ERROR;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   605
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   606
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   607
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   608
    // Extracts string from text by specified patterns.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   609
    private static String extract(String text, String linePattern,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   610
            String replacePattern) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   611
        Matcher lineMatcher = Pattern.compile(linePattern).matcher(text);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   612
        if (lineMatcher.find()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   613
            String line = lineMatcher.group(0);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   614
            return line.replaceAll(replacePattern, "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   615
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   616
            return null;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   617
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   618
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   619
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   620
    // Using specified jarsigner to sign the pre-created jar with specified
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   621
    // algorithms.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   622
    private static OutputAnalyzer signJar(String jarsignerPath, String sigalg,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   623
            String tsadigestalg, String tsa, String alias, String signedJar)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   624
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   625
        List<String> arguments = new ArrayList<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   626
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   627
        if (PROXY_HOST != null && PROXY_PORT != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   628
            arguments.add("-J-Dhttp.proxyHost=" + PROXY_HOST);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   629
            arguments.add("-J-Dhttp.proxyPort=" + PROXY_PORT);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   630
            arguments.add("-J-Dhttps.proxyHost=" + PROXY_HOST);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   631
            arguments.add("-J-Dhttps.proxyPort=" + PROXY_PORT);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   632
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   633
        arguments.add("-J-Djava.security.properties=" + JAVA_SECURITY);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   634
        arguments.add("-debug");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   635
        arguments.add("-verbose");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   636
        if (sigalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   637
            arguments.add("-sigalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   638
            arguments.add(sigalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   639
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   640
        if (tsa != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   641
            arguments.add("-tsa");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   642
            arguments.add(tsa);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   643
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   644
        if (tsadigestalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   645
            arguments.add("-tsadigestalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   646
            arguments.add(tsadigestalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   647
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   648
        arguments.add("-keystore");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   649
        arguments.add(KEYSTORE);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   650
        arguments.add("-storepass");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   651
        arguments.add(PASSWORD);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   652
        arguments.add("-signedjar");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   653
        arguments.add(signedJar + ".jar");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   654
        arguments.add(TEST_JAR_NAME);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   655
        arguments.add(alias);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   656
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   657
        OutputAnalyzer outputAnalyzer = execTool(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   658
                jarsignerPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   659
                arguments.toArray(new String[arguments.size()]));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   660
        return outputAnalyzer;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   661
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   662
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   663
    // Using specified jarsigner to verify the signed jar.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   664
    private static OutputAnalyzer verifyJar(String jarsignerPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   665
            String signedJar) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   666
        OutputAnalyzer outputAnalyzer = execTool(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   667
                jarsignerPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   668
                "-J-Djava.security.properties=" + JAVA_SECURITY,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   669
                "-debug",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   670
                "-verbose",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   671
                "-certs",
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   672
                "-keystore", KEYSTORE,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   673
                "-verify", signedJar + ".jar");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   674
        return outputAnalyzer;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   675
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   676
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   677
    // Generates the test result report.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   678
    private static boolean generateReport(List<TsaInfo> tsaList,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   679
            List<SignItem> signItems) throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   680
        System.out.println("Report is being generated...");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   681
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   682
        StringBuilder report = new StringBuilder();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   683
        report.append(HtmlHelper.startHtml());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   684
        report.append(HtmlHelper.startPre());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   685
        // Generates TSA URLs
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   686
        report.append("TSA list:\n");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   687
        for(TsaInfo tsaInfo : tsaList) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   688
            report.append(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   689
                    String.format("%d=%s%n", tsaInfo.index, tsaInfo.tsaUrl));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   690
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   691
        report.append(HtmlHelper.endPre());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   692
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   693
        report.append(HtmlHelper.startTable());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   694
        // Generates report headers.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   695
        List<String> headers = new ArrayList<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   696
        headers.add("[Certificate]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   697
        headers.add("[Signer JDK]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   698
        headers.add("[Signature Algorithm]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   699
        headers.add("[TSA Digest]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   700
        headers.add("[TSA]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   701
        headers.add("[Signing Status]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   702
        headers.add("[Verifier JDK]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   703
        headers.add("[Verifying Status]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   704
        if (DELAY_VERIFY) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   705
            headers.add("[Delay Verifying Status]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   706
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   707
        headers.add("[Failed]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   708
        report.append(HtmlHelper.htmlRow(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   709
                headers.toArray(new String[headers.size()])));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   710
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   711
        StringBuilder failedReport = new StringBuilder(report.toString());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   712
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   713
        boolean failed = false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   714
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   715
        // Generates report rows.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   716
        for (SignItem signItem : signItems) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   717
            for (VerifyItem verifyItem : signItem.verifyItems) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   718
                String reportRow = reportRow(signItem, verifyItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   719
                report.append(reportRow);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   720
                boolean isFailedCase = isFailed(signItem, verifyItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   721
                if (isFailedCase) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   722
                    failedReport.append(reportRow);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   723
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   724
                failed = failed || isFailedCase;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   725
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   726
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   727
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   728
        report.append(HtmlHelper.endTable());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   729
        report.append(HtmlHelper.endHtml());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   730
        generateFile("report.html", report.toString());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   731
        if (failed) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   732
            failedReport.append(HtmlHelper.endTable());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   733
            failedReport.append(HtmlHelper.endPre());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   734
            failedReport.append(HtmlHelper.endHtml());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   735
            generateFile("failedReport.html", failedReport.toString());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   736
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   737
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   738
        System.out.println("Report is generated.");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   739
        return failed;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   740
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   741
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   742
    private static void generateFile(String path, String content)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   743
            throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   744
        FileWriter writer = new FileWriter(new File(path));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   745
        writer.write(content);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   746
        writer.close();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   747
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   748
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   749
    private static String jarsignerPath(String jdkPath) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   750
        return jdkPath + "/bin/jarsigner";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   751
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   752
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   753
    // Executes the specified function on JdkUtils by the specified JDK.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   754
    private static String execJdkUtils(String jdkPath, String method,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   755
            String... args) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   756
        String[] cmd = new String[args.length + 5];
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   757
        cmd[0] = jdkPath + "/bin/java";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   758
        cmd[1] = "-cp";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   759
        cmd[2] = TEST_CLASSES;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   760
        cmd[3] = JdkUtils.class.getName();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   761
        cmd[4] = method;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   762
        System.arraycopy(args, 0, cmd, 5, args.length);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   763
        return ProcessTools.executeCommand(cmd).getOutput();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   764
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   765
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   766
    // Executes the specified JDK tools, such as keytool and jarsigner, and
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   767
    // ensures the output is in US English.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   768
    private static OutputAnalyzer execTool(String toolPath, String... args)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   769
            throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   770
        String[] cmd = new String[args.length + 4];
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   771
        cmd[0] = toolPath;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   772
        cmd[1] = "-J-Duser.language=en";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   773
        cmd[2] = "-J-Duser.country=US";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   774
        cmd[3] = "-J-Djava.security.egd=file:/dev/./urandom";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   775
        System.arraycopy(args, 0, cmd, 4, args.length);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   776
        return ProcessTools.executeCommand(cmd);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   777
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   778
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   779
    private static class JdkInfo {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   780
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   781
        private final String jdkPath;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   782
        private final String jarsignerPath;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   783
        private final String version;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   784
        private final boolean supportsTsadigestalg;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   785
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   786
        private Map<String, Boolean> sigalgMap = new HashMap<String, Boolean>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   787
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   788
        private JdkInfo(String jdkPath) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   789
            this.jdkPath = jdkPath;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   790
            version = execJdkUtils(jdkPath, JdkUtils.M_JAVA_RUNTIME_VERSION);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   791
            if (version == null || version.trim().isEmpty()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   792
                throw new RuntimeException(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   793
                        "Cannot determine the JDK version: " + jdkPath);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   794
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   795
            jarsignerPath = jarsignerPath(jdkPath);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   796
            supportsTsadigestalg = execTool(jarsignerPath, "-help")
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   797
                    .getOutput().contains("-tsadigestalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   798
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   799
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   800
        private boolean isSupportedSigalg(String sigalg) throws Throwable {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   801
            if (!sigalgMap.containsKey(sigalg)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   802
                boolean isSupported = "true".equalsIgnoreCase(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   803
                        execJdkUtils(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   804
                                jdkPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   805
                                JdkUtils.M_IS_SUPPORTED_SIGALG,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   806
                                sigalg));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   807
                sigalgMap.put(sigalg, isSupported);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   808
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   809
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   810
            return sigalgMap.get(sigalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   811
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   812
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   813
        private boolean isJdk6() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   814
            return version.startsWith("1.6");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   815
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   816
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   817
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   818
        public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   819
            final int prime = 31;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   820
            int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   821
            result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   822
                    + ((version == null) ? 0 : version.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   823
            return result;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   824
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   825
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   826
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   827
        public boolean equals(Object obj) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   828
            if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   829
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   830
            if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   831
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   832
            if (getClass() != obj.getClass())
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   833
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   834
            JdkInfo other = (JdkInfo) obj;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   835
            if (version == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   836
                if (other.version != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   837
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   838
            } else if (!version.equals(other.version))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   839
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   840
            return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   841
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   842
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   843
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   844
    private static class TsaInfo {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   845
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   846
        private final int index;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   847
        private final String tsaUrl;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   848
        private Set<String> digestList = new HashSet<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   849
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   850
        private TsaInfo(int index, String tsa) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   851
            this.index = index;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   852
            this.tsaUrl = tsa;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   853
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   854
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   855
        private void addDigest(String digest) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   856
            if (!ignore(digest)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   857
                digestList.add(digest);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   858
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   859
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   860
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   861
        private static boolean ignore(String digest) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   862
            return !SHA1.equalsIgnoreCase(digest)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   863
                    && !SHA256.equalsIgnoreCase(digest)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   864
                    && !SHA512.equalsIgnoreCase(digest);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   865
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   866
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   867
        private boolean isDigestSupported(String digest) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   868
            return digest == null || digestList.isEmpty()
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   869
                    || digestList.contains(digest);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   870
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   871
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   872
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   873
    private static class CertInfo {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   874
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   875
        private final String jdkVersion;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   876
        private final String keyAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   877
        private final String digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   878
        private final int keySize;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   879
        private final boolean expired;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   880
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   881
        private CertInfo(String jdkVersion, String keyAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   882
                String digestAlgorithm, int keySize, boolean expired) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   883
            this.jdkVersion = jdkVersion;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   884
            this.keyAlgorithm = keyAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   885
            this.digestAlgorithm = digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   886
            this.keySize = keySize;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   887
            this.expired = expired;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   888
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   889
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   890
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   891
        public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   892
            final int prime = 31;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   893
            int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   894
            result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   895
                    + ((digestAlgorithm == null) ? 0 : digestAlgorithm.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   896
            result = prime * result + (expired ? 1231 : 1237);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   897
            result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   898
                    + ((jdkVersion == null) ? 0 : jdkVersion.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   899
            result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   900
                    + ((keyAlgorithm == null) ? 0 : keyAlgorithm.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   901
            result = prime * result + keySize;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   902
            return result;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   903
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   904
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   905
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   906
        public boolean equals(Object obj) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   907
            if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   908
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   909
            if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   910
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   911
            if (getClass() != obj.getClass())
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   912
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   913
            CertInfo other = (CertInfo) obj;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   914
            if (digestAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   915
                if (other.digestAlgorithm != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   916
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   917
            } else if (!digestAlgorithm.equals(other.digestAlgorithm))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   918
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   919
            if (expired != other.expired)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   920
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   921
            if (jdkVersion == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   922
                if (other.jdkVersion != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   923
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   924
            } else if (!jdkVersion.equals(other.jdkVersion))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   925
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   926
            if (keyAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   927
                if (other.keyAlgorithm != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   928
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   929
            } else if (!keyAlgorithm.equals(other.keyAlgorithm))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   930
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   931
            if (keySize != other.keySize)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   932
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   933
            return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   934
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   935
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   936
        private String alias() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   937
            return jdkVersion + "_" + toString();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   938
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   939
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   940
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   941
        public String toString() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   942
            return keyAlgorithm + "_" + digestAlgorithm
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   943
                    + (keySize == 0 ? "" : "_" + keySize)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   944
                    + (expired ? "_Expired" : "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   945
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   946
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   947
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   948
    // It does only one timestamping for the same JDK, digest algorithm and
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   949
    // TSA service with an arbitrary valid/expired certificate.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   950
    private static class TsaFilter {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   951
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   952
        private static final Set<Condition> SET = new HashSet<Condition>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   953
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   954
        private static boolean filter(String signerVersion,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   955
                String digestAlgorithm, boolean expiredCert, int tsaIndex) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   956
            return !SET.add(new Condition(signerVersion, digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   957
                    expiredCert, tsaIndex));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   958
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   959
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   960
        private static class Condition {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   961
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   962
            private final String signerVersion;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   963
            private final String digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   964
            private final boolean expiredCert;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   965
            private final int tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   966
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   967
            private Condition(String signerVersion, String digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   968
                    boolean expiredCert, int tsaIndex) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   969
                this.signerVersion = signerVersion;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   970
                this.digestAlgorithm = digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   971
                this.expiredCert = expiredCert;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   972
                this.tsaIndex = tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   973
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   974
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   975
            @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   976
            public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   977
                final int prime = 31;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   978
                int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   979
                result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   980
                        + ((digestAlgorithm == null) ? 0 : digestAlgorithm.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   981
                result = prime * result + (expiredCert ? 1231 : 1237);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   982
                result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   983
                        + ((signerVersion == null) ? 0 : signerVersion.hashCode());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   984
                result = prime * result + tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   985
                return result;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   986
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   987
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   988
            @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   989
            public boolean equals(Object obj) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   990
                if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   991
                    return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   992
                if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   993
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   994
                if (getClass() != obj.getClass())
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   995
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   996
                Condition other = (Condition) obj;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   997
                if (digestAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   998
                    if (other.digestAlgorithm != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   999
                        return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1000
                } else if (!digestAlgorithm.equals(other.digestAlgorithm))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1001
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1002
                if (expiredCert != other.expiredCert)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1003
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1004
                if (signerVersion == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1005
                    if (other.signerVersion != null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1006
                        return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1007
                } else if (!signerVersion.equals(other.signerVersion))
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1008
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1009
                if (tsaIndex != other.tsaIndex)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1010
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1011
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1012
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1013
        }}
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1014
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1015
    private static enum Status {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1016
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1017
        // No action due to pre-action fails.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1018
        NONE,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1019
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1020
        // jar is signed/verified with error
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1021
        ERROR,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1022
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1023
        // jar is signed/verified with warning
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1024
        WARNING,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1025
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1026
        // jar is signed/verified without any warning and error
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1027
        NORMAL
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1028
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1029
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1030
    private static class SignItem {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1031
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1032
        private CertInfo certInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1033
        private String version;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1034
        private String signatureAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1035
        // Signature algorithm that is extracted from verification output.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1036
        private String extractedSignatureAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1037
        private String tsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1038
        // TSA digest algorithm that is extracted from verification output.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1039
        private String extractedTsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1040
        private int tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1041
        private Status status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1042
        private String signedJar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1043
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1044
        private List<VerifyItem> verifyItems = new ArrayList<VerifyItem>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1045
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1046
        private static SignItem build() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1047
            return new SignItem();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1048
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1049
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1050
        private SignItem certInfo(CertInfo certInfo) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1051
            this.certInfo = certInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1052
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1053
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1054
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1055
        private SignItem version(String version) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1056
            this.version = version;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1057
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1058
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1059
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1060
        private SignItem signatureAlgorithm(String signatureAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1061
            this.signatureAlgorithm = signatureAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1062
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1063
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1064
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1065
        private SignItem extractedSignatureAlgorithm(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1066
                String extractedSignatureAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1067
            this.extractedSignatureAlgorithm = extractedSignatureAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1068
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1069
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1070
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1071
        private SignItem tsaDigestAlgorithm(String tsaDigestAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1072
            this.tsaDigestAlgorithm = tsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1073
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1074
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1075
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1076
        private SignItem extractedTsaDigestAlgorithm(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1077
                String extractedTsaDigestAlgorithm) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1078
            this.extractedTsaDigestAlgorithm = extractedTsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1079
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1080
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1081
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1082
        private SignItem tsaIndex(int tsaIndex) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1083
            this.tsaIndex = tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1084
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1085
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1086
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1087
        private SignItem status(Status status) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1088
            this.status = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1089
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1090
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1091
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1092
        private SignItem signedJar(String signedJar) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1093
            this.signedJar = signedJar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1094
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1095
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1096
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1097
        private void addVerifyItem(VerifyItem verifyItem) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1098
            verifyItems.add(verifyItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1099
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1100
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1101
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1102
    private static class VerifyItem {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1103
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1104
        private JdkInfo jdkInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1105
        private Status status = Status.NONE;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1106
        private Status delayStatus = Status.NONE;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1107
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1108
        private static VerifyItem build(JdkInfo jdkInfo) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1109
            VerifyItem verifyItem = new VerifyItem();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1110
            verifyItem.jdkInfo = jdkInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1111
            return verifyItem;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1112
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1113
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1114
        private VerifyItem status(Status status) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1115
            this.status = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1116
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1117
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1118
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1119
        private VerifyItem delayStatus(Status status) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1120
            this.delayStatus = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1121
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1122
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1123
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1124
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1125
    // The identifier for a specific signing.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1126
    private static String signingId(SignItem signItem) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1127
        return signItem.signedJar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1128
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1129
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1130
    // The identifier for a specific verifying.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1131
    private static String verifyingId(SignItem signItem, VerifyItem verifyItem,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1132
            boolean delayVerify) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1133
        return "S_" + signingId(signItem) + "-" + (delayVerify ? "DV" : "V")
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1134
                + "_" + verifyItem.jdkInfo.version;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1135
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1136
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1137
    private static String reportRow(SignItem signItem, VerifyItem verifyItem) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1138
        List<String> values = new ArrayList<String>();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1139
        values.add(signItem.certInfo.toString());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1140
        values.add(signItem.version);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1141
        values.add(null2Default(signItem.signatureAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1142
                signItem.extractedSignatureAlgorithm));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1143
        values.add(signItem.tsaIndex == -1
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1144
                   ? ""
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1145
                   : null2Default(signItem.tsaDigestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1146
                        signItem.extractedTsaDigestAlgorithm));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1147
        values.add(signItem.tsaIndex == -1 ? "" : signItem.tsaIndex + "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1148
        values.add(HtmlHelper.anchorLink(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1149
                PhaseOutputStream.fileName(PhaseOutputStream.Phase.SIGNING),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1150
                signingId(signItem),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1151
                signItem.status.toString()));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1152
        values.add(verifyItem.jdkInfo.version);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1153
        values.add(HtmlHelper.anchorLink(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1154
                PhaseOutputStream.fileName(PhaseOutputStream.Phase.VERIFYING),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1155
                verifyingId(signItem, verifyItem, false),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1156
                verifyItem.status.toString()));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1157
        if (DELAY_VERIFY) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1158
            values.add(HtmlHelper.anchorLink(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1159
                    PhaseOutputStream.fileName(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1160
                            PhaseOutputStream.Phase.DELAY_VERIFYING),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1161
                    verifyingId(signItem, verifyItem, true),
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1162
                    verifyItem.delayStatus.toString()));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1163
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1164
        values.add(isFailed(signItem, verifyItem) ? "X" : "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1165
        return HtmlHelper.htmlRow(values.toArray(new String[values.size()]));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1166
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1167
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1168
    private static boolean isFailed(SignItem signItem,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1169
            VerifyItem verifyItem) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1170
        return signItem.status == Status.ERROR
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1171
                || verifyItem.status == Status.ERROR
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1172
                || verifyItem.delayStatus == Status.ERROR;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1173
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1174
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1175
    // If a value is null, then displays the default value or N/A.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1176
    private static String null2Default(String value, String defaultValue) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1177
        return value == null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1178
               ? DEFAULT + "(" + (defaultValue == null
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1179
                                  ? "N/A"
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1180
                                  : defaultValue) + ")"
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1181
               : value;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1182
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1183
}