OSDN Git Service

2009-04-26 Matthias Klose <doko@ubuntu.com>
authordoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 26 Apr 2009 14:11:58 +0000 (14:11 +0000)
committerdoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 26 Apr 2009 14:11:58 +0000 (14:11 +0000)
        * contrib/aot-compile.in: Print diagnostics for malformed or invalid
        class files.
        * contrib/generate-cacerts.pl.in: New.
        * configure.ac (AC_CONFIG_FILES): Add generate-cacerts.pl.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146802 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/configure
libjava/configure.ac
libjava/contrib/aotcompile.py.in
libjava/contrib/generate-cacerts.pl.in [new file with mode: 0644]

index a86ffcf..878797a 100644 (file)
@@ -1,3 +1,10 @@
+2009-04-26  Matthias Klose <doko@ubuntu.com>
+
+       * contrib/aot-compile.in: Print diagnostics for malformed or invalid
+       class files.
+       * contrib/generate-cacerts.pl.in: New.
+       * configure.ac (AC_CONFIG_FILES): Add generate-cacerts.pl.
+
 2009-04-24  Matthias Klose  <doko@ubuntu.com>
 
        * configure.ac: Create missing directory gnu/java/security/jce/prng.
index b3d5394..ffb4682 100755 (executable)
@@ -28312,7 +28312,7 @@ echo "${ECHO_T}arch directory: ${host_cpu}" >&6
 
 fi
 
-                                                                                                              ac_config_files="$ac_config_files Makefile libgcj.pc libgcj.spec libgcj-test.spec gcj/Makefile include/Makefile testsuite/Makefile contrib/aotcompile.py contrib/aot-compile contrib/aot-compile-rpm contrib/rebuild-gcj-db"
+                                                                                                                        ac_config_files="$ac_config_files Makefile libgcj.pc libgcj.spec libgcj-test.spec gcj/Makefile include/Makefile testsuite/Makefile contrib/aotcompile.py contrib/aot-compile contrib/aot-compile-rpm contrib/generate-cacerts.pl contrib/rebuild-gcj-db"
 
 
 if test ${multilib} = yes; then
@@ -29562,6 +29562,7 @@ do
   "contrib/aotcompile.py" ) CONFIG_FILES="$CONFIG_FILES contrib/aotcompile.py" ;;
   "contrib/aot-compile" ) CONFIG_FILES="$CONFIG_FILES contrib/aot-compile" ;;
   "contrib/aot-compile-rpm" ) CONFIG_FILES="$CONFIG_FILES contrib/aot-compile-rpm" ;;
+  "contrib/generate-cacerts.pl" ) CONFIG_FILES="$CONFIG_FILES contrib/generate-cacerts.pl" ;;
   "contrib/rebuild-gcj-db" ) CONFIG_FILES="$CONFIG_FILES contrib/rebuild-gcj-db" ;;
   "scripts/jar" ) CONFIG_FILES="$CONFIG_FILES scripts/jar" ;;
   "include/platform.h" ) CONFIG_LINKS="$CONFIG_LINKS include/platform.h:include/$PLATFORMH" ;;
index f558e34..05d2371 100644 (file)
@@ -1923,6 +1923,7 @@ testsuite/Makefile
 contrib/aotcompile.py
 contrib/aot-compile
 contrib/aot-compile-rpm
+contrib/generate-cacerts.pl
 contrib/rebuild-gcj-db
 ])
 
index 9e25c90..9db08d2 100644 (file)
@@ -177,11 +177,14 @@ class Job:
     
     def __init__(self, path):
         self.path, self.classes, self.blocks = path, {}, None
+        self.classnames = {}
 
-    def addClass(self, bytes):
+    def addClass(self, bytes, name):
         """Subclasses call this from their __init__ method for
         every class they find."""
-        self.classes[md5.new(bytes).digest()] = bytes
+        digest = md5.new(bytes).digest()
+        self.classes[digest] = bytes
+        self.classnames[digest] = name
 
     def __makeBlocks(self):
         """Split self.classes into chunks that can be compiled to
@@ -200,7 +203,12 @@ class Job:
         if the job is subsetted."""
         names = {}
         for hash, bytes in self.classes.items():
