Path: blob/master/test/jdk/sun/security/ec/TestEC.java
41149 views
/*1* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223//24// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/**29* @test30* @bug 6840752 816807831* @summary Provide out-of-the-box support for ECC algorithms32* @library /test/lib33* @library ../pkcs1134* @library ../pkcs11/ec35* @library ../pkcs11/sslecc36* @library ../../../java/security/testlibrary37* @library ../../../javax/net/ssl/TLSCommon38* @modules jdk.crypto.cryptoki/sun.security.pkcs11.wrapper39* @run main/othervm -Djdk.tls.namedGroups="secp256r1" TestEC40* @run main/othervm -Djava.security.policy=TestEC.policy41* -Djdk.tls.namedGroups="secp256r1" TestEC42*/4344import java.security.NoSuchProviderException;45import java.security.Provider;46import java.security.Security;4748/*49* Leverage the collection of EC tests used by PKCS1150*51* NOTE: the following 5 files were copied here from the PKCS11 EC Test area52* and must be kept in sync with the originals:53*54* ../pkcs11/ec/p12passwords.txt55* ../pkcs11/ec/certs/sunlabscerts.pem56* ../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p1257* ../pkcs11/sslecc/keystore58* ../pkcs11/sslecc/truststore59*/6061public class TestEC {6263/*64* Turn on SSL debugging65*/66private static final boolean debug = true;6768public static void main(String[] args) throws Exception {69// reset security properties to make sure that the algorithms70// and keys used in this test are not disabled.71Security.setProperty("jdk.tls.disabledAlgorithms", "");72Security.setProperty("jdk.certpath.disabledAlgorithms", "");7374if (debug) {75System.setProperty("javax.net.debug", "all");76}7778ProvidersSnapshot snapshot = ProvidersSnapshot.create();79try {80main0(args);81} finally {82snapshot.restore();83}84}8586public static void main0(String[] args) throws Exception {87Provider p = Security.getProvider("SunEC");8889if (p == null) {90throw new NoSuchProviderException("Can't get SunEC provider");91}9293System.out.println("Running tests with " + p.getName() +94" provider...\n");95long start = System.currentTimeMillis();9697/*98* The entry point used for each test is its instance method99* called main (not its static method called main).100*/101System.out.println("TestECDH");102new TestECDH().main(p);103System.out.println("TestECDSA");104new TestECDSA().main(p);105System.out.println("TestCurves");106new TestCurves().main(p);107System.out.println("TestKeyFactory");108new TestKeyFactory().main(p);109System.out.println("TestECGenSpec");110new TestECGenSpec().main(p);111System.out.println("ReadPKCS12");112new ReadPKCS12().main(p);113System.out.println("ReadCertificate");114new ReadCertificates().main(p);115System.out.println("ClientJSSEServerJSSE");116new ClientJSSEServerJSSE().main(p);117118long stop = System.currentTimeMillis();119System.out.println("\nCompleted tests with " + p.getName() +120" provider (" + ((stop - start) / 1000.0) + " seconds).");121}122}123124125