test/jdk/sun/security/tools/keytool/PSS.java
author weijun
Thu, 09 May 2019 08:49:31 +0800
changeset 54774 271ee240244c
parent 53351 bdb29aa5fd31
permissions -rw-r--r--
8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC Reviewed-by: mullan, xuelei
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
54774
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    26
 * @bug 8215694 8222987
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
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    29
 * @modules java.base/sun.security.util
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    30
 *          java.base/sun.security.x509
54774
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    31
 * @requires os.family != "solaris"
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    32
 * @run main PSS
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    33
 */
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    34
54774
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    35
// 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
    36
// generator is extremely slow there.
271ee240244c 8222987: sun/security/tools/keytool/PSS.java times out on Solaris-SPARC
weijun
parents: 53351
diff changeset
    37
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    38
import jdk.test.lib.Asserts;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    39
import jdk.test.lib.SecurityTools;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    40
import jdk.test.lib.process.OutputAnalyzer;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    41
import jdk.test.lib.security.DerUtils;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    42
import sun.security.util.ObjectIdentifier;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    43
import sun.security.x509.AlgorithmId;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    44
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    45
import java.io.File;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    46
import java.security.KeyStore;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    47
import java.security.cert.X509Certificate;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    48
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    49
public class PSS {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    50
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    51
    public static void main(String[] args) throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    52
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    53
        genkeypair("p", "-keyalg RSASSA-PSS -sigalg RSASSA-PSS")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    54
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    55
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    56
        genkeypair("a", "-keyalg RSA -sigalg RSASSA-PSS -keysize 2048")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    57
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    58
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    59
        genkeypair("b", "-keyalg RSA -sigalg RSASSA-PSS -keysize 4096")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    60
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    61
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    62
        genkeypair("c", "-keyalg RSA -sigalg RSASSA-PSS -keysize 8192")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    63
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    64
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    65
        KeyStore ks = KeyStore.getInstance(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    66
                new File("ks"), "changeit".toCharArray());
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    67
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    68
        check((X509Certificate)ks.getCertificate("p"), "RSASSA-PSS",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    69
                AlgorithmId.SHA256_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    70
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    71
        check((X509Certificate)ks.getCertificate("a"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    72
                AlgorithmId.SHA256_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    73
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    74
        check((X509Certificate)ks.getCertificate("b"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    75
                AlgorithmId.SHA384_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    76
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    77
        check((X509Certificate)ks.getCertificate("c"), "RSA",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    78
                AlgorithmId.SHA512_oid);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    79
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    80
        // More commands
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    81
        kt("-certreq -alias p -sigalg RSASSA-PSS -file p.req")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    82
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    83
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    84
        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
    85
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    86
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    87
        kt("-importcert -alias p -file p.cert")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    88
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    89
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    90
        kt("-selfcert -alias p -sigalg RSASSA-PSS")
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    91
                .shouldHaveExitValue(0);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    92
    }
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
    static OutputAnalyzer genkeypair(String alias, String options)
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    95
            throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    96
        return kt("-genkeypair -alias " + alias
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    97
                + " -dname CN=" + alias + " " + options);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    98
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
    99
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   100
    static OutputAnalyzer kt(String cmd)
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   101
            throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   102
        return SecurityTools.keytool("-storepass changeit -keypass changeit "
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   103
                + "-keystore ks " + cmd);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   104
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   105
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   106
    static void check(X509Certificate cert, String expectedKeyAlg,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   107
            ObjectIdentifier expectedMdAlg) throws Exception {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   108
        Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), expectedKeyAlg);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   109
        Asserts.assertEQ(cert.getSigAlgName(), "RSASSA-PSS");
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   110
        DerUtils.checkAlg(cert.getSigAlgParams(), "000", expectedMdAlg);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   111
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents:
diff changeset
   112
}