changeset 11705:79db712cd915

8154009: Some methods of java.security.Security require more permissions, than necessary Reviewed-by: mullan
author akosarev
date Wed, 08 Jun 2016 15:52:05 +0000
parents fe5b73da2569
children 2cca69b723f1
files src/share/classes/sun/security/jca/ProviderConfig.java test/ProblemList.txt test/java/security/Security/AddProvider.java test/java/security/Security/AddProvider.policy.1 test/java/security/Security/AddProvider.policy.2 test/java/security/Security/AddProvider.policy.3 test/java/security/Security/EmptyPolicy.policy test/java/security/Security/GetProviders.java test/java/security/Security/removing/RemoveStaticProvider.java test/java/security/Security/removing/RemoveStaticProvider.policy
diffstat 10 files changed, 94 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/jca/ProviderConfig.java	Thu Jun 09 15:08:54 2016 +0300
+++ b/src/share/classes/sun/security/jca/ProviderConfig.java	Wed Jun 08 15:52:05 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. 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
@@ -255,6 +255,15 @@
                         disableLoad();
                     }
                     return null;
+                } catch (ExceptionInInitializerError err) {
+                    // unexpected exception thrown from static initialization block in provider
+                    // (ex: insufficient permission to initialize provider class)
+                    if (debug != null) {
+                        debug.println("Error loading provider " + ProviderConfig.this);
+                        err.printStackTrace();
+                    }
+                    disableLoad();
+                    return null;
                 }
             }
         });
--- a/test/ProblemList.txt	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/ProblemList.txt	Wed Jun 08 15:52:05 2016 +0000
@@ -237,10 +237,6 @@
 # 8026393
 sun/security/tools/jarsigner/warnings/BadKeyUsageTest.java      generic-all
 
-# 8154009
-javax/security/auth/PrivateCredentialPermission/MoreThenOnePrincipals.java solaris-all
-java/security/Policy/ExtensiblePolicy/ExtensiblePolicyTest.java            solaris-all 
-
 ############################################################################
 
 # jdk_sound
--- a/test/java/security/Security/AddProvider.java	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/AddProvider.java	Wed Jun 08 15:52:05 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. 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,7 +23,7 @@
 
 /*
  * @test
- * @bug 8001319
+ * @bug 8001319 8154009
  * @summary check that SecurityPermission insertProvider permission is enforced
  *          correctly
  * @run main/othervm/policy=AddProvider.policy.1 AddProvider 1
--- a/test/java/security/Security/AddProvider.policy.1	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/AddProvider.policy.1	Wed Jun 08 15:52:05 2016 +0000
@@ -1,7 +1,3 @@
-grant codeBase "file:${{java.ext.dirs}}/*" {
-	permission java.security.AllPermission;
-};
-
 grant {
     permission java.security.SecurityPermission "insertProvider";
 };
--- a/test/java/security/Security/AddProvider.policy.2	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/AddProvider.policy.2	Wed Jun 08 15:52:05 2016 +0000
@@ -1,7 +1,3 @@
-grant codeBase "file:${{java.ext.dirs}}/*" {
-	permission java.security.AllPermission;
-};
-
 grant {
     permission java.security.SecurityPermission "insertProvider.Test1";
     permission java.security.SecurityPermission "insertProvider.Test2";
--- a/test/java/security/Security/AddProvider.policy.3	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/AddProvider.policy.3	Wed Jun 08 15:52:05 2016 +0000
@@ -1,7 +1,3 @@
-grant codeBase "file:${{java.ext.dirs}}/*" {
-	permission java.security.AllPermission;
-};
-
 grant {
     permission java.security.SecurityPermission "insertProvider.*";
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/security/Security/EmptyPolicy.policy	Wed Jun 08 15:52:05 2016 +0000
@@ -0,0 +1,2 @@
+// empty policy file for testing
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/security/Security/GetProviders.java	Wed Jun 08 15:52:05 2016 +0000
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8154009
+ * @summary make sure getProviders() doesn't require additional permissions
+ * @run main/othervm/policy=EmptyPolicy.policy GetProviders
+ */
+
+import java.security.Provider;
+import java.security.Security;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetProviders {
+
+    private static final String serviceAlgFilter = "Signature.SHA1withRSA";
+    private static final String emptyServAlgFilter = "wrongSig.wrongAlg";
+
+    public static void main(String[] args) throws Exception {
+        try {
+            Provider[] providers1 = Security.getProviders();
+            System.out.println("Amount of providers1: " + providers1.length);
+
+            Provider[] providers2 = Security.getProviders(serviceAlgFilter);
+            System.out.println("Amount of providers2: " + providers2.length);
+
+            Map<String, String> filter = new HashMap<String, String>();
+            filter.put(serviceAlgFilter, "");
+            Provider[] providers3 = Security.getProviders(filter);
+            System.out.println("Amount of providers3: " + providers3.length);
+
+            Provider[] emptyProv1 = Security.getProviders(emptyServAlgFilter);
+            if (emptyProv1 != null) {
+                throw new RuntimeException("Empty Filter returned: " +
+                    emptyProv1.length + " providers");
+            }
+            System.out.println("emptyProv1 is empty as expected");
+
+            Map<String, String> emptyFilter = new HashMap<String, String>();
+            emptyFilter.put(emptyServAlgFilter, "");
+            Provider[] emptyProv2 = Security.getProviders(emptyFilter);
+            if (emptyProv2 != null) {
+                throw new RuntimeException("Empty Filter returned: " +
+                    emptyProv2.length + " providers");
+            }
+            System.out.println("emptyProv2 is empty as expected");
+
+        } catch(ExceptionInInitializerError e) {
+            e.printStackTrace(System.out);
+            throw new RuntimeException("Provider initialization error due to "
+                    + e.getCause());
+        }
+        System.out.println("Test passed");
+    }
+
+}
--- a/test/java/security/Security/removing/RemoveStaticProvider.java	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/removing/RemoveStaticProvider.java	Wed Jun 08 15:52:05 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. 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,7 +23,7 @@
 
 /*
  * @test
- * @bug 4420687
+ * @bug 4420687 8154009
  * @summary Make sure that a removed provider won't be acceessable.
  * @run main/othervm/policy=RemoveStaticProvider.policy RemoveStaticProvider
  */
--- a/test/java/security/Security/removing/RemoveStaticProvider.policy	Thu Jun 09 15:08:54 2016 +0300
+++ b/test/java/security/Security/removing/RemoveStaticProvider.policy	Wed Jun 08 15:52:05 2016 +0000
@@ -3,8 +3,3 @@
     permission java.security.SecurityPermission "insertProvider.SunJCE";
 };
 
-// Standard extensions get all permissions
-grant codeBase "file:${java.home}/lib/ext/*" {
-        permission java.security.AllPermission;
-};
-