Mercurial > hg > icedtea7
view test/standalone/TestCryptoLevel.java @ 2879:2fbb359cc3c7
PR3115: Add check for elliptic curve cryptography implementation.
2015-05-20 Andrew John Hughes <gnu_andrew@member.fsf.org>
PR3115: Add check for elliptic curve
cryptography implementation.
* TestCryptoLevel.java: Moved to
test/standalone.
* rewriter/agpl-3.0.txt: Moved to
root directory.
* test/RH1195203.java: Likewise.
* Makefile.am:
(ECC_CHECK_BUILD_DIR): Added.
(CRYPTO_CHECK_SRCS): Update TestCryptoLevel.java
path.
(ECC_CHECK_SRCS): Added.
(MIME_TYPE_CHECK_SRCS): Update path.
(EXTRA_DIST): Add ECC_CHECK_SRCS.
(check-local): Add check-ecc.
(clean-tests): Add clean-check-ecc.
(clean-local): Add clean-ecccheck.
(ecccheck): Build ECC check test.
(clean-ecccheck): Cleanup ECC check test.
(check-ecc): Run ECC check test.
(clean-check-ecc): Cleanup run of ECC check test.
* NEWS: Updated.
* agpl-3.0.txt: Moved from rewriter as also
applies to tests.
* test/standalone/RH1195203.java: Moved from test.
* test/standalone/TestCryptoLevel.java: Moved from
root directory.
* test/standalone/TestEllipticCurveCryptoSupport.java:
Add check for elliptic curve cryptography support.
author | Andrew John Hughes <gnu_andrew@member.fsf.org> |
---|---|
date | Thu, 28 Jul 2016 03:46:39 +0100 |
parents | TestCryptoLevel.java@080f4776a2f8 |
children |
line wrap: on
line source
/* 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); } catch (ExceptionInInitializerError err) { System.err.println("Failed to initialise JceSecurity: " + err.getCause().getCause().getMessage()); System.exit(-2); } 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); } } }