changeset 719:31cb1c17f524

6728890: Add SwissSign root certificates to the JDK 6732157: Add VeriSign TSA Root Cert to the JDK 6754779: Add Camerfirma root certificates to the JDK 6768559: Add t-systems root CA certificate (Deutsche Telekom Root CA 2) to the JRE Reviewed-by: vinnie
author mullan
date Tue, 25 Nov 2008 10:17:00 -0500
parents d7b0a715bd3b
children b1620482689a
files test/lib/security/cacerts/VerifyCACerts.java
diffstat 1 files changed, 85 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/test/lib/security/cacerts/VerifyCACerts.java	Sun Nov 23 09:56:39 2008 -0800
+++ b/test/lib/security/cacerts/VerifyCACerts.java	Tue Nov 25 10:17:00 2008 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,11 +23,12 @@
 
 /**
  * @test
- * @bug 4400624 6321453
+ * @bug 4400624 6321453 6728890 6732157 6754779 6768559
  * @summary Make sure all self-signed root cert signatures are valid
  */
 import java.io.FileInputStream;
 import java.security.KeyStore;
+import java.security.MessageDigest;
 import java.security.cert.*;
 import java.util.*;
 
@@ -39,25 +40,102 @@
         System.getProperty("file.separator") + "security" +
         System.getProperty("file.separator") + "cacerts";
 
+    private static boolean atLeastOneFailed = false;
+
+    private static MessageDigest md;
+
+    // map of cert alias to SHA1 fingerprint
+    private static Map<String, String> fpMap = new HashMap<String, String>();
+
+    private static String[][] entries = {
+        { "swisssignsilverg2ca", "9B:AA:E5:9F:56:EE:21:CB:43:5A:BE:25:93:DF:A7:F0:40:D1:1D:CB"},
+        { "swisssigngoldg2ca", "D8:C5:38:8A:B7:30:1B:1B:6E:D4:7A:E6:45:25:3A:6F:9F:1A:27:61"},
+        { "swisssignplatinumg2ca", "56:E0:FA:C0:3B:8F:18:23:55:18:E5:D3:11:CA:E8:C2:43:31:AB:66"},
+        { "verisigntsaca", "BE:36:A4:56:2F:B2:EE:05:DB:B3:D3:23:23:AD:F4:45:08:4E:D6:56"},
+        { "camerfirmachambersignca", "4A:BD:EE:EC:95:0D:35:9C:89:AE:C7:52:A1:2C:5B:29:F6:D6:AA:0C"},
+        { "camerfirmachambersca", "78:6A:74:AC:76:AB:14:7F:9C:6A:30:50:BA:9E:A8:7E:FE:9A:CE:3C"},
+        { "camerfirmachamberscommerceca", "6E:3A:55:A4:19:0C:19:5C:93:84:3C:C0:DB:72:2E:31:30:61:F0:B1"},
+        { "deutschetelekomrootca2", "85:A4:08:C0:9C:19:3E:5D:51:58:7D:CD:D6:13:30:FD:8C:DE:37:BF"},
+    };
+
+    static {
+        for (String[] entry : entries) {
+            fpMap.put(entry[0], entry[1]);
+        }
+    };
+
     public static void main(String[] args) throws Exception {
+        md = MessageDigest.getInstance("SHA1");
+        KeyStore ks = KeyStore.getInstance("JKS");
+        ks.load(new FileInputStream(cacertsFileName), "changeit".toCharArray());
 
+        // check that all entries in the map are in the keystore
+        for (String alias : fpMap.keySet()) {
+            if (!ks.isCertificateEntry(alias)) {
+                atLeastOneFailed = true;
+                System.err.println(alias + " is not in cacerts");
+            }
+        }
         // pull all the trusted self-signed CA certs out of the cacerts file
         // and verify their signatures
-        KeyStore ks = KeyStore.getInstance("JKS");
-        ks.load(new FileInputStream(cacertsFileName), "changeit".toCharArray());
         Enumeration<String> aliases = ks.aliases();
         while (aliases.hasMoreElements()) {
             String alias = aliases.nextElement();
             System.out.println("Verifying " + alias);
-            if (!ks.isCertificateEntry(alias))
-                throw new Exception(alias + " is not a trusted cert entry");
+            if (!ks.isCertificateEntry(alias)) {
+                atLeastOneFailed = true;
+                System.err.println(alias + " is not a trusted cert entry");
+            }
             Certificate cert = ks.getCertificate(alias);
             // remember the GTE CyberTrust CA cert for further tests
             if (alias.equals("gtecybertrustca")) {
-                throw new Exception
+                atLeastOneFailed = true;
+                System.err.println
                     ("gtecybertrustca is expired and should be deleted");
             }
             cert.verify(cert.getPublicKey());
+            if (!checkFingerprint(alias, cert)) {
+                atLeastOneFailed = true;
+                System.err.println
+                    (alias + " SHA1 fingerprint is incorrect");
+            }
+        }
+
+        if (atLeastOneFailed) {
+            throw new Exception("At least one cacert test failed");
         }
     }
+
+    private static boolean checkFingerprint(String alias, Certificate cert)
+        throws Exception {
+        String fingerprint = fpMap.get(alias);
+        if (fingerprint == null) {
+            // no entry for alias
+            return true;
+        }
+        System.out.println("Checking fingerprint of " + alias);
+        byte[] digest = md.digest(cert.getEncoded());
+        return fingerprint.equals(toHexString(digest));
+    }
+
+    private static String toHexString(byte[] block) {
+        StringBuffer buf = new StringBuffer();
+        int len = block.length;
+        for (int i = 0; i < len; i++) {
+             byte2hex(block[i], buf);
+             if (i < len-1) {
+                 buf.append(":");
+             }
+        }
+        return buf.toString();
+    }
+
+    private static void byte2hex(byte b, StringBuffer buf) {
+        char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
+                            '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+        int high = ((b & 0xf0) >> 4);
+        int low = (b & 0x0f);
+        buf.append(hexChars[high]);
+        buf.append(hexChars[low]);
+    }
 }