test/jdk/sun/security/ec/TestEC.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 51461 58d7aa066071
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     4
 *
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     8
 *
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    13
 * accompanied this code).
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    14
 *
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3863
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3863
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3863
diff changeset
    21
 * questions.
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    22
 */
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    23
16913
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    24
//
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    25
// SunJSSE does not support dynamic system properties, no way to re-use
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    26
// system properties in samevm/agentvm mode.
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    27
//
a6f4d1626ad9 8011680: Re-integrate AEAD implementation of JSSE
xuelei
parents: 16067
diff changeset
    28
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    29
/**
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    30
 * @test
41556
0c49ded763a8 8168078: Remove permission to read all system properties granted to the jdk.crypto.ec module
mullan
parents: 39563
diff changeset
    31
 * @bug 6840752 8168078
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    32
 * @summary  Provide out-of-the-box support for ECC algorithms
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    33
 * @library ../pkcs11
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    34
 * @library ../pkcs11/ec
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    35
 * @library ../pkcs11/sslecc
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    36
 * @library ../../../java/security/testlibrary
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    37
 * @library ../../../javax/net/ssl/TLSCommon
43248
5e15de85a1a0 8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents: 42693
diff changeset
    38
 * @modules jdk.crypto.cryptoki/sun.security.pkcs11.wrapper
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 38886
diff changeset
    39
 * @run main/othervm -Djdk.tls.namedGroups="secp256r1,sect193r1" TestEC
41556
0c49ded763a8 8168078: Remove permission to read all system properties granted to the jdk.crypto.ec module
mullan
parents: 39563
diff changeset
    40
 * @run main/othervm/java.security.policy=TestEC.policy -Djdk.tls.namedGroups="secp256r1,sect193r1" TestEC
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    41
 */
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    42
13661
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    43
import java.security.NoSuchProviderException;
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    44
import java.security.Provider;
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    45
import java.security.Security;
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    46
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    47
/*
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    48
 * Leverage the collection of EC tests used by PKCS11
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    49
 *
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    50
 * NOTE: the following 6 files were copied here from the PKCS11 EC Test area
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    51
 *       and must be kept in sync with the originals:
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    52
 *
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    53
 *           ../pkcs11/ec/p12passwords.txt
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    54
 *           ../pkcs11/ec/certs/sunlabscerts.pem
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    55
 *           ../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p12
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    56
 *           ../pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    57
 *           ../pkcs11/sslecc/keystore
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    58
 *           ../pkcs11/sslecc/truststore
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    59
 */
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    60
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    61
public class TestEC {
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    62
38886
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    63
    /*
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    64
     * Turn on SSL debugging
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    65
     */
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    66
    private static final boolean debug = true;
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    67
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    68
    public static void main(String[] args) throws Exception {
31712
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 30820
diff changeset
    69
        // reset security properties to make sure that the algorithms
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 22268
diff changeset
    70
        // and keys used in this test are not disabled.
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 22268
diff changeset
    71
        Security.setProperty("jdk.tls.disabledAlgorithms", "");
31712
e4d5230193da 8076328: Enforce key exchange constraints
xuelei
parents: 30820
diff changeset
    72
        Security.setProperty("jdk.certpath.disabledAlgorithms", "");
22268
d72c97c708ae 8030829: Add MD5 to jdk.certpath.disabledAlgorithms security property
xuelei
parents: 16913
diff changeset
    73
38886
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    74
        if (debug) {
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    75
            System.setProperty("javax.net.debug", "all");
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    76
        }
bf687d4281eb 8158620: Enable debug option for sun/security/ec/TestEC.java
fyuan
parents: 31712
diff changeset
    77
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    78
        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    79
        try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    80
            main0(args);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    81
        } finally {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    82
            snapshot.restore();
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    83
        }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    84
    }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    85
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
    86
    public static void main0(String[] args) throws Exception {
13661
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    87
        Provider p = Security.getProvider("SunEC");
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    88
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    89
        if (p == null) {
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    90
            throw new NoSuchProviderException("Can't get SunEC provider");
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    91
        }
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 10328
diff changeset
    92
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    93
        System.out.println("Running tests with " + p.getName() +
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    94
            " provider...\n");
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    95
        long start = System.currentTimeMillis();
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
    96
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    97
        /*
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    98
         * The entry point used for each test is its instance method
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
    99
         * called main (not its static method called main).
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
   100
         */
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   101
        new TestECDH().main(p);
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   102
        new TestECDSA().main(p);
3636
b80fdcc0b0d5 6872048: bad private keys are generated for 2 specific ECC curves
vinnie
parents: 3492
diff changeset
   103
        new TestCurves().main(p);
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   104
        new TestKeyFactory().main(p);
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   105
        new TestECGenSpec().main(p);
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   106
        new ReadPKCS12().main(p);
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
   107
        new ReadCertificates().main(p);
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
   108
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
   109
        // ClientJSSEServerJSSE fails on Solaris 11 when both SunEC and
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
   110
        // SunPKCS11-Solaris providers are enabled.
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
   111
        // Workaround:
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 8991
diff changeset
   112
        // Security.removeProvider("SunPKCS11-Solaris");
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
   113
        new ClientJSSEServerJSSE().main(p);
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   114
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
   115
        long stop = System.currentTimeMillis();
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   116
        System.out.println("\nCompleted tests with " + p.getName() +
3863
8e0f58b1c072 6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents: 3636
diff changeset
   117
            " provider (" + ((stop - start) / 1000.0) + " seconds).");
3492
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   118
    }
e549cea58864 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff changeset
   119
}