test/jdk/sun/security/tools/jarsigner/LineBrokenMultiByteCharacter.java
author weijun
Fri, 15 Nov 2019 09:06:58 +0800
changeset 59104 046e4024e55a
parent 49111 1b33025ae610
permissions -rw-r--r--
8214024: Remove the default keytool -keyalg value Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47273
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     1
/*
59104
046e4024e55a 8214024: Remove the default keytool -keyalg value
weijun
parents: 49111
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47273
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     4
 *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     8
 *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    13
 * accompanied this code).
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    14
 *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    18
 *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    21
 * questions.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    22
 */
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    23
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    24
/*
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    25
 * @test
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    26
 * @bug 6695402
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    27
 * @summary verify signatures of jars containing classes with names
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    28
 *          with multi-byte unicode characters broken across lines
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    29
 * @library /test/lib
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    30
 */
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    31
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    32
import java.io.IOException;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    33
import java.io.InputStream;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    34
import java.nio.file.Files;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    35
import java.nio.file.Paths;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    36
import java.util.jar.JarFile;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    37
import java.util.jar.Attributes.Name;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    38
import java.util.jar.JarEntry;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    39
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    40
import static java.nio.charset.StandardCharsets.UTF_8;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    41
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    42
import jdk.test.lib.SecurityTools;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    43
import jdk.test.lib.util.JarUtils;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    44
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    45
public class LineBrokenMultiByteCharacter {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    46
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    47
    /**
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    48
     * this name will break across lines in MANIFEST.MF at the
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    49
     * middle of a two-byte utf-8 encoded character due to its e acute letter
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    50
     * at its exact position.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    51
     *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    52
     * because no file with such a name exists {@link JarUtils} will add the
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    53
     * name itself as contents to the jar entry which would have contained a
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    54
     * compiled class in the original bug. For this test, the contents of the
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    55
     * files contained in the jar file is not important as long as they get
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    56
     * signed.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    57
     *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    58
     * @see #verifyClassNameLineBroken(JarFile, String)
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    59
     */
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    60
    static final String testClassName =
49111
1b33025ae610 6372077: JarFile.getManifest() should handle manifest attribute name 70 bytes
rriggs
parents: 47273
diff changeset
    61
            "LineBrokenMultiByteCharacterA1234567890B1234567890C123456789D1234\u00E9xyz.class";
47273
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    62
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    63
    static final String anotherName =
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    64
            "LineBrokenMultiByteCharacterA1234567890B1234567890C123456789D1234567890.class";
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    65
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    66
    static final String alias = "a";
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    67
    static final String keystoreFileName = "test.jks";
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    68
    static final String manifestFileName = "MANIFEST.MF";
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    69
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    70
    public static void main(String[] args) throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    71
        prepare();
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    72
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    73
        testSignJar("test.jar");
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    74
        testSignJarNoManifest("test-no-manifest.jar");
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    75
        testSignJarUpdate("test-update.jar", "test-updated.jar");
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    76
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    77
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    78
    static void prepare() throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    79
        SecurityTools.keytool("-keystore", keystoreFileName, "-genkeypair",
59104
046e4024e55a 8214024: Remove the default keytool -keyalg value
weijun
parents: 49111
diff changeset
    80
                "-keyalg", "dsa",
47273
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    81
                "-storepass", "changeit", "-keypass", "changeit", "-storetype",
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    82
                "JKS", "-alias", alias, "-dname", "CN=X", "-validity", "366")
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    83
            .shouldHaveExitValue(0);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    84
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    85
        Files.write(Paths.get(manifestFileName), (Name.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    86
                MANIFEST_VERSION.toString() + ": 1.0\r\n").getBytes(UTF_8));
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    87
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    88
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    89
    static void testSignJar(String jarFileName) throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    90
        JarUtils.createJar(jarFileName, manifestFileName, testClassName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    91
        verifyJarSignature(jarFileName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    92
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    93
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    94
    static void testSignJarNoManifest(String jarFileName) throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    95
        JarUtils.createJar(jarFileName, testClassName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    96
        verifyJarSignature(jarFileName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    97
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    98
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
    99
    static void testSignJarUpdate(
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   100
            String initialFileName, String updatedFileName) throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   101
        JarUtils.createJar(initialFileName, manifestFileName, anotherName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   102
        SecurityTools.jarsigner("-keystore", keystoreFileName, "-storetype",
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   103
                "JKS", "-storepass", "changeit", "-debug", initialFileName,
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   104
                alias).shouldHaveExitValue(0);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   105
        JarUtils.updateJar(initialFileName, updatedFileName, testClassName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   106
        verifyJarSignature(updatedFileName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   107
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   108
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   109
    static void verifyJarSignature(String jarFileName) throws Exception {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   110
        // actually sign the jar
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   111
        SecurityTools.jarsigner("-keystore", keystoreFileName, "-storetype",
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   112
                "JKS", "-storepass", "changeit", "-debug", jarFileName, alias)
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   113
            .shouldHaveExitValue(0);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   114
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   115
        try (
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   116
            JarFile jar = new JarFile(jarFileName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   117
        ) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   118
            verifyClassNameLineBroken(jar, testClassName);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   119
            verifyCodeSigners(jar, jar.getJarEntry(testClassName));
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   120
        }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   121
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   122
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   123
    /**
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   124
     * it would be too easy to miss the actual test case by just renaming an
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   125
     * identifier so that the multi-byte encoded character would not any longer
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   126
     * be broken across a line break.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   127
     *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   128
     * this check here verifies that the actual test case is tested based on
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   129
     * the manifest and not based on the signature file because at the moment,
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   130
     * the signature file does not even contain the desired entry at all.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   131
     *
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   132
     * this relies on {@link java.util.jar.Manifest} breaking lines unaware
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   133
     * of bytes that belong to the same multi-byte utf characters.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   134
     */
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   135
    static void verifyClassNameLineBroken(JarFile jar, String className)
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   136
            throws IOException {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   137
        byte[] eAcute = "\u00E9".getBytes(UTF_8);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   138
        byte[] eAcuteBroken =
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   139
                new byte[] {eAcute[0], '\r', '\n', ' ', eAcute[1]};
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   140
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   141
        if (jar.getManifest().getAttributes(className) == null) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   142
            throw new AssertionError(className + " not found in manifest");
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   143
        }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   144
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   145
        JarEntry manifestEntry = jar.getJarEntry(JarFile.MANIFEST_NAME);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   146
        try (
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   147
            InputStream manifestIs = jar.getInputStream(manifestEntry);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   148
        ) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   149
            int bytesMatched = 0;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   150
            for (int b = manifestIs.read(); b > -1; b = manifestIs.read()) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   151
                if ((byte) b == eAcuteBroken[bytesMatched]) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   152
                    bytesMatched++;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   153
                    if (bytesMatched == eAcuteBroken.length) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   154
                        break;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   155
                    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   156
                } else {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   157
                    bytesMatched = 0;
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   158
                }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   159
            }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   160
            if (bytesMatched < eAcuteBroken.length) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   161
                throw new AssertionError("self-test failed: multi-byte "
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   162
                        + "utf-8 character not broken across lines");
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   163
            }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   164
        }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   165
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   166
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   167
    static void verifyCodeSigners(JarFile jar, JarEntry jarEntry)
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   168
            throws IOException {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   169
        // codeSigners is initialized only after the entry has been read
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   170
        try (
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   171
            InputStream inputStream = jar.getInputStream(jarEntry);
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   172
        ) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   173
            inputStream.readAllBytes();
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   174
        }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   175
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   176
        // a check for the presence of code signers is sufficient to check
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   177
        // bug JDK-6695402. no need to also verify the actual code signers
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   178
        // attributes here.
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   179
        if (jarEntry.getCodeSigners() == null
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   180
                || jarEntry.getCodeSigners().length == 0) {
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   181
            throw new AssertionError(
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   182
                    "no signing certificate found for " + jarEntry.getName());
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   183
        }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   184
    }
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   185
f60a42d4b8cd 6695402: Jarsigner with multi-byte characters in class names
weijun
parents:
diff changeset
   186
}