|
|
4ca1da |
/* TestCryptoLevel -- Ensure unlimited crypto policy is in use.
|
|
|
4ca1da |
Copyright (C) 2012 Red Hat, Inc.
|
|
|
4ca1da |
|
|
|
4ca1da |
This program is free software: you can redistribute it and/or modify
|
|
|
4ca1da |
it under the terms of the GNU Affero General Public License as
|
|
|
4ca1da |
published by the Free Software Foundation, either version 3 of the
|
|
|
4ca1da |
License, or (at your option) any later version.
|
|
|
4ca1da |
|
|
|
4ca1da |
This program is distributed in the hope that it will be useful,
|
|
|
4ca1da |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
4ca1da |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
4ca1da |
GNU Affero General Public License for more details.
|
|
|
4ca1da |
|
|
|
4ca1da |
You should have received a copy of the GNU Affero General Public License
|
|
|
4ca1da |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
4ca1da |
*/
|
|
|
4ca1da |
|
|
|
4ca1da |
import java.lang.reflect.Field;
|
|
|
4ca1da |
import java.lang.reflect.Method;
|
|
|
4ca1da |
import java.lang.reflect.InvocationTargetException;
|
|
|
4ca1da |
|
|
|
4ca1da |
import java.security.Permission;
|
|
|
4ca1da |
import java.security.PermissionCollection;
|
|
|
4ca1da |
|
|
|
4ca1da |
public class TestCryptoLevel
|
|
|
4ca1da |
{
|
|
|
4ca1da |
public static void main(String[] args)
|
|
|
4ca1da |
throws NoSuchFieldException, ClassNotFoundException,
|
|
|
4ca1da |
IllegalAccessException, InvocationTargetException
|
|
|
4ca1da |
{
|
|
|
4ca1da |
Class cls = null;
|
|
|
4ca1da |
Method def = null, exempt = null;
|
|
|
4ca1da |
|
|
|
4ca1da |
try
|
|
|
4ca1da |
{
|
|
|
4ca1da |
cls = Class.forName("javax.crypto.JceSecurity");
|
|
|
4ca1da |
}
|
|
|
4ca1da |
catch (ClassNotFoundException ex)
|
|
|
4ca1da |
{
|
|
|
4ca1da |
System.err.println("Running a non-Sun JDK.");
|
|
|
4ca1da |
System.exit(0);
|
|
|
4ca1da |
}
|
|
|
4ca1da |
try
|
|
|
4ca1da |
{
|
|
|
4ca1da |
def = cls.getDeclaredMethod("getDefaultPolicy");
|
|
|
4ca1da |
exempt = cls.getDeclaredMethod("getExemptPolicy");
|
|
|
4ca1da |
}
|
|
|
4ca1da |
catch (NoSuchMethodException ex)
|
|
|
4ca1da |
{
|
|
|
4ca1da |
System.err.println("Running IcedTea with the original crypto patch.");
|
|
|
4ca1da |
System.exit(0);
|
|
|
4ca1da |
}
|
|
|
4ca1da |
def.setAccessible(true);
|
|
|
4ca1da |
exempt.setAccessible(true);
|
|
|
4ca1da |
PermissionCollection defPerms = (PermissionCollection) def.invoke(null);
|
|
|
4ca1da |
PermissionCollection exemptPerms = (PermissionCollection) exempt.invoke(null);
|
|
|
4ca1da |
Class apCls = Class.forName("javax.crypto.CryptoAllPermission");
|
|
|
4ca1da |
Field apField = apCls.getDeclaredField("INSTANCE");
|
|
|
4ca1da |
apField.setAccessible(true);
|
|
|
4ca1da |
Permission allPerms = (Permission) apField.get(null);
|
|
|
4ca1da |
if (defPerms.implies(allPerms) && (exemptPerms == null || exemptPerms.implies(allPerms)))
|
|
|
4ca1da |
{
|
|
|
4ca1da |
System.err.println("Running with the unlimited policy.");
|
|
|
4ca1da |
System.exit(0);
|
|
|
4ca1da |
}
|
|
|
4ca1da |
else
|
|
|
4ca1da |
{
|
|
|
4ca1da |
System.err.println("WARNING: Running with a restricted crypto policy.");
|
|
|
4ca1da |
System.exit(-1);
|
|
|
4ca1da |
}
|
|
|
4ca1da |
}
|
|
|
4ca1da |
}
|