TestEC.java 3.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
22 23
 */

24 25 26 27 28
//
// SunJSSE does not support dynamic system properties, no way to re-use
// system properties in samevm/agentvm mode.
//

29 30 31 32 33 34
/**
 * @test
 * @bug 6840752
 * @summary  Provide out-of-the-box support for ECC algorithms
 * @library ../pkcs11
 * @library ../pkcs11/ec
35
 * @library ../pkcs11/sslecc
36
 * @library ../../../java/security/testlibrary
37
 * @compile -XDignore.symbol.file TestEC.java
38
 * @run main/othervm TestEC
39 40
 */

41
import java.security.NoSuchProviderException;
42
import java.security.Provider;
43
import java.security.Security;
44 45 46 47

/*
 * Leverage the collection of EC tests used by PKCS11
 *
48
 * NOTE: the following 6 files were copied here from the PKCS11 EC Test area
49 50 51
 *       and must be kept in sync with the originals:
 *
 *           ../pkcs11/ec/p12passwords.txt
52
 *           ../pkcs11/ec/certs/sunlabscerts.pem
53 54
 *           ../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p12
 *           ../pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12
55 56
 *           ../pkcs11/sslecc/keystore
 *           ../pkcs11/sslecc/truststore
57 58 59 60 61
 */

public class TestEC {

    public static void main(String[] args) throws Exception {
62 63 64 65 66 67 68 69 70
        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
        try {
            main0(args);
        } finally {
            snapshot.restore();
        }
    }

    public static void main0(String[] args) throws Exception {
X
xuelei 已提交
71 72 73 74
        // reset the security property to make sure that the algorithms
        // and keys used in this test are not disabled.
        Security.setProperty("jdk.tls.disabledAlgorithms", "");

75 76 77 78 79 80
        Provider p = Security.getProvider("SunEC");

        if (p == null) {
            throw new NoSuchProviderException("Can't get SunEC provider");
        }

81 82 83
        System.out.println("Running tests with " + p.getName() +
            " provider...\n");
        long start = System.currentTimeMillis();
84 85 86 87 88

        /*
         * The entry point used for each test is its instance method
         * called main (not its static method called main).
         */
89 90
        new TestECDH().main(p);
        new TestECDSA().main(p);
91
        new TestCurves().main(p);
92 93 94
        new TestKeyFactory().main(p);
        new TestECGenSpec().main(p);
        new ReadPKCS12().main(p);
95
        new ReadCertificates().main(p);
96 97 98 99 100

        // ClientJSSEServerJSSE fails on Solaris 11 when both SunEC and
        // SunPKCS11-Solaris providers are enabled.
        // Workaround:
        // Security.removeProvider("SunPKCS11-Solaris");
101
        new ClientJSSEServerJSSE().main(p);
102

103
        long stop = System.currentTimeMillis();
104
        System.out.println("\nCompleted tests with " + p.getName() +
105
            " provider (" + ((stop - start) / 1000.0) + " seconds).");
106 107
    }
}