test/jdk/sun/security/tools/keytool/pss/PSS.java
author weijun
Fri, 21 Jun 2019 23:44:58 +0800
changeset 55468 076f34b82b98
parent 54774 test/jdk/sun/security/tools/keytool/PSS.java@271ee240244c
permissions -rw-r--r--
8225257: sun/security/tools/keytool/PSS.java timed out Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     1
/*
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     4
 *
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     8
 *
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    13
 * accompanied this code).
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    14
 *
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    18
 *
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    21
 * questions.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    22
 */
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    23
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    24
/*
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    25
 * @test
55468
076f34b82b98 8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents: 54774
diff changeset
    26
 * @bug 8215694 8222987 8225257
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    27
 * @summary keytool cannot generate RSASSA-PSS certificates
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    28
 * @library /test/lib
55468
076f34b82b98 8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents: 54774
diff changeset
    29
 * @build java.base/sun.security.rsa.RSAKeyPairGenerator
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    30
 * @modules java.base/sun.security.util
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    31
 *          java.base/sun.security.x509
54774
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    32
 * @requires os.family != "solaris"
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    33
 * @run main PSS
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    34
 */
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    35
54774
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    36
// This test is excluded from Solaris because the 8192-bit RSA key pair
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    37
// generator is extremely slow there.
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    38
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    39
import jdk.test.lib.Asserts;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    40
import jdk.test.lib.SecurityTools;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    42
import jdk.test.lib.security.DerUtils;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    43
import sun.security.util.ObjectIdentifier;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    44
import sun.security.x509.AlgorithmId;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    45
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    46
import java.io.File;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    47
import java.security.KeyStore;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    48
import java.security.cert.X509Certificate;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    49
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    50
public class PSS {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    51
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    53
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    54
        genkeypair("p", "-keyalg RSASSA-PSS -sigalg RSASSA-PSS")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    55
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    56
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    57
        genkeypair("a", "-keyalg RSA -sigalg RSASSA-PSS -keysize 2048")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    58
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    59
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    60
        genkeypair("b", "-keyalg RSA -sigalg RSASSA-PSS -keysize 4096")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    61
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    62
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    63
        genkeypair("c", "-keyalg RSA -sigalg RSASSA-PSS -keysize 8192")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    64
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    65
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    66
        KeyStore ks = KeyStore.getInstance(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    67
                new File("ks"), "changeit".toCharArray());
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    68
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    69
        check((X509Certificate)ks.getCertificate("p"), "RSASSA-PSS",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    70
                AlgorithmId.SHA256_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    71
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    72
        check((X509Certificate)ks.getCertificate("a"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    73
                AlgorithmId.SHA256_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    74
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    75
        check((X509Certificate)ks.getCertificate("b"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    76
                AlgorithmId.SHA384_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    77
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    78
        check((X509Certificate)ks.getCertificate("c"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    79
                AlgorithmId.SHA512_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    80
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    81
        // More commands
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    82
        kt("-certreq -alias p -sigalg RSASSA-PSS -file p.req")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    83
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    84
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    85
        kt("-gencert -alias a -sigalg RSASSA-PSS -infile p.req -outfile p.cert")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    86
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    87
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    88
        kt("-importcert -alias p -file p.cert")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    89
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    90
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    91
        kt("-selfcert -alias p -sigalg RSASSA-PSS")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    92
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    93
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    94
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    95
    static OutputAnalyzer genkeypair(String alias, String options)
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    96
            throws Exception {
55468
076f34b82b98 8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents: 54774
diff changeset
    97
        String patchArg = "-J--patch-module=java.base=" + System.getProperty("test.classes")
076f34b82b98 8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents: 54774
diff changeset
    98
                + File.separator + "patches" + File.separator + "java.base";
076f34b82b98 8225257: sun/security/tools/keytool/PSS.java timed out
weijun
parents: 54774
diff changeset
    99
        return kt(patchArg + " -genkeypair -alias " + alias
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   100
                + " -dname CN=" + alias + " " + options);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   101
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   102
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   103
    static OutputAnalyzer kt(String cmd)
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   104
            throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   105
        return SecurityTools.keytool("-storepass changeit -keypass changeit "
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   106
                + "-keystore ks " + cmd);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   107
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   108
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   109
    static void check(X509Certificate cert, String expectedKeyAlg,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   110
            ObjectIdentifier expectedMdAlg) throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   111
        Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), expectedKeyAlg);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   112
        Asserts.assertEQ(cert.getSigAlgName(), "RSASSA-PSS");
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   113
        DerUtils.checkAlg(cert.getSigAlgParams(), "000", expectedMdAlg);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   114
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   115
}