changeset 2637:080f4776a2f8

PR1170: Ensure unlimited crypto policy is in place. 2013-06-05 Andrew John Hughes <gnu.andrew@member.fsf.org> PR1170: Ensure unlimited crypto policy is in place. * Makefile.am: (CRYPTO_CHECK_BUILD_DIR): New variable. (EXTRA_DIST): Add TestCryptoLevel.java (.PHONY): Add new clean targets. (check-crypto): Run the crypto checker on a normal stage 2 build. (clean-check-crypto): Delete the check-crypto stamp. (check-crypto-debug): Run the crypto checker on a debug stage 2 build. (clean-check-crypto-debug): Delete the check-crypto-debug stamp. (icedtea-stage2): Depend on check-crypto. (clean-icedtea-stage2): Depend on clean-check-crypto. (icedtea-debug-stage2): Depend on check-crypto-debug. (clean-icedtea-debug-stage2): Depend on clean-check-crypto-debug. (check-crypto-boot): Run the crypto checker on the stage 1 build. (clean-check-crypto-boot): Delete the check-crypto-boot stamp. (icedtea-stage1): Depend on check-crypto-boot. (clean-icedtea-stage1): Depend on clean-check-crypto-boot. (cryptocheck): Build the crypto checker. (clean-cryptocheck): Revert cryptocheck. * NEWS: Updated. * TestCryptoLevel.java: Checks whether the unlimited crypto policy is in place or not.
author Andrew John Hughes <gnu_andrew@member.fsf.org>
date Wed, 05 Jun 2013 20:59:33 +0100
parents 02bbff3d71ff
children 609b5317bd98
files ChangeLog Makefile.am NEWS TestCryptoLevel.java
diffstat 4 files changed, 177 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 23 11:26:52 2013 +0100
+++ b/ChangeLog	Wed Jun 05 20:59:33 2013 +0100
@@ -1,3 +1,36 @@
+2013-06-05  Andrew John Hughes  <gnu.andrew@member.fsf.org>
+
+	PR1170: Ensure unlimited crypto policy is in place.
+	* Makefile.am:
+	(CRYPTO_CHECK_BUILD_DIR): New variable.
+	(EXTRA_DIST): Add TestCryptoLevel.java
+	(.PHONY): Add new clean targets.
+	(check-crypto): Run the crypto checker on a normal
+	stage 2 build.
+	(clean-check-crypto): Delete the check-crypto stamp.
+	(check-crypto-debug): Run the crypto checker on a
+	debug stage 2 build.
+	(clean-check-crypto-debug): Delete the
+	check-crypto-debug stamp.
+	(icedtea-stage2): Depend on check-crypto.
+	(clean-icedtea-stage2): Depend on clean-check-crypto.
+	(icedtea-debug-stage2): Depend on check-crypto-debug.
+	(clean-icedtea-debug-stage2): Depend on
+	clean-check-crypto-debug.
+	(check-crypto-boot): Run the crypto checker on
+	the stage 1 build.
+	(clean-check-crypto-boot): Delete the
+	check-crypto-boot stamp.
+	(icedtea-stage1): Depend on check-crypto-boot.
+	(clean-icedtea-stage1): Depend on
+	clean-check-crypto-boot.
+	(cryptocheck): Build the crypto checker.
+	(clean-cryptocheck): Revert cryptocheck.
+	* NEWS: Updated.
+	* TestCryptoLevel.java:
+	Checks whether the unlimited crypto policy is in
+	place or not.
+
 2013-05-23  Andrew John Hughes  <gnu.andrew@member.fsf.org>
 
 	* NEWS: Update with fixes brought in by latest
--- a/Makefile.am	Thu May 23 11:26:52 2013 +0100
+++ b/Makefile.am	Wed Jun 05 20:59:33 2013 +0100
@@ -66,6 +66,7 @@
 STAGE1_BOOT_DIR = $(abs_top_builddir)/bootstrap/boot
 STAGE2_BOOT_DIR = $(abs_top_builddir)/bootstrap/icedtea
 JAMVM_IMPORT_PATH = $(abs_top_builddir)/jamvm/install/hotspot
