test/jdk/sun/security/x509/X509CertImpl/ECSigParamsVerifyWithCert.java
author valeriep
Thu, 11 Jul 2019 20:11:47 +0000
changeset 55667 6521aec1c26e
permissions -rw-r--r--
8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support Summary: Fixed SignatureUtil and ECDSA signature impl to handle EC parameters Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55667
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     1
/*
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     4
 *
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     8
 *
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    13
 * accompanied this code).
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    14
 *
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    18
 *
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    21
 * questions.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    22
 */
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    23
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    24
/*
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    25
 * @test
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    26
 * @bug 8225745
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    27
 * @summary Ensure ECDSA certificates with signature algorithm parameters
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    28
 *          can be verified successfully
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    29
 * @run main ECSigParamsVerifyWithCert
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    30
 */
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    31
import java.io.*;
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    32
import java.security.cert.CertificateFactory;
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    33
import java.security.cert.X509Certificate;
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    34
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    35
public class ECSigParamsVerifyWithCert {
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    36
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    37
    // ECDSA certificate with non-null signature parameters, i.e.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    38
    // Signature Algorithm: SHA256withECDSA, params unparsed,
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    39
    // OID = 1.2.840.10045.4.3.2
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    40
    private static String ecEntityWithSigParamsStr =
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    41
        "-----BEGIN CERTIFICATE-----\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    42
        "MIICXjCCAfmgAwIBAgIIHzREzASpiTowFAYIKoZIzj0EAwIGCCqGSM49AwEHMGAx\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    43
        "IzAhBgNVBAMMGkNvcmRhIE5vZGUgSW50ZXJtZWRpYXRlIENBMQswCQYDVQQKDAJS\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    44
        "MzEOMAwGA1UECwwFY29yZGExDzANBgNVBAcMBkxvbmRvbjELMAkGA1UEBhMCVUsw\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    45
        "HhcNMTgwNjI1MDAwMDAwWhcNMjcwNTIwMDAwMDAwWjAxMQswCQYDVQQGEwJHQjEP\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    46
        "MA0GA1UEBwwGTG9uZG9uMREwDwYDVQQKDAhNZWdhQ29ycDBZMBMGByqGSM49AgEG\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    47
        "CCqGSM49AwEHA0IABG2VjWPPFnGVka3G9++Sz/GPRkAkht4BDoYTlkRz8hpwr4iu\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    48
        "fU6NlReirLOB4LBLZcmp16xm4RYsN5ouTS7Z3wKjgcEwgb4wHQYDVR0OBBYEFBnY\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    49
        "sikYpaSL9U8FUygbqN3sIvMOMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgGG\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    50
        "MCMGA1UdJQQcMBoGCCsGAQUFBwMBBggrBgEFBQcDAgYEVR0lADARBgorBgEEAYOK\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    51
        "YgEBBAMCAQQwRwYDVR0eAQH/BD0wO6A3MDWkMzAxMQswCQYDVQQGEwJHQjEPMA0G\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    52
        "A1UEBwwGTG9uZG9uMREwDwYDVQQKDAhNZWdhQ29ycKEAMBQGCCqGSM49BAMCBggq\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    53
        "hkjOPQMBBwNJADBGAiEAos+QzgwwH2hfOtrlLncHnoT2YXXHP4q5h01T2DRmjcMC\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    54
        "IQDa3xZz7CkyyNO1+paAthiNVIlGwwnl4UxuYMwkAiWACw==\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    55
        "-----END CERTIFICATE-----\n";
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    56
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    57
    // ECDSA certificate with only signature algorithm oid, no parameters, i.e.
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    58
    // Signature Algorithm: SHA256withECDSA, OID = 1.2.840.10045.4.3.2
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    59
    private static String ecSigner =
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    60
        "-----BEGIN CERTIFICATE-----\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    61
        "MIICETCCAbigAwIBAgIIaHr3YTnjT8YwCgYIKoZIzj0EAwIwWDEbMBkGA1UEAwwS\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    62
        "Q29yZGEgTm9kZSBSb290IENBMQswCQYDVQQKDAJSMzEOMAwGA1UECwwFY29yZGEx\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    63
        "DzANBgNVBAcMBkxvbmRvbjELMAkGA1UEBhMCVUswHhcNMTcwNTIyMDAwMDAwWhcN\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    64
        "MjcwNTIwMDAwMDAwWjBgMSMwIQYDVQQDDBpDb3JkYSBOb2RlIEludGVybWVkaWF0\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    65
        "ZSBDQTELMAkGA1UECgwCUjMxDjAMBgNVBAsMBWNvcmRhMQ8wDQYDVQQHDAZMb25k\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    66
        "b24xCzAJBgNVBAYTAlVLMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEA8veoCbh\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    67
        "ZmazlyIFWjExBd8ru5OYdFW9Z9ZD5BVg/dswdKC4dlHMHe/sQ4TxFmkYNqf7DTTt\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    68
        "ePtdHT7Eb1LGYKNkMGIwHQYDVR0OBBYEFOvuLjAVKUCuGZge2G/jfX8HosITMAsG\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    69
        "A1UdDwQEAwIBhjAjBgNVHSUEHDAaBggrBgEFBQcDAQYIKwYBBQUHAwIGBFUdJQAw\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    70
        "DwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNHADBEAiB6wr47tuC71qi6+FbY\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    71
        "XYDTvK+QmAi5ywkFc95I9fPLaQIgIM+nNNQ50NwK610h3bG37XC2tGu+A7Dhtt2Q\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    72
        "4nDqu30=\n" +
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    73
        "-----END CERTIFICATE-----\n";
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    74
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    75
    public static void main(String[] args) throws Exception {
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    76
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    77
        ByteArrayInputStream is
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    78
                = new ByteArrayInputStream(ecEntityWithSigParamsStr.getBytes());
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    79
        X509Certificate ecEntityWithSigParams = (X509Certificate)certFactory.generateCertificate(is);
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    80
        is = new ByteArrayInputStream(ecSigner.getBytes());
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    81
        X509Certificate ecSigner = (X509Certificate)certFactory.generateCertificate(is);
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    82
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    83
        try {
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    84
            ecEntityWithSigParams.verify(ecSigner.getPublicKey());
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    85
            System.out.println("Test Passed: EC Cert verified");
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    86
        } catch (Exception e) {
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    87
            System.out.println("Failed, cannot verify EC certificate with sig params");
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    88
            throw e;
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    89
        }
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    90
    }
6521aec1c26e 8225745: NoSuchAlgorithmException exception for SHA256withECDSA with RSASSA-PSS support
valeriep
parents:
diff changeset
    91
}