-            name = classname(bytes)
+            try:
+                name = classname(bytes)
+            except:
+                warn("job %s: class %s malformed or not a valid class file" \
+                     % (self.path, self.classnames[hash]))
+                raise
             if not names.has_key(name):
                 names[name] = []
             names[name].append(hash)
@@ -302,7 +310,7 @@ class JarJob(Job):
             if bytes.startswith(ZIPMAGIC):
                 self._walk(zipfile.ZipFile(StringIO.StringIO(bytes)))
             elif bytes.startswith(CLASSMAGIC):
-                self.addClass(bytes)
+                self.addClass(bytes, name)
 
 class DirJob(Job):
     """A Job whose origin was a directory of classfiles."""
@@ -319,7 +327,7 @@ class DirJob(Job):
             fp = open(path, "r")
             magic = fp.read(4)
             if magic == CLASSMAGIC:
-                self.addClass(magic + fp.read())
+                self.addClass(magic + fp.read(), name)
     
 def weed_jobs(jobs):
     """Remove any jarfiles that are completely contained within
diff --git a/libjava/contrib/generate-cacerts.pl.in b/libjava/contrib/generate-cacerts.pl.in
new file mode 100644 (file)
index 0000000..b90f6ef
--- /dev/null
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2007, 2009 Free Software Foundation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 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 General Public License for more details.
+
+# generate-cacerts.pl generates a gkeytool keystore named 'cacerts'
+# from OpenSSL's certificate bundle.
+
+# First extract each of OpenSSL's bundled certificates into its own
+# aliased filename.
+chomp($file=@ARGV[0]);
+$file = "/etc/pki/tls/cert.pem" unless $file ne "";
+open(CERTS, $file);
+@certs = <CERTS>;
+close(CERTS);
+
+$pem_file_number = 0;
+$writing_cert = 0;
+foreach $cert (@certs)
+{
+        if ($cert eq "-----BEGIN CERTIFICATE-----\n")
+        {
+                 if ($writing_cert != 0)
+                 {
+                               die "$file is malformed.";
+                 }
+                 $pem_file_number++;
+                 # Numbering each file guarantees that cert aliases will be
+                 # unique.
+                 $pem_file_name = "$pem_file_number$cert_alias.pem";
+                 $writing_cert = 1;
+                 open(PEM, ">$pem_file_name");
+                 print PEM $cert;
+        }
+        elsif ($cert eq "-----END CERTIFICATE-----\n")
+        {
+                 $writing_cert = 0;
+                 print PEM $cert;
+                 close(PEM);
+        }
+        elsif ($cert =~ /Issuer: /)
+        {
+                 # Generate an alias using the OU and CN attributes of the
+                 # Issuer field if both are present, otherwise use only the CN
+                 # attribute.  The Issuer field must have either the OU or the
+                 # CN attribute.
+                 $_ = $cert;
+                 if ($cert =~ /OU=/)
+                 {
+                               s/Issuer:.*?OU=//;
+                               # Remove other occurrences of OU=.
+                               s/OU=.*CN=//;
+                               # Remove CN= if there were not other occurrences of OU=.
+                               s/CN=//;
+                 }
+                 elsif ($cert =~ /CN=/)
+                 {
+                               s/Issuer:.*CN=//;
+                 }
+                 s/\W//g;
+                 tr/A-Z/a-z/;
+                 $cert_alias = $_
+        }
+        else
+        {
+                 if ($writing_cert == 1)
+                 {
+                               print PEM $cert;
+                 }
+        }
+}
+
+# Check that the correct number of .pem files were produced.
+@pem_files = <*.pem>;
+if (@pem_files != $pem_file_number)
+{
+        die "Number of .pem files produced does not match".
+                 " number of certs read from $file.";
+}
+
+# Now store each cert in the 'cacerts' file using gkeytool.
+$certs_written_count = 0;
+foreach $pem_file (@pem_files)
+{
+        system "yes | gkeytool@gcc_suffix@ -import -alias `basename $pem_file .pem`".
+                 " -keystore cacerts -storepass '' -file $pem_file".
+                 " 2>&1 >/dev/null";
+        unlink($pem_file);
+        $certs_written_count++;
+}
+
+# Check that the correct number of certs were added to the keystore.
+if ($certs_written_count != $pem_file_number)
+{
+        die "Number of certs added to keystore does not match".
+                 " number of certs read from $file.";
+}