+CRYPTO_CHECK_BUILD_DIR = $(abs_top_builddir)/cryptocheck.build
 
 # Source directories
 
@@ -251,6 +252,7 @@
 # Sources list
 
 REWRITER_SRCS = $(top_srcdir)/rewriter/com/redhat/rewriter/ClassRewriter.java
+CRYPTO_CHECK_SRCS = $(top_srcdir)/TestCryptoLevel.java
 
 # Patch list
 
@@ -774,7 +776,8 @@
 	scripts/jni_desc \
 	rewriter/agpl-3.0.txt \
 	$(REWRITER_SRCS) \
-	THANKYOU test/tapset
+	THANKYOU test/tapset \
+	$(CRYPTO_CHECK_SRCS)
 
 # Top-Level Targets
 # =================
@@ -831,7 +834,8 @@
 	clean-tests clean-tapset-report clean-add-systemtap \
 	clean-add-systemtap-debug clean-add-pulseaudio clean-add-pulseaudio-debug \
 	clean-add-nss clean-add-tzdata-support clean-add-tzdata-support-debug \
-	clean-add-systemtap-boot clean-add-pulseaudio-boot clean-add-tzdata-support-boot
+	clean-add-systemtap-boot clean-add-pulseaudio-boot clean-add-tzdata-support-boot \
+	clean-check-crypto clean-check-crypto-debug clean-check-crypto-boot
 
 env:
 	@echo 'unset JAVA_HOME'
@@ -1802,6 +1806,16 @@
 	fi
 	rm -f stamps/add-tzdata-support.stamp
 
+stamps/check-crypto.stamp: stamps/cryptocheck.stamp
+	if [ -e $(BUILD_OUTPUT_DIR)/j2sdk-image/bin/java ] ; then \
+	  $(BUILD_OUTPUT_DIR)/j2sdk-image/bin/java -cp $(CRYPTO_CHECK_BUILD_DIR) TestCryptoLevel ; \
+	fi
+	mkdir -p stamps
+	touch $@
+
+clean-check-crypto:
+	rm -f stamps/check-crypto.stamp
+
 stamps/icedtea-debug.stamp: stamps/bootstrap-directory-symlink-stage2.stamp \
  stamps/download.stamp stamps/extract.stamp $(OPENJDK_TREE) \
  stamps/cacao.stamp stamps/rewrite-rhino.stamp stamps/jamvm.stamp
@@ -1904,23 +1918,33 @@
 	fi
 	rm -f stamps/add-tzdata-support-debug.stamp
 
-stamps/icedtea-stage2.stamp: stamps/icedtea.stamp stamps/add-cacao.stamp \
- stamps/add-zero.stamp stamps/add-jamvm.stamp stamps/add-systemtap.stamp \
- stamps/add-pulseaudio.stamp stamps/add-tzdata-support.stamp
+stamps/check-crypto-debug.stamp: stamps/cryptocheck.stamp
+	if [ -e $(DEBUG_BUILD_OUTPUT_DIR)/j2sdk-image/bin/java ] ; then \
+	  $(DEBUG_BUILD_OUTPUT_DIR)/j2sdk-image/bin/java -cp $(CRYPTO_CHECK_BUILD_DIR) TestCryptoLevel ; \
+	fi
 	mkdir -p stamps
 	touch $@
 
-clean-icedtea-stage2: clean-add-jamvm
+clean-check-crypto-debug:
+	rm -f stamps/check-crypto-debug.stamp
+
+stamps/icedtea-stage2.stamp: stamps/icedtea.stamp stamps/add-cacao.stamp \
+ stamps/add-zero.stamp stamps/add-jamvm.stamp stamps/add-systemtap.stamp \
+ stamps/add-pulseaudio.stamp stamps/add-tzdata-support.stamp stamps/check-crypto.stamp
+	mkdir -p stamps
+	touch $@
+
+clean-icedtea-stage2: clean-add-jamvm clean-check-crypto
 	rm -f stamps/icedtea-stage2.stamp
 
 stamps/icedtea-debug-stage2.stamp: stamps/icedtea-debug.stamp \
  stamps/add-cacao-debug.stamp stamps/add-zero-debug.stamp stamps/add-jamvm-debug.stamp \
  stamps/add-systemtap-debug.stamp stamps/add-pulseaudio-debug.stamp \
