blob: 774908cca54bdc61d70ddee0cd08f4dcbace9bb4 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4400624 6321453
27 * @summary Make sure all self-signed root cert signatures are valid
28 */
29import java.io.FileInputStream;
30import java.security.KeyStore;
31import java.security.cert.*;
32import java.util.*;
33
34public class VerifyCACerts {
35
36 private final static String cacertsFileName =
37 System.getProperty("java.home") +
38 System.getProperty("file.separator") + "lib" +
39 System.getProperty("file.separator") + "security" +
40 System.getProperty("file.separator") + "cacerts";
41
42 public static void main(String[] args) throws Exception {
43
44 // pull all the trusted self-signed CA certs out of the cacerts file
45 // and verify their signatures
46 KeyStore ks = KeyStore.getInstance("JKS");
47 ks.load(new FileInputStream(cacertsFileName), "changeit".toCharArray());
48 Enumeration<String> aliases = ks.aliases();
49 while (aliases.hasMoreElements()) {
50 String alias = aliases.nextElement();
51 System.out.println("Verifying " + alias);
52 if (!ks.isCertificateEntry(alias))
53 throw new Exception(alias + " is not a trusted cert entry");
54 Certificate cert = ks.getCertificate(alias);
55 // remember the GTE CyberTrust CA cert for further tests
56 if (alias.equals("gtecybertrustca")) {
57 throw new Exception
58 ("gtecybertrustca is expired and should be deleted");
59 }
60 cert.verify(cert.getPublicKey());
61 }
62 }
63}