jdk/test/sun/security/pkcs11/rsa/TestCACerts.java
changeset 10328 06c93c42bca0
parent 5506 202f599c92aa
child 14342 8435a30053c1
--- a/jdk/test/sun/security/pkcs11/rsa/TestCACerts.java	Fri Aug 12 11:20:45 2011 +0800
+++ b/jdk/test/sun/security/pkcs11/rsa/TestCACerts.java	Fri Aug 12 12:26:31 2011 +0800
@@ -48,32 +48,35 @@
     public void main(Provider p) throws Exception {
         long start = System.currentTimeMillis();
         Security.addProvider(p);
-        String PROVIDER = p.getName();
-        String javaHome = System.getProperty("java.home");
-        String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
-        InputStream in = new FileInputStream(caCerts);
-        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
-        ks.load(in, null);
-        in.close();
-        for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
-            String alias = (String)e.nextElement();
-            if (ks.isCertificateEntry(alias)) {
-                System.out.println("* Testing " + alias + "...");
-                X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
-                PublicKey key = cert.getPublicKey();
-                String alg = key.getAlgorithm();
-                if (alg.equals("RSA")) {
-                    System.out.println("Signature algorithm: " + cert.getSigAlgName());
-                    cert.verify(key, PROVIDER);
+        try {
+            String PROVIDER = p.getName();
+            String javaHome = System.getProperty("java.home");
+            String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
+            InputStream in = new FileInputStream(caCerts);
+            KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+            ks.load(in, null);
+            in.close();
+            for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
+                String alias = (String)e.nextElement();
+                if (ks.isCertificateEntry(alias)) {
+                    System.out.println("* Testing " + alias + "...");
+                    X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
+                    PublicKey key = cert.getPublicKey();
+                    String alg = key.getAlgorithm();
+                    if (alg.equals("RSA")) {
+                        System.out.println("Signature algorithm: " + cert.getSigAlgName());
+                        cert.verify(key, PROVIDER);
+                    } else {
+                        System.out.println("Skipping cert with key: " + alg);
+                    }
                 } else {
-                    System.out.println("Skipping cert with key: " + alg);
+                    System.out.println("Skipping alias " + alias);
                 }
-            } else {
-                System.out.println("Skipping alias " + alias);
             }
+            long stop = System.currentTimeMillis();
+            System.out.println("All tests passed (" + (stop - start) + " ms).");
+        } finally {
+            Security.removeProvider(p.getName());
         }
-        long stop = System.currentTimeMillis();
-        System.out.println("All tests passed (" + (stop - start) + " ms).");
     }
-
 }