- stamps/add/tzdata-support-debug.stamp
+ stamps/add/tzdata-support-debug.stamp stamps/check-crypto-debug.stamp
 	mkdir -p stamps
 	touch $@
 
-clean-icedtea-debug-stage2: clean-add-jamvm-debug
+clean-icedtea-debug-stage2: clean-add-jamvm-debug clean-check-crypto-debug
 	rm -f stamps/icedtea-debug-stage2.stamp
 
 # OpenJDK boot Targets
@@ -2012,14 +2036,24 @@
 	fi
 	rm -f stamps/add-tzdata-support-boot.stamp
 
+stamps/check-crypto-boot.stamp: stamps/cryptocheck.stamp
+	if [ -e $(BOOT_BUILD_OUTPUT_DIR)/j2sdk-image/bin/java ] ; then \
+	  $(BOOT_BUILD_OUTPUT_DIR)/j2sdk-image/bin/java -cp $(CRYPTO_CHECK_BUILD_DIR) TestCryptoLevel ; \
+	fi
+	mkdir -p stamps
+	touch $@
+
+clean-check-crypto-boot:
+	rm -f stamps/check-crypto-boot.stamp
+
 stamps/icedtea-stage1.stamp: stamps/icedtea-boot.stamp \
  stamps/add-systemtap-boot.stamp stamps/add-pulseaudio-boot.stamp \
- stamps/add-tzdata-support-boot.stamp
+ stamps/add-tzdata-support-boot.stamp stamps/check-crypto-boot.stamp
 	mkdir -p stamps
 	touch $@
 
 clean-icedtea-stage1: clean-add-systemtap-boot clean-add-pulseaudio-boot \
- clean-add-tzdata-support-boot
+ clean-add-tzdata-support-boot clean-check-crypto-boot
 	rm -f stamps/icedtea-stage1.stamp
 
 # Rebuild targets
@@ -2582,6 +2616,19 @@
 	  cp $(SYSTEM_JDK_DIR)/jre/lib/rt.jar $(STAGE1_BOOT_DIR)/jre/lib ; \
 	fi
 
+# Crypto Level Check
+
+stamps/cryptocheck.stamp: $(INITIAL_BOOTSTRAP_LINK_STAMP)
+	mkdir -p $(CRYPTO_CHECK_BUILD_DIR)
+	$(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \
+	  -d $(CRYPTO_CHECK_BUILD_DIR) $(CRYPTO_CHECK_SRCS)
+	mkdir -p stamps
+	touch $@
+
+clean-cryptocheck:
+	rm -rf $(CRYPTO_CHECK_BUILD_DIR)
+	rm -f stamps/cryptocheck.stamp
+
 # Target Aliases
 # ===============
 
@@ -2615,8 +2662,16 @@
 
 cacao: stamps/cacao.stamp
 
+check-crypto: stamps/check-crypto.stamp
+
+check-crypto-boot: stamps/check-crypto-boot.stamp
+
+check-crypto-debug: stamps/check-crypto-debug.stamp
+
 clone-boot: stamps/clone-boot.stamp
 
+cryptocheck: stamps/cryptocheck.stamp
+
 download: stamps/download.stamp
 
 download-cacao: stamps/download-cacao.stamp
--- a/NEWS	Thu May 23 11:26:52 2013 +0100
+++ b/NEWS	Wed Jun 05 20:59:33 2013 +0100
@@ -809,6 +809,7 @@
   - Include defs.make in buildtree.make so ZERO_BUILD is recognised and JVM_VARIANT_ZERO set.
   - Make sure libffi cflags and libs are used.
   - PR1378: Add AArch64 support to Zero
+  - PR1170: Ensure unlimited crypto policy is in place.
 * CACAO
   - src/vm/jit/x86_64/asmpart.S (asm_abstractmethoderror): Keep stack aligned.
   - src/native/jni.cpp (GetObjectClass): Remove null pointer check.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestCryptoLevel.java	Wed Jun 05 20:59:33 2013 +0100
@@ -0,0 +1,78 @@
+/* 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);
+      }
+  }
+}