Path: blob/master/test/jdk/sun/security/rsa/TestCACerts.java
41149 views
/*1* Copyright (c) 2003, 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* @test25* @bug 485330526* @summary Test the new RSA provider can verify all the RSA certs in the cacerts file27* @author Andreas Sterbenz28*/2930// this test serves as our known answer test3132import java.io.*;33import java.util.*;3435import java.security.*;36import java.security.cert.*;3738public class TestCACerts {3940private final static String PROVIDER = "SunRsaSign";4142private final static char SEP = File.separatorChar;4344public static void main(String[] args) throws Exception {45long start = System.currentTimeMillis();46String javaHome = System.getProperty("java.home");47String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";48InputStream in = new FileInputStream(caCerts);49KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());50ks.load(in, null);51in.close();52for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {53String alias = (String)e.nextElement();54if (ks.isCertificateEntry(alias)) {55System.out.println("* Testing " + alias + "...");56X509Certificate cert = (X509Certificate)ks.getCertificate(alias);57PublicKey key = cert.getPublicKey();58String alg = key.getAlgorithm();59if (alg.equals("RSA")) {60System.out.println("Signature algorithm: " + cert.getSigAlgName());61cert.verify(key, PROVIDER);62} else {63System.out.println("Skipping cert with key: " + alg);64}65} else {66System.out.println("Skipping alias " + alias);67}68}69long stop = System.currentTimeMillis();70System.out.println("All tests passed (" + (stop - start) + " ms).");71}7273}747576