test/jdk/sun/security/tools/jarsigner/compatibility/DetailsOutputStream.java
author weijun
Thu, 18 Jul 2019 08:53:06 +0800
changeset 57488 94691d8e746f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8217375: jarsigner breaks old signature with long lines in manifest Reviewed-by: jjiang, weijun Contributed-by: Philipp Kunz <philipp.kunz@paratix.ch>
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: 47216
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
import java.io.FileNotFoundException;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    25
import java.io.FileOutputStream;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    26
import java.io.IOException;
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    27
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    28
/*
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    29
 * A custom output stream that redirects the testing outputs to a file, called
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    30
 * details.out. It also calls another output stream to save some outputs to
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    31
 * other files.
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    32
 */
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    33
public class DetailsOutputStream extends FileOutputStream {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    34
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    35
    private PhaseOutputStream phaseOutputStream = new PhaseOutputStream();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    36
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 47216
diff changeset
    37
    public DetailsOutputStream(String filename) throws FileNotFoundException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 47216
diff changeset
    38
        super(filename != null && !filename.isEmpty() ? filename :
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents: 47216
diff changeset
    39
            "details.out", true);
46156
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    40
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    41
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    42
    public void transferPhase() throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    43
        if (phaseOutputStream.isCorePhase()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    44
            phaseOutputStream.write(HtmlHelper.endHtml());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    45
            phaseOutputStream.write(HtmlHelper.endPre());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    46
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    47
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    48
        phaseOutputStream.transfer();
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    49
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    50
        if (phaseOutputStream.isCorePhase()) {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    51
            phaseOutputStream.write(HtmlHelper.startHtml());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    52
            phaseOutputStream.write(HtmlHelper.startPre());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    53
        }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    54
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    55
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    56
    @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    57
    public void write(byte[] b) throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    58
        super.write(b);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    59
        phaseOutputStream.write(b);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    60
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    61
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    62
    @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    63
    public void write(int b) throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    64
        super.write(b);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    65
        phaseOutputStream.write(b);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    66
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    67
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    68
    @Override
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    69
    public void write(byte b[], int off, int len) throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    70
        super.write(b, off, len);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    71
        phaseOutputStream.write(b, off, len);
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    72
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    73
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    74
    public void writeAnchorName(String name, String text) throws IOException {
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    75
        super.write((text).getBytes());
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    76
        super.write('\n');
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    77
        phaseOutputStream.write(HtmlHelper.anchorName(name, text));
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    78
        phaseOutputStream.write('\n');
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    79
    }
79e8a865c5b8 8179614: Test for jarsigner on verifying jars that are signed and timestamped by other JDK releases
mli
parents:
diff changeset
    80
}