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