incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r917766 - /incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
Date Mon, 01 Mar 2010 22:40:19 GMT
Author: gawor
Date: Mon Mar  1 22:40:19 2010
New Revision: 917766

URL: http://svn.apache.org/viewvc?rev=917766&view=rev
Log:
ARIES-208: Deal with signed war files. Remove signature file and remove Digest attributes
from manifest

Modified:
    incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java

Modified: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java?rev=917766&r1=917765&r2=917766&view=diff
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
(original)
+++ incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
Mon Mar  1 22:40:19 2010
@@ -74,6 +74,7 @@
   private Set<String> exemptPackages;
   private Map<String, Manifest> manifests; 
   private ArrayList<String> classPath;
+  private boolean signed;
 
   public WarToWabConverterImpl(InputStreamProvider warFile, String name, Properties properties)
throws IOException {
       this(warFile, name, new CaseInsensitiveMap(properties));
@@ -131,6 +132,10 @@
       jarInput = new JarInputStream(input.getInputStream());
       byte[] buffer = new byte[2048];
       while ((entry = jarInput.getNextEntry()) != null) {
+        // skip signature files if war is signed
+        if (signed && isSignatureFile(entry.getName())) {
+            continue;
+        }
         jarOutput.putNextEntry(entry);        
         while ((val = jarInput.read(buffer)) > 0) {
           jarOutput.write(buffer, 0, val);
@@ -262,6 +267,9 @@
     if (manifest == null) {
       manifest = new Manifest();
       manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1");
+    } else {
+      // remove digest attributes if was is signed
+      signed = removeDigestAttributes(manifest);
     }
     
     // Compare the manifest and the supplied properties
@@ -481,6 +489,36 @@
       return list;
   }
   
+  private static boolean removeDigestAttributes(Manifest manifest) {
+      boolean foundDigestAttribute = false;
+      for (Map.Entry<String, Attributes> entry : manifest.getEntries().entrySet())
{
+          Attributes attributes = entry.getValue();
+          for (Object attributeName : attributes.keySet()) {    
+              String name = ((Attributes.Name) attributeName).toString();
+              name = name.toLowerCase();
+              if (name.endsWith("-digest") || name.contains("-digest-")) {
+                  attributes.remove(attributeName);
+                  foundDigestAttribute = true;
+              }
+          }
+      }
+      return foundDigestAttribute;
+  }
+  
+  private static boolean isSignatureFile(String entryName) {
+      String[] parts = entryName.split("/");
+      if (parts.length == 2) {
+          String name = parts[1].toLowerCase();
+          return (parts[0].equals("META-INF") &&
+                  (name.endsWith(".sf") || 
+                   name.endsWith(".dsa") || 
+                   name.endsWith(".rsa") || 
+                   name.startsWith("sig-")));
+      } else {
+          return false;
+      }
+  }
+  
   public InputStream getWAB() throws IOException {
     convert();
     return wab.getInputStream();



Mime
View raw message