diff options
author | Simon Frankenberger <simon@fraho.eu> | 2020-03-18 20:57:41 +0200 |
---|---|---|
committer | Rasmus Thomsen <oss@cogitri.dev> | 2020-03-25 14:03:30 +0000 |
commit | 3991e58da736e29cd687b150644fe6c1317b6750 (patch) | |
tree | d82d24657f530fd325515144312b61859135e2e6 /testing/openjdk13/TestCryptoLevel.java | |
parent | 34d19eb8f259f911f54db7bdea486ba830a5c599 (diff) | |
download | aports-3991e58da736e29cd687b150644fe6c1317b6750.tar.bz2 aports-3991e58da736e29cd687b150644fe6c1317b6750.tar.xz |
testing/openjdk13: New aport
Diffstat (limited to 'testing/openjdk13/TestCryptoLevel.java')
-rw-r--r-- | testing/openjdk13/TestCryptoLevel.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/openjdk13/TestCryptoLevel.java b/testing/openjdk13/TestCryptoLevel.java new file mode 100644 index 0000000000..3ed6c8dc15 --- /dev/null +++ b/testing/openjdk13/TestCryptoLevel.java @@ -0,0 +1,72 @@ +/* TestCryptoLevel -- Ensure unlimited crypto policy is in use. + Copyright (C) 2012 Red Hat, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program 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 Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; + +import java.security.Permission; +import java.security.PermissionCollection; + +public class TestCryptoLevel +{ + public static void main(String[] args) + throws NoSuchFieldException, ClassNotFoundException, + IllegalAccessException, InvocationTargetException + { + Class<?> cls = null; + Method def = null, exempt = null; + + try + { + cls = Class.forName("javax.crypto.JceSecurity"); + } + catch (ClassNotFoundException ex) + { + System.err.println("Running a non-Sun JDK."); + System.exit(0); + } + try + { + def = cls.getDeclaredMethod("getDefaultPolicy"); + exempt = cls.getDeclaredMethod("getExemptPolicy"); + } + catch (NoSuchMethodException ex) + { + System.err.println("Running IcedTea with the original crypto patch."); + System.exit(0); + } + def.setAccessible(true); + exempt.setAccessible(true); + PermissionCollection defPerms = (PermissionCollection) def.invoke(null); + PermissionCollection exemptPerms = (PermissionCollection) exempt.invoke(null); + Class<?> apCls = Class.forName("javax.crypto.CryptoAllPermission"); + Field apField = apCls.getDeclaredField("INSTANCE"); + apField.setAccessible(true); + Permission allPerms = (Permission) apField.get(null); + if (defPerms.implies(allPerms) && (exemptPerms == null || exemptPerms.implies(allPerms))) + { + System.err.println("Running with the unlimited policy."); + System.exit(0); + } + else + { + System.err.println("WARNING: Running with a restricted crypto policy."); + System.exit(-1); + } + } +} |