test/jdk/sun/security/tools/jarsigner/compatibility/Compatibility.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57581 57a391a23f7f
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
/*
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
46156
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    26
 * @bug 8217375
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    27
 * @summary This test is used to verify the compatibility of jarsigner across
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    28
 *     different JDK releases. It also can be used to check jar signing (w/
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    29
 *     and w/o TSA) and to verify some specific signing and digest algorithms.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    30
 *     Note that this is a manual test. For more details about the test and
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    31
 *     its usages, please look through the README.
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    32
 *
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    33
 * @library /test/lib ../warnings
51058
44c355346475 8206443: Update security libs manual test to cope with removal of javac -source/-target 6
jjiang
parents: 47216
diff changeset
    34
 * @compile -source 1.7 -target 1.7 JdkUtils.java
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    35
 * @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
    36
 */
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    37
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    38
import static java.nio.charset.StandardCharsets.UTF_8;
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    39
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    40
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
    41
import java.io.File;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    42
import java.io.FileOutputStream;
46156
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.FileReader;
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.FileWriter;
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.IOException;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    46
import java.io.OutputStream;
46156
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.PrintStream;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    48
import java.nio.file.Files;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    49
import java.nio.file.Path;
46156
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.DateFormat;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    51
import java.text.SimpleDateFormat;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    52
import java.util.ArrayList;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    53
import java.util.Arrays;
46156
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.Calendar;
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.Date;
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.HashMap;
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.HashSet;
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.List;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    59
import java.util.Locale;
46156
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.Map;
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.Set;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    62
import java.util.concurrent.TimeUnit;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    63
import java.util.function.Consumer;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    64
import java.util.function.Function;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    65
import java.util.jar.Attributes.Name;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    66
import java.util.jar.Manifest;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    67
import java.util.stream.Collectors;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    68
import java.util.stream.IntStream;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
    69
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    70
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
    71
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
    72
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
    73
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    74
public class Compatibility {
46156
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 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
    77
    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
    78
    private static final String TEST_JDK = System.getProperty("test.jdk");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    79
    private static JdkInfo TEST_JDK_INFO;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    80
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    81
    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
    82
    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
    83
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    84
    // 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
    85
    // 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
    86
    // 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
    87
    // 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
    88
    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
    89
            "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
    90
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 PASSWORD = "testpass";
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    92
    private static final String KEYSTORE = "testKeystore.jks";
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    93
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    94
    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
    95
    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
    96
    private static final String EC = "EC";
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    97
    private static String[] KEY_ALGORITHMS;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
    98
    private static final String[] DEFAULT_KEY_ALGORITHMS = new String[] {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    99
            RSA,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   100
            DSA,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   101
            EC};
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   102
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   103
    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
   104
    private static final String SHA256 = "SHA-256";
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   105
    private static final String SHA384 = "SHA-384";
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   106
    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
   107
    private static final String DEFAULT = "DEFAULT";
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   108
    private static String[] DIGEST_ALGORITHMS;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   109
    private static final String[] DEFAULT_DIGEST_ALGORITHMS = new String[] {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   110
            SHA1,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   111
            SHA256,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   112
            SHA384,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   113
            SHA512, // note: digests break onto continuation line in manifest
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   114
            DEFAULT};
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   115
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   116
    private static final boolean[] EXPIRED =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   117
            Boolean.valueOf(System.getProperty("expired", "true")) ?
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   118
                    new boolean[] { false, true } : new boolean[] { false };
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   119
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   120
    private static final boolean TEST_COMPREHENSIVE_JAR_CONTENTS =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   121
            Boolean.valueOf(System.getProperty(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   122
                    "testComprehensiveJarContents", "false"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   123
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   124
    private static final boolean TEST_JAR_UPDATE =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   125
            Boolean.valueOf(System.getProperty("testJarUpdate", "false"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   126
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   127
    private static final boolean STRICT =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   128
            Boolean.valueOf(System.getProperty("strict", "false"));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   129
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   130
    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
   131
    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
   132
            = 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
   133
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   134
    // 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
   135
    // 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
   136
    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
   137
            = 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
   138
    static {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   139
        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
   140
            throw new RuntimeException(
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   141
                    "certValidity out of range [1, 1440]: " + CERT_VALIDITY);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   142
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   143
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   144
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   145
    // 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
   146
    // 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
   147
    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
   148
            = 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
   149
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   150
    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
   151
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   152
    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
   153
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   154
    private static int sigfileCounter;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   155
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   156
    private static String nextSigfileName(String alias, String u, String s) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   157
        String sigfileName = "" + (++sigfileCounter);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   158
        System.out.println("using sigfile " + sigfileName + " for alias "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   159
                    + alias + " signing " + u + ".jar to " + s + ".jar");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   160
        return sigfileName;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   161
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   162
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   163
    public static void main(String... args) throws Throwable {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   164
        // 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
   165
        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
   166
        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
   167
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   168
        detailsOutput = new DetailsOutputStream(outfile());
46156
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
        // 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
   171
        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
   172
        System.setOut(printStream);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   173
        System.setErr(printStream);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   174
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   175
        TEST_JDK_INFO = new JdkInfo(TEST_JDK);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   176
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   177
        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
   178
        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
   179
        List<CertInfo> certList = createCertificates(jdkInfoList);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   180
        List<SignItem> signItems =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   181
                test(jdkInfoList, tsaList, certList, createJars());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   182
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   183
        boolean failed = generateReport(jdkInfoList, tsaList, signItems);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   184
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   185
        // 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
   186
        System.setOut(origStdOut);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   187
        System.setErr(origStdErr);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   188
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   189
        if (failed) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   190
            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
   191
                    + "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
   192
                    + "or failedReport.html.");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   193
        }
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   196
    private static SignItem createJarFile(String jar, Manifest m,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   197
            String... files) throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   198
        JarUtils.createJarFile(Path.of(jar), m, Path.of("."),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   199
                Arrays.stream(files).map(Path::of).toArray(Path[]::new));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   200
        return SignItem.build()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   201
                .signedJar(jar.replaceAll("[.]jar$", ""))
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   202
            .addContentFiles(Arrays.stream(files).collect(Collectors.toList()));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   203
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   204
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   205
    private static String createDummyFile(String name) throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   206
        if (name.contains("/")) new File(name).getParentFile().mkdir();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   207
        try (OutputStream fos = new FileOutputStream(name)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   208
            fos.write(name.getBytes(UTF_8));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   209
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   210
        return name;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   211
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   212
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   213
    // Creates one or more jar files to test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   214
    private static List<SignItem> createJars() throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   215
        List<SignItem> jarList = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   216
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   217
        Manifest m = new Manifest();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   218
        m.getMainAttributes().put(Name.MANIFEST_VERSION, "1.0");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   219
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   220
        // creates a jar file that contains a dummy file
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   221
        jarList.add(createJarFile("test.jar", m, createDummyFile("dummy")));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   222
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   223
        if (TEST_COMPREHENSIVE_JAR_CONTENTS) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   224
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   225
            // empty jar file so that jarsigner will add a default manifest
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   226
            jarList.add(createJarFile("empty.jar", m));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   227
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   228
            // jar file that contains only an empty manifest with empty main
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   229
            // attributes (due to missing "Manifest-Version" header)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   230
            JarUtils.createJar("nomainatts.jar");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   231
            jarList.add(SignItem.build().signedJar("nomainatts"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   232
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   233
            // creates a jar file that contains several files.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   234
            jarList.add(createJarFile("files.jar", m,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   235
                    IntStream.range(1, 9).boxed().map(i -> {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   236
                        try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   237
                            return createDummyFile("dummy" + i);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   238
                        } catch (IOException e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   239
                            throw new RuntimeException(e);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   240
                        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   241
                    }).toArray(String[]::new)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   242
            ));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   243
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   244
            // forces a line break by exceeding the line width limit of 72 bytes
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   245
            // in the filename and hence manifest entry name
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   246
            jarList.add(createJarFile("longfilename.jar", m,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   247
                    createDummyFile("test".repeat(20))));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   248
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   249
            // another interesting case is with different digest algorithms
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   250
            // resulting in digests broken across line breaks onto continuation
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   251
            // lines. these however are set with the 'digestAlgs' option or
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   252
            // include all digest algorithms by default, see SignTwice.java.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   253
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   254
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   255
        return jarList;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   256
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   257
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   258
    // updates a signed jar file by adding another file
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   259
    private static List<SignItem> updateJar(SignItem prev) throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   260
        List<SignItem> jarList = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   261
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   262
        // sign unmodified jar again
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   263
        Files.copy(Path.of(prev.signedJar + ".jar"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   264
                Path.of(prev.signedJar + "-signagainunmodified.jar"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   265
        jarList.add(SignItem.build(prev)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   266
                .signedJar(prev.signedJar + "-signagainunmodified"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   267
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   268
        String oldJar = prev.signedJar;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   269
        String newJar = oldJar + "-addfile";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   270
        String triggerUpdateFile = "addfile";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   271
        JarUtils.updateJar(oldJar + ".jar", newJar + ".jar", triggerUpdateFile);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   272
        jarList.add(SignItem.build(prev).signedJar(newJar)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   273
                .addContentFiles(Arrays.asList(triggerUpdateFile)));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   274
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   275
        return jarList;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   276
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   277
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   278
    // 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
   279
    // with various algorithms.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   280
    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
   281
            throws Throwable {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   282
        List<CertInfo> certList = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   283
        Set<String> expiredCertFilter = new HashSet<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   284
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   285
        for (JdkInfo jdkInfo : jdkInfoList) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   286
            for (String keyAlgorithm : keyAlgs()) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   287
                if (!jdkInfo.supportsKeyAlg(keyAlgorithm)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   288
                for (int keySize : keySizes(keyAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   289
                    for (String digestAlgorithm : digestAlgs()) {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   290
                        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
   291
                            // 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
   292
                            // key algorithm.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   293
                            if (expired
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   294
                                    && !expiredCertFilter.add(keyAlgorithm)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   295
                                continue;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   296
                            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   297
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   298
                            CertInfo certInfo = new CertInfo(
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   299
                                    jdkInfo,
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   300
                                    keyAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   301
                                    digestAlgorithm,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   302
                                    keySize,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   303
                                    expired);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   304
                            // If the signature algorithm is not supported by the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   305
                            // JDK, it cannot try to sign jar with this algorithm.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   306
                            String sigalg = certInfo.sigalg();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   307
                            if (sigalg != null &&
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   308
                                    !jdkInfo.isSupportedSigalg(sigalg)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   309
                                continue;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   310
                            }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   311
                            createCertificate(jdkInfo, certInfo);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   312
                            certList.add(certInfo);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   313
                        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   314
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   315
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   316
            }
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   319
        System.out.println("the keystore contents:");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   320
        for (JdkInfo jdkInfo : jdkInfoList) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   321
            execTool(jdkInfo.jdkPath + "/bin/keytool", new String[] {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   322
                    "-v",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   323
                    "-storetype",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   324
                    "jks",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   325
                    "-storepass",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   326
                    PASSWORD,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   327
                    "-keystore",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   328
                    KEYSTORE,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   329
                    "-list"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   330
            });
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   331
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   332
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   333
        return certList;
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
    // Creates/Updates a key store that adds a certificate with specific algorithm.
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   337
    private static void createCertificate(JdkInfo jdkInfo, CertInfo certInfo)
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   338
            throws Throwable {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   339
        List<String> arguments = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   340
        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
   341
        arguments.add("-v");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   342
        arguments.add("-debug");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   343
        arguments.add("-storetype");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   344
        arguments.add("jks");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   345
        arguments.add("-keystore");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   346
        arguments.add(KEYSTORE);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   347
        arguments.add("-storepass");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   348
        arguments.add(PASSWORD);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   349
        arguments.add(jdkInfo.majorVersion < 6 ? "-genkey" : "-genkeypair");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   350
        arguments.add("-keyalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   351
        arguments.add(certInfo.keyAlgorithm);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   352
        String sigalg = certInfo.sigalg();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   353
        if (sigalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   354
            arguments.add("-sigalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   355
            arguments.add(sigalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   356
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   357
        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
   358
            arguments.add("-keysize");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   359
            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
   360
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   361
        arguments.add("-dname");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   362
        arguments.add("CN=" + certInfo);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   363
        arguments.add("-alias");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   364
        arguments.add(certInfo.alias());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   365
        arguments.add("-keypass");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   366
        arguments.add(PASSWORD);
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
        arguments.add("-startdate");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   369
        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
   370
        arguments.add("-validity");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   371
//        arguments.add(DELAY_VERIFY ? "1" : "222"); // > six months no warn
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   372
        arguments.add("1");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   373
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   374
        OutputAnalyzer outputAnalyzer = execTool(
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   375
                jdkInfo.jdkPath + "/bin/keytool",
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   376
                arguments.toArray(new String[arguments.size()]));
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   377
        if (outputAnalyzer.getExitValue() != 0
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   378
                || outputAnalyzer.getOutput().matches("[Ee]xception")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   379
                || outputAnalyzer.getOutput().matches(Test.ERROR + " ?")) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   380
            System.out.println(outputAnalyzer.getOutput());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   381
            throw new Exception("error generating a key pair: " + arguments);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   382
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   383
    }
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
    // 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
   386
    // 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
   387
    // 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
   388
    // 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
   389
    // 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
   390
    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
   391
        CALENDAR.setTime(new Date());
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   392
        if (DELAY_VERIFY || expiredCert) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   393
            // corresponds to '-validity 1'
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   394
            CALENDAR.add(Calendar.DAY_OF_MONTH, -1);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   395
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   396
        if (DELAY_VERIFY && !expiredCert) {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   397
            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
   398
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   399
        Date startDate = CALENDAR.getTime();
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   400
        if (!expiredCert) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   401
            lastCertStartTime = startDate.getTime();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   402
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   403
        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
   404
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   405
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   406
    private static String outfile() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   407
        return System.getProperty("o");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   408
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   409
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   410
    // Retrieves JDK info from the file which is specified by property
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   411
    // jdkListFile, or from property jdkList if jdkListFile is not available.
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   412
    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
   413
        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
   414
        if (jdkList.length == 0) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   415
            jdkList = new String[] { "TEST_JDK" };
46156
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   418
        List<JdkInfo> jdkInfoList = new ArrayList<>();
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   419
        int index = 0;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   420
        for (String jdkPath : jdkList) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   421
            JdkInfo jdkInfo = "TEST_JDK".equalsIgnoreCase(jdkPath) ?
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   422
                    TEST_JDK_INFO : new JdkInfo(jdkPath);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   423
            // 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
   424
            if (!jdkInfoList.contains(jdkInfo)) {
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   425
                jdkInfo.index = index++;
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   426
                jdkInfo.version = String.format(
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   427
                        "%s(%d)", jdkInfo.version, jdkInfo.index);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   428
                jdkInfoList.add(jdkInfo);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   429
            } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   430
                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
   431
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   432
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   433
        return jdkInfoList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   434
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   435
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   436
    private static List<String> keyAlgs() throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   437
        if (KEY_ALGORITHMS == null) KEY_ALGORITHMS = list("keyAlgs");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   438
        if (KEY_ALGORITHMS.length == 0)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   439
            return Arrays.asList(DEFAULT_KEY_ALGORITHMS);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   440
        return Arrays.stream(KEY_ALGORITHMS).map(a -> a.split(";")[0])
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   441
                .collect(Collectors.toList());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   442
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   443
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   444
    // Return key sizes according to the specified key algorithm.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   445
    private static int[] keySizes(String keyAlgorithm) throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   446
        if (KEY_ALGORITHMS == null) KEY_ALGORITHMS = list("keyAlgs");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   447
        for (String keyAlg : KEY_ALGORITHMS) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   448
            String[] split = (keyAlg + " ").split(";");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   449
            if (keyAlgorithm.equals(split[0].trim()) && split.length > 1) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   450
                int sizes[] = new int[split.length - 1];
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   451
                for (int i = 1; i <= sizes.length; i++)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   452
                    sizes[i - 1] = split[i].isBlank() ? 0 : // default
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   453
                        Integer.parseInt(split[i].trim());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   454
                return sizes;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   455
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   456
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   457
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   458
        // defaults
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   459
        if (RSA.equals(keyAlgorithm) || DSA.equals(keyAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   460
            return new int[] { 1024, 2048, 0 }; // 0 is no keysize specified
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   461
        } else if (EC.equals(keyAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   462
            return new int[] { 384, 571, 0 }; // 0 is no keysize specified
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   463
        } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   464
            throw new RuntimeException("problem determining key sizes");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   465
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   466
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   467
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   468
    private static List<String> digestAlgs() throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   469
        if (DIGEST_ALGORITHMS == null) DIGEST_ALGORITHMS = list("digestAlgs");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   470
        if (DIGEST_ALGORITHMS.length == 0)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   471
            return Arrays.asList(DEFAULT_DIGEST_ALGORITHMS);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   472
        return Arrays.asList(DIGEST_ALGORITHMS);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   473
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   474
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   475
    // 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
   476
    // 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
   477
    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
   478
        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
   479
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   480
        List<TsaInfo> tsaInfoList = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   481
        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
   482
            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
   483
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   484
            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
   485
            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
   486
                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
   487
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   488
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   489
            String tsaUrl = values[0];
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   490
            if (tsaUrl.isEmpty() || tsaUrl.equalsIgnoreCase("notsa")) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   491
                tsaUrl = null;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   492
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   493
            TsaInfo bufTsa = new TsaInfo(i, tsaUrl);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   494
            for (String digest : digests) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   495
                bufTsa.addDigest(digest.toUpperCase());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   496
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   497
            tsaInfoList.add(bufTsa);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   498
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   499
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   500
        if (tsaInfoList.size() == 0) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   501
            throw new RuntimeException("TSA service is mandatory unless "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   502
                    + "'notsa' specified explicitly.");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   503
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   504
        return tsaInfoList;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   505
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   506
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   507
    private static String[] list(String listProp) throws IOException {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   508
        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
   509
        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
   510
        if (!isEmpty(listFile)) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   511
            System.out.println(listFileProp + "=" + listFile);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   512
            List<String> list = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   513
            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
   514
                    new FileReader(listFile));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   515
            String line;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   516
            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
   517
                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
   518
                if (!item.isEmpty()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   519
                    list.add(item);
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
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   522
            reader.close();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   523
            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
   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
        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
   527
        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
   528
        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
   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
    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
   532
        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
   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
    // 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
   536
    // 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
   537
    // jars respectively.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   538
    private static List<SignItem> test(List<JdkInfo> jdkInfoList,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   539
            List<TsaInfo> tsaInfoList, List<CertInfo> certList,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   540
            List<SignItem> jars) throws Throwable {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   541
        detailsOutput.transferPhase();
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   542
        List<SignItem> signItems = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   543
        signItems.addAll(signing(jdkInfoList, tsaInfoList, certList, jars));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   544
        if (TEST_JAR_UPDATE) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   545
            signItems.addAll(signing(jdkInfoList, tsaInfoList, certList,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   546
                    updating(signItems.stream().filter(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   547
                            x -> x.status != Status.ERROR)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   548
                    .collect(Collectors.toList()))));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   549
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   550
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   551
        detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   552
        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
   553
            for (JdkInfo verifierInfo : jdkInfoList) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   554
                if (!verifierInfo.supportsKeyAlg(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   555
                        signItem.certInfo.keyAlgorithm)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   556
                VerifyItem verifyItem = VerifyItem.build(verifierInfo);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   557
                verifyItem.addSignerCertInfos(signItem);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   558
                signItem.addVerifyItem(verifyItem);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   559
                verifying(signItem, verifyItem);
46156
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
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   562
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   563
        // if lastCertExpirationTime passed already now, probably some
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   564
        // certificate was already expired during jar signature verification
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   565
        // (jarsigner -verify) and the test should probably be repeated with an
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   566
        // increased validity period -DcertValidity CERT_VALIDITY
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   567
        long lastCertExpirationTime = lastCertStartTime + 24 * 60 * 60 * 1000;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   568
        if (lastCertExpirationTime < System.currentTimeMillis()) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   569
            throw new AssertionError("CERT_VALIDITY (" + CERT_VALIDITY
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   570
                    + " [minutes]) was too short. "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   571
                    + "Creating and signing the jars took longer, "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   572
                    + "presumably at least "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   573
                    + ((lastCertExpirationTime - System.currentTimeMillis())
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   574
                            / 60 * 1000 + CERT_VALIDITY) + " [minutes].");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   575
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   576
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   577
        if (DELAY_VERIFY) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   578
            detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   579
            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
   580
            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
   581
                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
   582
                System.out.print(".");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   583
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   584
            System.out.println();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   585
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   586
            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
   587
            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
   588
                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
   589
                    verifying(signItem, verifyItem);
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
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   593
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   594
        detailsOutput.transferPhase();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   595
        return signItems;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   596
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   597
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   598
    private static List<SignItem> signing(List<JdkInfo> jdkInfos,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   599
            List<TsaInfo> tsaList, List<CertInfo> certList,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   600
            List<SignItem> unsignedJars) throws Throwable {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   601
        List<SignItem> signItems = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   602
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   603
        for (CertInfo certInfo : certList) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   604
            JdkInfo signerInfo = certInfo.jdkInfo;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   605
            String keyAlgorithm = certInfo.keyAlgorithm;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   606
            String sigDigestAlgorithm = certInfo.digestAlgorithm;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   607
            int keySize = certInfo.keySize;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   608
            boolean expired = certInfo.expired;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   609
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   610
            for (String jarDigestAlgorithm : digestAlgs()) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   611
                if (DEFAULT.equals(jarDigestAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   612
                    jarDigestAlgorithm = null;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   613
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   614
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   615
                for (TsaInfo tsaInfo : tsaList) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   616
                    String tsaUrl = tsaInfo.tsaUrl;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   617
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   618
                    List<String> tsaDigestAlgs = digestAlgs();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   619
                    // no point in specifying a tsa digest algorithm
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   620
                    // for no TSA, except maybe it would issue a warning.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   621
                    if (tsaUrl == null) tsaDigestAlgs = Arrays.asList(DEFAULT);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   622
                    // If the JDK doesn't support option -tsadigestalg, the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   623
                    // associated cases can just be ignored.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   624
                    if (!signerInfo.supportsTsadigestalg) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   625
                        tsaDigestAlgs = Arrays.asList(DEFAULT);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   626
                    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   627
                    for (String tsaDigestAlg : tsaDigestAlgs) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   628
                        if (DEFAULT.equals(tsaDigestAlg)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   629
                            tsaDigestAlg = null;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   630
                        } else if (!tsaInfo.isDigestSupported(tsaDigestAlg)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   631
                            // It has to ignore the digest algorithm, which
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   632
                            // is not supported by the TSA server.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   633
                            continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   634
                        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   635
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   636
                        if (tsaUrl != null && TsaFilter.filter(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   637
                                signerInfo.version,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   638
                                tsaDigestAlg,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   639
                                expired,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   640
                                tsaInfo.index)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   641
                            continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   642
                        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   643
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   644
                        for (SignItem prevSign : unsignedJars) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   645
                            String unsignedJar = prevSign.signedJar;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   646
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   647
                            SignItem signItem = SignItem.build(prevSign)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   648
                                    .certInfo(certInfo)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   649
                                    .jdkInfo(signerInfo);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   650
                            String signedJar = unsignedJar + "-" + "JDK_" + (
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   651
                                    signerInfo.version + "-CERT_" + certInfo).
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   652
                                    replaceAll("[^a-z_0-9A-Z.]+", "-");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   653
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   654
                            if (jarDigestAlgorithm != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   655
                                signedJar += "-DIGESTALG_" + jarDigestAlgorithm;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   656
                                signItem.digestAlgorithm(jarDigestAlgorithm);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   657
                            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   658
                            if (tsaUrl == null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   659
                                signItem.tsaIndex(-1);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   660
                            } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   661
                                signedJar += "-TSA_" + tsaInfo.index;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   662
                                signItem.tsaIndex(tsaInfo.index);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   663
                                if (tsaDigestAlg != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   664
                                    signedJar += "-TSADIGALG_" + tsaDigestAlg;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   665
                                    signItem.tsaDigestAlgorithm(tsaDigestAlg);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   666
                                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   667
                            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   668
                            signItem.signedJar(signedJar);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   669
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   670
                            String signingId = signingId(signItem);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   671
                            detailsOutput.writeAnchorName(signingId,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   672
                                    "Signing: " + signingId);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   673
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   674
                            OutputAnalyzer signOA = signJar(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   675
                                    signerInfo.jarsignerPath,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   676
                                    certInfo.sigalg(),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   677
                                    jarDigestAlgorithm,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   678
                                    tsaDigestAlg,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   679
                                    tsaUrl,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   680
                                    certInfo.alias(),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   681
                                    unsignedJar,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   682
                                    signedJar);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   683
                            Status signingStatus = signingStatus(signOA,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   684
                                    tsaUrl != null);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   685
                            signItem.status(signingStatus);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   686
                            signItems.add(signItem);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   687
                        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   688
                    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   689
                }
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
        }
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
        return signItems;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   694
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   695
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   696
    private static List<SignItem> updating(List<SignItem> prevSignItems)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   697
            throws IOException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   698
        List<SignItem> updateItems = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   699
        for (SignItem prevSign : prevSignItems) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   700
            updateItems.addAll(updateJar(prevSign));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   701
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   702
        return updateItems;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   703
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   704
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   705
    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
   706
            throws Throwable {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   707
        // TODO: how will be ensured that the first verification is not after valid period expired which is only one minute?
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   708
        boolean delayVerify = verifyItem.status != Status.NONE;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   709
        String verifyingId = verifyingId(signItem, verifyItem, delayVerify);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   710
        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
   711
        OutputAnalyzer verifyOA = verifyJar(verifyItem.jdkInfo.jarsignerPath,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   712
                signItem.signedJar, verifyItem.certInfo == null ? null :
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   713
                verifyItem.certInfo.alias());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   714
        Status verifyingStatus = verifyingStatus(signItem, verifyItem, verifyOA);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   715
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   716
        try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   717
            String match = "^  ("
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   718
                    + "  Signature algorithm: " + signItem.certInfo.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   719
                            expectedSigalg() + ", " + signItem.certInfo.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   720
                            expectedKeySize() + "-bit key"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   721
                    + ")|("
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   722
                    + "  Digest algorithm: " + signItem.expectedDigestAlg()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   723
                    + (signItem.tsaIndex < 0 ? "" :
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   724
                      ")|("
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   725
                    + "Timestamped by \".+\" on .*"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   726
                    + ")|("
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   727
                    + "  Timestamp digest algorithm: "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   728
                            + signItem.expectedTsaDigestAlg()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   729
                    + ")|("
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   730
                    + "  Timestamp signature algorithm: .*"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   731
                      )
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   732
                    + ")$";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   733
            verifyOA.stdoutShouldMatchByLine(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   734
                    "^- Signed by \"CN=" +  signItem.certInfo.toString()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   735
                            .replaceAll("[.]", "[.]") + "\"$",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   736
                    "^(- Signed by \"CN=.+\")?$",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   737
                    match);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   738
        } catch (Throwable e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   739
            e.printStackTrace();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   740
            verifyingStatus = Status.ERROR;
46156
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   743
        if (!delayVerify) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   744
            verifyItem.status(verifyingStatus);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   745
        } else {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   746
            verifyItem.delayStatus(verifyingStatus);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   747
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   748
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   749
        if (verifyItem.prevVerify != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   750
            verifying(signItem, verifyItem.prevVerify);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   751
        }
46156
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
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   754
    // Determines the status of signing.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   755
    private static Status signingStatus(OutputAnalyzer outputAnalyzer,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   756
            boolean tsa) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   757
        if (outputAnalyzer.getExitValue() != 0) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   758
            return Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   759
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   760
        if (!outputAnalyzer.getOutput().contains(Test.JAR_SIGNED)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   761
            return Status.ERROR;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   762
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   763
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   764
        boolean warning = false;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   765
        for (String line : outputAnalyzer.getOutput().lines()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   766
                .toArray(String[]::new)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   767
            if (line.matches(Test.ERROR + " ?")) return Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   768
            if (line.matches(Test.WARNING + " ?")) warning = true;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   769
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   770
        return warning ? Status.WARNING : Status.NORMAL;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   771
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   772
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   773
    // Determines the status of verifying.
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   774
    private static Status verifyingStatus(SignItem signItem, VerifyItem
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   775
            verifyItem, OutputAnalyzer outputAnalyzer) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   776
        List<String> expectedSignedContent = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   777
        if (verifyItem.certInfo == null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   778
            expectedSignedContent.addAll(signItem.jarContents);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   779
        } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   780
            SignItem i = signItem;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   781
            while (i != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   782
                if (i.certInfo != null && i.certInfo.equals(verifyItem.certInfo)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   783
                    expectedSignedContent.addAll(i.jarContents);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   784
                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   785
                i = i.prevSign;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   786
            }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   787
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   788
        List<String> expectedUnsignedContent =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   789
                new ArrayList<>(signItem.jarContents);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   790
        expectedUnsignedContent.removeAll(expectedSignedContent);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   791
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   792
        int expectedExitCode = !STRICT || expectedUnsignedContent.isEmpty() ? 0 : 32;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   793
        if (outputAnalyzer.getExitValue() != expectedExitCode) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   794
            System.out.println("verifyingStatus: error: exit code != " + expectedExitCode + ": " + outputAnalyzer.getExitValue() + " != " + expectedExitCode);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   795
            return Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   796
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   797
        String expectedSuccessMessage = expectedUnsignedContent.isEmpty() ?
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   798
                Test.JAR_VERIFIED : Test.JAR_VERIFIED_WITH_SIGNER_ERRORS;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   799
        if (!outputAnalyzer.getOutput().contains(expectedSuccessMessage)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   800
            System.out.println("verifyingStatus: error: expectedSuccessMessage not found: " + expectedSuccessMessage);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   801
            return Status.ERROR;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   802
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   803
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   804
        boolean tsa = signItem.tsaIndex >= 0;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   805
        boolean warning = false;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   806
        for (String line : outputAnalyzer.getOutput().lines()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   807
                .toArray(String[]::new)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   808
            if (line.isBlank()) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   809
            if (Test.JAR_VERIFIED.equals(line)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   810
            if (line.matches(Test.ERROR + " ?") && expectedExitCode == 0) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   811
                System.out.println("verifyingStatus: error: line.matches(" + Test.ERROR + "\" ?\"): " + line);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   812
                return Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   813
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   814
            if (line.matches(Test.WARNING + " ?")) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   815
                warning = true;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   816
                continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   817
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   818
            if (!warning) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   819
            line = line.strip();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   820
            if (Test.NOT_YET_VALID_CERT_SIGNING_WARNING.equals(line)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   821
            if (Test.HAS_EXPIRING_CERT_SIGNING_WARNING.equals(line)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   822
            if (Test.HAS_EXPIRING_CERT_VERIFYING_WARNING.equals(line)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   823
            if (line.matches("^" + Test.NO_TIMESTAMP_SIGNING_WARN_TEMPLATE
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   824
                    .replaceAll(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   825
                        "\\(%1\\$tY-%1\\$tm-%1\\$td\\)", "\\\\([^\\\\)]+\\\\)"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   826
                        + "( or after any future revocation date)?")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   827
                    .replaceAll("[.]", "[.]") + "$") && !tsa) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   828
            if (line.matches("^" + Test.NO_TIMESTAMP_VERIFYING_WARN_TEMPLATE
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   829
                    .replaceAll("\\(as early as %1\\$tY-%1\\$tm-%1\\$td\\)",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   830
                        "\\\\([^\\\\)]+\\\\)"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   831
                        + "( or after any future revocation date)?")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   832
                    .replaceAll("[.]", "[.]") + "$") && !tsa) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   833
            if (line.matches("^This jar contains signatures that do(es)? not "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   834
                    + "include a timestamp[.] Without a timestamp, users may "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   835
                    + "not be able to validate this jar after the signer "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   836
                    + "certificate's expiration date \\([^\\)]+\\) or after "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   837
                    + "any future revocation date[.]") && !tsa) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   838
            if (Test.CERTIFICATE_SELF_SIGNED.equals(line)) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   839
            if (Test.HAS_EXPIRED_CERT_VERIFYING_WARNING.equals(line)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   840
                    && signItem.certInfo.expired) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   841
            System.out.println("verifyingStatus: unexpected line: " + line);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   842
            return Status.ERROR; // treat unexpected warnings as error
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   843
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   844
        return warning ? Status.WARNING : Status.NORMAL;
46156
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   847
    // 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
   848
    // algorithms.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   849
    private static OutputAnalyzer signJar(String jarsignerPath, String sigalg,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   850
            String jarDigestAlgorithm,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   851
            String tsadigestalg, String tsa, String alias, String unsignedJar,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   852
            String signedJar) throws Throwable {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   853
        List<String> arguments = new ArrayList<>();
46156
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
        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
   856
            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
   857
            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
   858
            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
   859
            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
   860
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   861
        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
   862
        arguments.add("-debug");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   863
        arguments.add("-verbose");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   864
        if (jarDigestAlgorithm != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   865
            arguments.add("-digestalg");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   866
            arguments.add(jarDigestAlgorithm);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   867
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   868
        if (sigalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   869
            arguments.add("-sigalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   870
            arguments.add(sigalg);
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
        if (tsa != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   873
            arguments.add("-tsa");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   874
            arguments.add(tsa);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   875
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   876
        if (tsadigestalg != null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   877
            arguments.add("-tsadigestalg");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   878
            arguments.add(tsadigestalg);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   879
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   880
        arguments.add("-keystore");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   881
        arguments.add(KEYSTORE);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   882
        arguments.add("-storepass");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   883
        arguments.add(PASSWORD);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   884
        arguments.add("-sigfile");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   885
        arguments.add(nextSigfileName(alias, unsignedJar, signedJar));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   886
        arguments.add("-signedjar");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   887
        arguments.add(signedJar + ".jar");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   888
        arguments.add(unsignedJar + ".jar");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   889
        arguments.add(alias);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   890
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   891
        OutputAnalyzer outputAnalyzer = execTool(jarsignerPath,
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   892
                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
   893
        return outputAnalyzer;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   894
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   895
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   896
    // 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
   897
    private static OutputAnalyzer verifyJar(String jarsignerPath,
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   898
            String signedJar, String alias) throws Throwable {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   899
        List<String> arguments = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   900
        arguments.add("-J-Djava.security.properties=" + JAVA_SECURITY);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   901
        arguments.add("-debug");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   902
        arguments.add("-verbose");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   903
        arguments.add("-certs");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   904
        arguments.add("-keystore");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   905
        arguments.add(KEYSTORE);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   906
        arguments.add("-verify");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   907
        if (STRICT) arguments.add("-strict");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   908
        arguments.add(signedJar + ".jar");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   909
        if (alias != null) arguments.add(alias);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   910
        OutputAnalyzer outputAnalyzer = execTool(jarsignerPath,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   911
                arguments.toArray(new String[arguments.size()]));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   912
        return outputAnalyzer;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   913
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   914
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   915
    // Generates the test result report.
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   916
    private static boolean generateReport(List<JdkInfo> jdkList, List<TsaInfo> tsaList,
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   917
            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
   918
        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
   919
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   920
        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
   921
        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
   922
        report.append(HtmlHelper.startPre());
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   923
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   924
        // Generates JDK list
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   925
        report.append("JDK list:\n");
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   926
        for(JdkInfo jdkInfo : jdkList) {
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   927
            report.append(String.format("%d=%s%n",
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   928
                    jdkInfo.index,
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   929
                    jdkInfo.runtimeVersion));
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   930
        }
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
   931
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   932
        // Generates TSA URLs
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   933
        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
   934
        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
   935
            report.append(
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   936
                    String.format("%d=%s%n", tsaInfo.index,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   937
                            tsaInfo.tsaUrl == null ? "notsa" : tsaInfo.tsaUrl));
46156
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
        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
   940
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   941
        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
   942
        // Generates report headers.
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   943
        List<String> headers = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   944
        headers.add("[Jarfile]");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   945
        headers.add("[Signing Certificate]");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   946
        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
   947
        headers.add("[Signature Algorithm]");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   948
        headers.add("[Jar Digest Algorithm]");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   949
        headers.add("[TSA Digest Algorithm]");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   950
        headers.add("[TSA]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   951
        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
   952
        headers.add("[Verifier JDK]");
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   953
        headers.add("[Verifying Certificate]");
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   954
        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
   955
        if (DELAY_VERIFY) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   956
            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
   957
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   958
        headers.add("[Failed]");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   959
        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
   960
                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
   961
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   962
        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
   963
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   964
        boolean failed = signItems.isEmpty();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   965
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   966
        // Generates report rows.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   967
        for (SignItem signItem : signItems) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
   968
            failed = failed || signItem.verifyItems.isEmpty();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   969
            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
   970
                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
   971
                report.append(reportRow);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   972
                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
   973
                if (isFailedCase) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   974
                    failedReport.append(reportRow);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   975
                }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   976
                failed = failed || isFailedCase;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   977
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   978
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   979
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   980
        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
   981
        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
   982
        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
   983
        if (failed) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   984
            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
   985
            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
   986
            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
   987
            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
   988
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   989
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   990
        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
   991
        return failed;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   992
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   993
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   994
    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
   995
            throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   996
        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
   997
        writer.write(content);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   998
        writer.close();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
   999
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1000
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1001
    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
  1002
        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
  1003
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1004
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1005
    // 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
  1006
    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
  1007
            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
  1008
        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
  1009
        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
  1010
        cmd[1] = "-cp";
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1011
        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
  1012
        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
  1013
        cmd[4] = method;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1014
        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
  1015
        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
  1016
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1017
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1018
    // 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
  1019
    // 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
  1020
    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
  1021
            throws Throwable {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1022
        long start = System.currentTimeMillis();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1023
        try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1024
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1025
            String[] cmd = new String[args.length + 4];
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1026
            cmd[0] = toolPath;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1027
            cmd[1] = "-J-Duser.language=en";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1028
            cmd[2] = "-J-Duser.country=US";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1029
            cmd[3] = "-J-Djava.security.egd=file:/dev/./urandom";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1030
            System.arraycopy(args, 0, cmd, 4, args.length);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1031
            return ProcessTools.executeCommand(cmd);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1032
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1033
        } finally {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1034
            long end = System.currentTimeMillis();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1035
            System.out.println("child process duration [ms]: " + (end - start));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1036
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1037
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1038
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1039
    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
  1040
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1041
        private int index;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1042
        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
  1043
        private final String jarsignerPath;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1044
        private final String runtimeVersion;
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1045
        private String version;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1046
        private final int majorVersion;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1047
        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
  1048
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1049
        private Map<String, Boolean> sigalgMap = new HashMap<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1050
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1051
        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
  1052
            this.jdkPath = jdkPath;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1053
            jarsignerPath = jarsignerPath(jdkPath);
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1054
            runtimeVersion = execJdkUtils(jdkPath, JdkUtils.M_JAVA_RUNTIME_VERSION);
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1055
            if (runtimeVersion == null || runtimeVersion.isBlank()) {
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1056
                throw new RuntimeException(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1057
                        "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
  1058
            }
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1059
            version = execJdkUtils(jdkPath, JdkUtils.M_JAVA_VERSION);
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1060
            majorVersion = Integer.parseInt((runtimeVersion.matches("^1[.].*") ?
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1061
                    runtimeVersion.substring(2) : runtimeVersion).replaceAll("[^0-9].*$", ""));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1062
            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
  1063
                    .getOutput().contains("-tsadigestalg");
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1066
        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
  1067
            if (!sigalgMap.containsKey(sigalg)) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1068
                boolean isSupported = Boolean.parseBoolean(
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1069
                        execJdkUtils(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1070
                                jdkPath,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1071
                                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
  1072
                                sigalg));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1073
                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
  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
            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
  1077
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1078
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1079
        private boolean isAtLeastMajorVersion(int minVersion) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1080
            return majorVersion >= minVersion;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1081
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1082
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1083
        private boolean supportsKeyAlg(String keyAlgorithm) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1084
            // JDK 6 doesn't support EC
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1085
            return isAtLeastMajorVersion(6) || !EC.equals(keyAlgorithm);
46156
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1088
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1089
        public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1090
            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
  1091
            int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1092
            result = prime * result
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1093
                    + ((runtimeVersion == null) ? 0 : runtimeVersion.hashCode());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1094
            return result;
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
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1098
        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
  1099
            if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1100
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1101
            if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1102
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1103
            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
  1104
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1105
            JdkInfo other = (JdkInfo) obj;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1106
            if (runtimeVersion == null) {
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1107
                if (other.runtimeVersion != null)
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1108
                    return false;
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1109
            } else if (!runtimeVersion.equals(other.runtimeVersion))
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1110
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1111
            return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1112
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1113
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1114
        @Override
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1115
        public String toString() {
57581
57a391a23f7f 8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
jjiang
parents: 57488
diff changeset
  1116
            return "JdkInfo[" + runtimeVersion + ", " + jdkPath + "]";
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1117
        }
46156
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1120
    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
  1121
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1122
        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
  1123
        private final String tsaUrl;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1124
        private Set<String> digestList = new HashSet<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1125
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1126
        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
  1127
            this.index = index;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1128
            this.tsaUrl = tsa;
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1131
        private void addDigest(String digest) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1132
            digestList.add(digest);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1133
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1134
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1135
        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
  1136
            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
  1137
                    || digestList.contains(digest);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1138
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1139
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1140
        @Override
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1141
        public String toString() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1142
            return "TsaInfo[" + index + ", " + tsaUrl + "]";
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1143
        }
46156
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
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1146
    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
  1147
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1148
        private static int certCounter;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1149
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1150
        // nr distinguishes cert CNs in jarsigner -verify output
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1151
        private final int nr = ++certCounter;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1152
        private final JdkInfo jdkInfo;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1153
        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
  1154
        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
  1155
        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
  1156
        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
  1157
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1158
        private CertInfo(JdkInfo jdkInfo, String keyAlgorithm,
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1159
                String digestAlgorithm, int keySize, boolean expired) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1160
            this.jdkInfo = jdkInfo;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1161
            this.keyAlgorithm = keyAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1162
            this.digestAlgorithm = digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1163
            this.keySize = keySize;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1164
            this.expired = expired;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1165
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1166
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1167
        private String sigalg() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1168
            return DEFAULT.equals(digestAlgorithm) ? null : expectedSigalg();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1169
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1170
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1171
        private String expectedSigalg() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1172
            return (DEFAULT.equals(this.digestAlgorithm) ? this.digestAlgorithm
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1173
                    : "SHA-256").replace("-", "") + "with" +
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1174
                    keyAlgorithm + (EC.equals(keyAlgorithm) ? "DSA" : "");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1175
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1176
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1177
        private int expectedKeySize() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1178
            if (keySize != 0) return keySize;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1179
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1180
            // defaults
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1181
            if (RSA.equals(keyAlgorithm) || DSA.equals(keyAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1182
                return 2048;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1183
            } else if (EC.equals(keyAlgorithm)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1184
                return 256;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1185
            } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1186
                throw new RuntimeException("problem determining key size");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1187
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1188
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1189
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1190
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1191
        public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1192
            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
  1193
            int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1194
            result = prime * result
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1195
                    + (digestAlgorithm == null ? 0 : digestAlgorithm.hashCode());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1196
            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
  1197
            result = prime * result
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1198
                    + (jdkInfo == null ? 0 : jdkInfo.hashCode());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1199
            result = prime * result
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1200
                    + (keyAlgorithm == null ? 0 : keyAlgorithm.hashCode());
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1201
            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
  1202
            return result;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1203
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1204
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1205
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1206
        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
  1207
            if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1208
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1209
            if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1210
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1211
            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
  1212
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1213
            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
  1214
            if (digestAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1215
                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
  1216
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1217
            } 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
  1218
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1219
            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
  1220
                return false;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1221
            if (jdkInfo == null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1222
                if (other.jdkInfo != null)
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1223
                    return false;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1224
            } else if (!jdkInfo.equals(other.jdkInfo))
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1225
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1226
            if (keyAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1227
                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
  1228
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1229
            } 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
  1230
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1231
            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
  1232
                return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1233
            return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1234
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1235
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1236
        private String alias() {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1237
            return (jdkInfo.version + "_" + toString())
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1238
                    // lower case for jks due to
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1239
                    // sun.security.provider.JavaKeyStore.JDK.convertAlias
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1240
                    .toLowerCase(Locale.ENGLISH);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1241
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1242
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1243
        @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1244
        public String toString() {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1245
            return "nr" + nr + "_"
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1246
                    + keyAlgorithm + "_" + digestAlgorithm
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1247
                    + (keySize == 0 ? "" : "_" + keySize)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1248
                    + (expired ? "_Expired" : "");
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1249
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1250
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1251
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1252
    // 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
  1253
    // 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
  1254
    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
  1255
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1256
        private static final Set<Condition> SET = new HashSet<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1257
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1258
        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
  1259
                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
  1260
            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
  1261
                    expiredCert, tsaIndex));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1262
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1263
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1264
        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
  1265
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1266
            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
  1267
            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
  1268
            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
  1269
            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
  1270
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1271
            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
  1272
                    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
  1273
                this.signerVersion = signerVersion;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1274
                this.digestAlgorithm = digestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1275
                this.expiredCert = expiredCert;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1276
                this.tsaIndex = tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1277
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1278
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1279
            @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1280
            public int hashCode() {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1281
                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
  1282
                int result = 1;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1283
                result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1284
                        + ((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
  1285
                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
  1286
                result = prime * result
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1287
                        + ((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
  1288
                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
  1289
                return result;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1290
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1291
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1292
            @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1293
            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
  1294
                if (this == obj)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1295
                    return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1296
                if (obj == null)
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1297
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1298
                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
  1299
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1300
                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
  1301
                if (digestAlgorithm == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1302
                    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
  1303
                        return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1304
                } 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
  1305
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1306
                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
  1307
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1308
                if (signerVersion == null) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1309
                    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
  1310
                        return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1311
                } 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
  1312
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1313
                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
  1314
                    return false;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1315
                return true;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1316
            }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1317
        }}
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1318
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1319
    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
  1320
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1321
        // 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
  1322
        NONE,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1323
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1324
        // 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
  1325
        ERROR,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1326
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1327
        // 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
  1328
        WARNING,
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1329
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1330
        // 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
  1331
        NORMAL
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1332
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1333
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1334
    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
  1335
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1336
        private SignItem prevSign;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1337
        private CertInfo certInfo;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1338
        private JdkInfo jdkInfo;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1339
        private String digestAlgorithm;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1340
        private String tsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1341
        private int tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1342
        private Status status;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1343
        private String unsignedJar;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1344
        private String signedJar;
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1345
        private List<String> jarContents = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1346
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1347
        private List<VerifyItem> verifyItems = new ArrayList<>();
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1348
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1349
        private static SignItem build() {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1350
            return new SignItem()
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1351
                    .addContentFiles(Arrays.asList("META-INF/MANIFEST.MF"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1352
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1353
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1354
        private static SignItem build(SignItem prevSign) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1355
            return build().prevSign(prevSign).unsignedJar(prevSign.signedJar)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1356
                    .addContentFiles(prevSign.jarContents);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1357
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1358
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1359
        private SignItem prevSign(SignItem prevSign) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1360
            this.prevSign = prevSign;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1361
            return this;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1362
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1363
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1364
        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
  1365
            this.certInfo = certInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1366
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1367
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1368
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1369
        private SignItem jdkInfo(JdkInfo jdkInfo) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1370
            this.jdkInfo = jdkInfo;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1371
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1372
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1373
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1374
        private SignItem digestAlgorithm(String digestAlgorithm) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1375
            this.digestAlgorithm = digestAlgorithm;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1376
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1377
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1378
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1379
        String expectedDigestAlg() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1380
            return digestAlgorithm != null ? digestAlgorithm : "SHA-256";
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1381
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1382
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1383
        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
  1384
            this.tsaDigestAlgorithm = tsaDigestAlgorithm;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1385
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1386
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1387
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1388
        String expectedTsaDigestAlg() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1389
            return tsaDigestAlgorithm != null ? tsaDigestAlgorithm : "SHA-256";
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1390
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1391
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1392
        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
  1393
            this.tsaIndex = tsaIndex;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1394
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1395
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1396
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1397
        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
  1398
            this.status = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1399
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1400
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1401
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1402
        private SignItem unsignedJar(String unsignedJar) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1403
            this.unsignedJar = unsignedJar;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1404
            return this;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1405
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1406
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1407
        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
  1408
            this.signedJar = signedJar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1409
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1410
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1411
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1412
        private SignItem addContentFiles(List<String> files) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1413
            this.jarContents.addAll(files);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1414
            return this;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1415
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1416
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1417
        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
  1418
            verifyItems.add(verifyItem);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1419
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1420
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1421
        private boolean isErrorInclPrev() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1422
            if (prevSign != null && prevSign.isErrorInclPrev()) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1423
                System.out.println("SignItem.isErrorInclPrev: returning true from previous");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1424
                return true;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1425
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1426
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1427
            return status == Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1428
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1429
        private List<String> toStringWithPrev(Function<SignItem,String> toStr) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1430
            List<String> s = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1431
            if (prevSign != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1432
                s.addAll(prevSign.toStringWithPrev(toStr));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1433
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1434
            if (status != null) { // no status means jar creation or update item
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1435
                s.add(toStr.apply(this));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1436
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1437
            return s;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1438
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1439
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1440
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1441
    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
  1442
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1443
        private VerifyItem prevVerify;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1444
        private CertInfo certInfo;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1445
        private JdkInfo jdkInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1446
        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
  1447
        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
  1448
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1449
        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
  1450
            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
  1451
            verifyItem.jdkInfo = jdkInfo;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1452
            return verifyItem;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1453
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1454
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1455
        private VerifyItem certInfo(CertInfo certInfo) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1456
            this.certInfo = certInfo;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1457
            return this;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1458
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1459
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1460
        private void addSignerCertInfos(SignItem signItem) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1461
            VerifyItem prevVerify = this;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1462
            CertInfo lastCertInfo = null;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1463
            while (signItem != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1464
                // (signItem.certInfo == null) means create or update jar step
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1465
                if (signItem.certInfo != null
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1466
                        && !signItem.certInfo.equals(lastCertInfo)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1467
                    lastCertInfo = signItem.certInfo;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1468
                    prevVerify = prevVerify.prevVerify =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1469
                            build(jdkInfo).certInfo(signItem.certInfo);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1470
                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1471
                signItem = signItem.prevSign;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1472
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1473
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1474
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1475
        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
  1476
            this.status = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1477
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1478
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1479
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1480
        private boolean isErrorInclPrev() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1481
            if (prevVerify != null && prevVerify.isErrorInclPrev()) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1482
                System.out.println("VerifyItem.isErrorInclPrev: returning true from previous");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1483
                return true;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1484
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1485
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1486
            return status == Status.ERROR || delayStatus == Status.ERROR;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1487
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1488
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1489
        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
  1490
            this.delayStatus = status;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1491
            return this;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1492
        }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1493
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1494
        private List<String> toStringWithPrev(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1495
                Function<VerifyItem,String> toStr) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1496
            List<String> s = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1497
            if (prevVerify != null) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1498
                s.addAll(prevVerify.toStringWithPrev(toStr));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1499
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1500
            s.add(toStr.apply(this));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1501
            return s;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1502
        }
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1503
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1504
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1505
    // 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
  1506
    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
  1507
        return signItem.signedJar;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1508
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1509
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1510
    // 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
  1511
    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
  1512
            boolean delayVerify) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1513
        return signingId(signItem) + (delayVerify ? "-DV" : "-V")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1514
                + "_" + verifyItem.jdkInfo.version +
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1515
                (verifyItem.certInfo == null ? "" : "_" + verifyItem.certInfo);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1516
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1517
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1518
    private static String reportRow(SignItem signItem, VerifyItem verifyItem) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1519
        List<String> values = new ArrayList<>();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1520
        Consumer<Function<SignItem, String>> s_values_add = f -> {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1521
            values.add(String.join("<br/><br/>", signItem.toStringWithPrev(f)));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1522
        };
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1523
        Consumer<Function<VerifyItem, String>> v_values_add = f -> {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1524
            values.add(String.join("<br/><br/>", verifyItem.toStringWithPrev(f)));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1525
        };
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1526
        s_values_add.accept(i -> i.unsignedJar + " -> " + i.signedJar);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1527
        s_values_add.accept(i -> i.certInfo.toString());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1528
        s_values_add.accept(i -> i.jdkInfo.version);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1529
        s_values_add.accept(i -> i.certInfo.expectedSigalg());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1530
        s_values_add.accept(i ->
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1531
                null2Default(i.digestAlgorithm, i.expectedDigestAlg()));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1532
        s_values_add.accept(i -> i.tsaIndex == -1 ? "" :
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1533
                null2Default(i.tsaDigestAlgorithm, i.expectedTsaDigestAlg()));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1534
        s_values_add.accept(i -> i.tsaIndex == -1 ? "" : i.tsaIndex + "");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1535
        s_values_add.accept(i -> HtmlHelper.anchorLink(
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1536
                PhaseOutputStream.fileName(PhaseOutputStream.Phase.SIGNING),
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1537
                signingId(i),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1538
                "" + i.status));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1539
        values.add(verifyItem.jdkInfo.version);
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1540
        v_values_add.accept(i ->
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1541
                i.certInfo == null ? "no alias" : "" + i.certInfo);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1542
        v_values_add.accept(i -> HtmlHelper.anchorLink(
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1543
                PhaseOutputStream.fileName(PhaseOutputStream.Phase.VERIFYING),
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1544
                verifyingId(signItem, i, false),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1545
                "" + i.status.toString()));
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1546
        if (DELAY_VERIFY) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1547
            v_values_add.accept(i -> HtmlHelper.anchorLink(
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1548
                    PhaseOutputStream.fileName(
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1549
                            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
  1550
                    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
  1551
                    verifyItem.delayStatus.toString()));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1552
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1553
        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
  1554
        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
  1555
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1556
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1557
    private static boolean isFailed(SignItem signItem, VerifyItem verifyItem) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1558
        System.out.println("isFailed: signItem = " + signItem + ", verifyItem = " + verifyItem);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1559
        // TODO: except known failing cases
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1560
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1561
        // Note about isAtLeastMajorVersion in the following conditions:
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1562
        // signItem.jdkInfo is the jdk which signed the jar last and
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1563
        // signItem.prevSign.jdkInfo is the jdk which signed the jar first
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1564
        // assuming only two successive signatures as there actually are now.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1565
        // the first signature always works and always has. subject here is
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1566
        // the update of an already signed jar. the following conditions always
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1567
        // depend on the second jdk that updated the jar with another signature
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1568
        // and the first one (signItem(.prevSign)+.jdkInfo) can be ignored.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1569
        // this is different for verifyItem. verifyItem.prevVerify refers to
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1570
        // the first signature created by signItem(.prevSign)+.jdkInfo.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1571
        // all verifyItem(.prevVerify)+.jdkInfo however point always to the same
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1572
        // jdk, only their certInfo is different. the same signatures are
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1573
        // verified with different jdks in different top-level VerifyItems
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1574
        // attached directly to signItem.verifyItems and not to
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1575
        // verifyItem.prevVerify.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1576
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1577
        // ManifestDigester fails to parse manifests ending in '\r' with
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1578
        // IndexOutOfBoundsException at ManifestDigester.java:87 before 8217375
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1579
        if (signItem.signedJar.startsWith("eofr")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1580
                && !signItem.jdkInfo.isAtLeastMajorVersion(13)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1581
                && !verifyItem.jdkInfo.isAtLeastMajorVersion(13)) return false;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1582
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1583
        // if there is no blank line after main attributes, JarSigner adds
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1584
        // individual sections nevertheless without being properly delimited
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1585
        // in JarSigner.java:777..790 without checking for blank line
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1586
        // before 8217375
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1587
//        if (signItem.signedJar.startsWith("eofn-")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1588
//                && signItem.signedJar.contains("-addfile-")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1589
//                && !signItem.jdkInfo.isAtLeastMajorVersion(13)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1590
//                && !verifyItem.jdkInfo.isAtLeastMajorVersion(13)) return false; // FIXME
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1591
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1592
//        System.out.println("isFailed: signItem.isErrorInclPrev() " + signItem.isErrorInclPrev());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1593
//        System.out.println("isFailed: verifyItem.isErrorInclPrev() " + verifyItem.isErrorInclPrev());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1594
        boolean isFailed = signItem.isErrorInclPrev() || verifyItem.isErrorInclPrev();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1595
        System.out.println("isFailed: returning " + isFailed);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1596
        return isFailed;
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1597
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1598
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1599
    // 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
  1600
    private static String null2Default(String value, String defaultValue) {
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1601
        return value != null ? value :
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1602
               DEFAULT + "(" + (defaultValue == null
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1603
                                  ? "N/A"
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1604
                                  : defaultValue) + ")";
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1605
    }
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 51058
diff changeset
  1606
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
  1607
}