TestEC.java revision 6705:6379415d8fca
1/*
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * @test
26 * @bug 6840752
27 * @summary  Provide out-of-the-box support for ECC algorithms
28 * @library ../pkcs11
29 * @library ../pkcs11/ec
30 * @library ../pkcs11/sslecc
31 * @library ../../../java/security/testlibrary
32 * @compile -XDignore.symbol.file TestEC.java
33 * @run main TestEC
34 */
35
36import java.security.NoSuchProviderException;
37import java.security.Provider;
38import java.security.Security;
39
40/*
41 * Leverage the collection of EC tests used by PKCS11
42 *
43 * NOTE: the following 6 files were copied here from the PKCS11 EC Test area
44 *       and must be kept in sync with the originals:
45 *
46 *           ../pkcs11/ec/p12passwords.txt
47 *           ../pkcs11/ec/certs/sunlabscerts.pem
48 *           ../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p12
49 *           ../pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12
50 *           ../pkcs11/sslecc/keystore
51 *           ../pkcs11/sslecc/truststore
52 */
53
54public class TestEC {
55
56    public static void main(String[] args) throws Exception {
57        ProvidersSnapshot snapshot = ProvidersSnapshot.create();
58        try {
59            main0(args);
60        } finally {
61            snapshot.restore();
62        }
63    }
64
65    public static void main0(String[] args) throws Exception {
66        Provider p = Security.getProvider("SunEC");
67
68        if (p == null) {
69            throw new NoSuchProviderException("Can't get SunEC provider");
70        }
71
72        System.out.println("Running tests with " + p.getName() +
73            " provider...\n");
74        long start = System.currentTimeMillis();
75
76        /*
77         * The entry point used for each test is its instance method
78         * called main (not its static method called main).
79         */
80        new TestECDH().main(p);
81        new TestECDSA().main(p);
82        new TestCurves().main(p);
83        new TestKeyFactory().main(p);
84        new TestECGenSpec().main(p);
85        new ReadPKCS12().main(p);
86        new ReadCertificates().main(p);
87
88        // ClientJSSEServerJSSE fails on Solaris 11 when both SunEC and
89        // SunPKCS11-Solaris providers are enabled.
90        // Workaround:
91        // Security.removeProvider("SunPKCS11-Solaris");
92        new ClientJSSEServerJSSE().main(p);
93
94        long stop = System.currentTimeMillis();
95        System.out.println("\nCompleted tests with " + p.getName() +
96            " provider (" + ((stop - start) / 1000.0) + " seconds).");
97    }
98}
99