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