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