felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1366310 - /felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java
Date Fri, 27 Jul 2012 08:51:13 GMT
Author: gnodet
Date: Fri Jul 27 08:51:13 2012
New Revision: 1366310

URL: http://svn.apache.org/viewvc?rev=1366310&view=rev
Log:
FELIX-3603: make sure the JarVerifier does not skip signed META-INF entries

Modified:
    felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java

Modified: felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java?rev=1366310&r1=1366309&r2=1366310&view=diff
==============================================================================
--- felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java
(original)
+++ felix/trunk/framework.security/src/main/java/org/apache/felix/framework/security/util/BundleInputStream.java
Fri Jul 27 08:51:13 2012
@@ -46,6 +46,8 @@ public final class BundleInputStream ext
     private ByteArrayInputStream m_buffer = null;
     private JarOutputStream m_output = null;
 
+    private static final String DUMMY_ENTRY = "__DUMMY-ENTRY__/";
+
     public BundleInputStream(Content root) throws IOException
     {
         m_root = root;
@@ -53,6 +55,7 @@ public final class BundleInputStream ext
         List entries = new ArrayList();
 
         int count = 0;
+        boolean inMetaInf = true;
         String manifest = null;
         for (Enumeration e = m_root.getEntries(); e.hasMoreElements();)
         {
@@ -68,7 +71,8 @@ public final class BundleInputStream ext
                     manifest = entry;
                 }
             }
-            else if (entry.toUpperCase().startsWith("META-INF/"))
+            else if (entry.toUpperCase().startsWith("META-INF/")
+                        && entry.indexOf('/', "META-INF/".length()) < 0)
             {
                 entries.add(count++, entry);
             }
@@ -77,6 +81,7 @@ public final class BundleInputStream ext
                 entries.add(entry);
             }
         }
+        entries.add(count++, DUMMY_ENTRY);
         if (manifest == null)
         {
             manifest = "META-INF/MANIFEST.MF";
@@ -150,38 +155,47 @@ public final class BundleInputStream ext
     {
         m_outputBuffer.m_outBuffer = new ByteArrayOutputStream();
 
-        InputStream in = null;
-        try
+        if (path == DUMMY_ENTRY)
         {
-            in = m_root.getEntryAsStream(path);
-
-            if (in == null)
-            {
-                throw new IOException("Missing entry");
-            }
-
             JarEntry entry = new JarEntry(path);
 
             m_output.putNextEntry(entry);
-
-            byte[] buffer = new byte[4 * 1024];
-
-            for (int c = in.read(buffer); c != -1; c = in.read(buffer))
-            {
-                m_output.write(buffer, 0, c);
-            }
         }
-        finally
+        else
         {
-            if (in != null)
+            InputStream in = null;
+            try
             {
-                try
+                in = m_root.getEntryAsStream(path);
+
+                if (in == null)
+                {
+                    throw new IOException("Missing entry");
+                }
+
+                JarEntry entry = new JarEntry(path);
+
+                m_output.putNextEntry(entry);
+
+                byte[] buffer = new byte[4 * 1024];
+
+                for (int c = in.read(buffer); c != -1; c = in.read(buffer))
                 {
-                    in.close();
+                    m_output.write(buffer, 0, c);
                 }
-                catch (Exception ex)
+            }
+            finally
+            {
+                if (in != null)
                 {
-                    // Not much we can do
+                    try
+                    {
+                        in.close();
+                    }
+                    catch (Exception ex)
+                    {
+                        // Not much we can do
+                    }
                 }
             }
         }



Mime
View raw message