test/jdk/sun/security/tools/jarsigner/NewSize7.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 54521 8de62c4af8c7
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54521
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     1
/*
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     4
 *
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     8
 *
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    13
 * accompanied this code).
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    14
 *
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    18
 *
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    21
 * questions.
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    22
 */
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    23
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    24
/*
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    25
 * @test
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    26
 * @bug 6561126
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    27
 * @summary keytool should use larger default keysize for keypairs
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    28
 * @library /test/lib
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    29
 */
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    30
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    31
import jdk.test.lib.Asserts;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    32
import jdk.test.lib.SecurityTools;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    33
import jdk.test.lib.util.JarUtils;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    34
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    35
import java.io.InputStream;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    36
import java.nio.file.Files;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    37
import java.nio.file.Path;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    38
import java.util.jar.JarFile;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    39
import java.util.jar.Manifest;
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    40
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    41
public class NewSize7 {
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    43
        String common = "-storepass changeit -keypass changeit -keystore ks ";
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    44
        SecurityTools.keytool(common
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    45
                + "-keyalg rsa -genkeypair -alias me -dname CN=Me");
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    46
        Files.write(Path.of("ns7.txt"), new byte[0]);
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    47
        JarUtils.createJarFile(Path.of("ns7.jar"), Path.of("."),
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    48
                Path.of("ns7.txt"));
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    49
        SecurityTools.jarsigner(common + "ns7.jar me");
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    50
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    51
        try (JarFile jf = new JarFile("ns7.jar")) {
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    52
            try (InputStream is = jf.getInputStream(
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    53
                    jf.getEntry("META-INF/MANIFEST.MF"))) {
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    54
                Asserts.assertTrue(new Manifest(is).getAttributes("ns7.txt")
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    55
                        .keySet().stream()
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    56
                        .anyMatch(s -> s.toString().contains("SHA-256")));
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    57
            }
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    58
            try (InputStream is = jf.getInputStream(
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    59
                    jf.getEntry("META-INF/ME.SF"))) {
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    60
                Asserts.assertTrue(new Manifest(is).getAttributes("ns7.txt")
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    61
                        .keySet().stream()
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    62
                        .anyMatch(s -> s.toString().contains("SHA-256")));
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    63
            }
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    64
        }
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    65
    }
8de62c4af8c7 8180573: Refactor sun/security/tools shell tests to plain java tests
weijun
parents:
diff changeset
    66
}