]> source.dussan.org Git - poi.git/commitdiff
[bug-63725] commons-compress 1.19
authorPJ Fanning <fanningpj@apache.org>
Wed, 4 Sep 2019 16:55:00 +0000 (16:55 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 4 Sep 2019 16:55:00 +0000 (16:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866402 13f79535-47bb-0310-9956-ffa450edef68

.classpath
build.gradle
build.xml
maven/poi-ooxml.pom
sonar/ooxml/pom.xml
src/ooxml/java/org/apache/poi/ooxml/util/DocumentHelper.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java
src/testcases/org/apache/poi/POIDataSamples.java

index a93222b2ea8211c5f1edcc0be3269edde1f04ec5..3ec3aa21326409c6208b223f9d16746a4ac77836 100644 (file)
@@ -40,7 +40,7 @@
        <classpathentry kind="lib" path="lib/commons-math3-3.6.1.jar"/>
        <classpathentry kind="lib" path="lib/xmlunit-core-2.5.1.jar"/>
        <classpathentry kind="lib" path="lib/objenesis-2.6.jar"/>
-       <classpathentry kind="lib" path="lib/commons-compress-1.18.jar"/>
+       <classpathentry kind="lib" path="lib/commons-compress-1.19.jar"/>
        <classpathentry kind="lib" path="lib/mockito-core-3.0.0.jar"/>
        <classpathentry kind="lib" path="lib/byte-buddy-1.10.1.jar"/>
        <classpathentry kind="lib" path="lib/byte-buddy-agent-1.10.1.jar"/>
index 430f948b5e4d27c58e2622a2443bda565c2a72b6..1123e4790f8a276258b01e3c3574ae6000279c45 100644 (file)
@@ -233,7 +233,7 @@ project('ooxml') {
         compile 'org.apache.xmlbeans:xmlbeans:3.1.0'
         compile 'org.apache.commons:commons-collections4:4.4'
         compile 'org.apache.commons:commons-math3:3.6.1'
-        compile 'org.apache.commons:commons-compress:1.18'
+        compile 'org.apache.commons:commons-compress:1.19'
         compile 'org.apache.santuario:xmlsec:2.1.2'
         compile 'org.bouncycastle:bcpkix-jdk15on:1.62'
         compile 'com.github.virtuald:curvesapi:1.06'
index 9536ac79c8d280b984e80fe7cf7f11424291dab9..5bb7230bd06ed2adb6566abe2d256be0ce1f9bda 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -244,9 +244,9 @@ under the License.
     <property name="ooxml.xmlbeans.jar" location="${ooxml.lib}/xmlbeans-3.1.0.jar"/>
     <property name="ooxml.xmlbeans.url"
               value="https://repository.apache.org/content/repositories/releases/org/apache/xmlbeans/xmlbeans/3.1.0/xmlbeans-3.1.0.jar"/>
-    <property name="ooxml.commons-compress.jar" location="${main.lib}/commons-compress-1.18.jar"/>
+    <property name="ooxml.commons-compress.jar" location="${main.lib}/commons-compress-1.19.jar"/>
     <property name="ooxml.commons-compress.url"
-              value="${repository.m2}/maven2/org/apache/commons/commons-compress/1.18/commons-compress-1.18.jar"/>
+              value="${repository.m2}/maven2/org/apache/commons/commons-compress/1.19/commons-compress-1.19.jar"/>
 
     <!-- jars in the ooxml-test-lib directory, see the fetch-ooxml-jars target-->
     <property name="ooxml.test.reflections.jar" location="${ooxml.test.lib}/reflections.jar"/>
@@ -652,6 +652,7 @@ under the License.
                 <include name="commons-codec-1.12*"/>
                 <include name="commons-compress-1.16*"/>
                 <include name="commons-compress-1.17*"/>
+                <include name="commons-compress-1.18*"/>
                 <include name="commons-collections4-4.1*"/>
                 <include name="commons-collections4-4.2*"/>
                 <include name="commons-collections4-4.3*"/>
index b885c8c4be55523154f4bceb24ba28192fda3ead..e4b40365dc2f0c6ecc4317561ad9a0134ad23e4b 100644 (file)
@@ -72,7 +72,7 @@
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-compress</artifactId>
-      <version>1.18</version>
+      <version>1.19</version>
     </dependency>
     <dependency>
       <groupId>com.github.virtuald</groupId>
index 4737fd05accddd303c97cad4b8473c5d48493593..c778f439b688545945d20e1eb723f2f7cd0acbce 100644 (file)
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-compress</artifactId>
-            <version>1.18</version>
+            <version>1.19</version>
         </dependency>
         <dependency>
             <groupId>com.github.virtuald</groupId>
index ce8c4d046304db668f04212bd1e791257ae8f179..8fe643d76430856d8232cd0a584d28af22b9a1d6 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.ooxml.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.concurrent.TimeUnit;
 
@@ -27,11 +28,15 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.events.Namespace;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.w3c.dom.*;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -97,6 +102,33 @@ public final class DocumentHelper {
         }
     }
 
+    public static String domToString(Node node) throws Exception {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer();
+        t.setOutputProperty(OutputKeys.INDENT, "yes");
+        StringWriter sw = new StringWriter();
+        t.transform(new DOMSource(node), new StreamResult(sw));
+        return sw.toString();
+    }
+
+    public static Attr findIdAttr(Element e, String name) throws Exception {
+        Attr att = e.getAttributeNode("Id");
+        if(att != null && name.equals(att.getValue())) {
+            return att;
+        }
+        NodeList nl = e.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node child = nl.item(i);
+            if (child instanceof Element) {
+                Attr x = findIdAttr((Element)child, name);
+                if (x != null) {
+                    return x;
+                }
+            }
+        }
+        return null;
+    }
+
     static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
     static {
         documentBuilderFactory.setNamespaceAware(true);
index c8f04e882407fa3f64a09dddb37a8c10593c6dc3..d8da2e1f031eb476f671cb58503d252cd5dcee41 100644 (file)
@@ -70,8 +70,7 @@ import org.etsi.uri.x01903.v13.SignedSignaturePropertiesType;
 import org.etsi.uri.x01903.v13.SignerRoleType;
 import org.w3.x2000.x09.xmldsig.DigestMethodType;
 import org.w3.x2000.x09.xmldsig.X509IssuerSerialType;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
+import org.w3c.dom.*;
 
 /**
  * XAdES Signature Facet. Implements XAdES v1.4.1 which is compatible with XAdES
@@ -224,10 +223,32 @@ public class XAdESSignatureFacet extends SignatureFacet {
     private XMLObject addXadesObject(Document document, QualifyingPropertiesType qualifyingProperties) {
         Node qualDocElSrc = qualifyingProperties.getDomNode();
         Node qualDocEl = document.importNode(qualDocElSrc, true);
+        markIds(qualDocEl);
         List<XMLStructure> xadesObjectContent = Arrays.asList(new DOMStructure(qualDocEl));
         return getSignatureFactory().newXMLObject(xadesObjectContent, null, null, null);
     }
 
+    private void markIds(Node node) {
+        if (node instanceof Element) {
+            markIds((Element)node);
+        } else if (node instanceof Document) {
+            markIds(((Document)node).getDocumentElement());
+        }
+    }
+
+    private void markIds(Element element) {
+        if (element != null) {
+            Attr att = element.getAttributeNode("Id");
+            if (att != null) {
+                element.setIdAttributeNode(att, true);
+            }
+            NodeList nl = element.getChildNodes();
+            for (int i = 0; i < nl.getLength(); i++) {
+                markIds(nl.item(i));
+            }
+        }
+    }
+
     private Reference addXadesReference() throws XMLSignatureException {
         List<Transform> transforms = singletonList(newTransform(CanonicalizationMethod.INCLUSIVE));
         return newReference("#"+signatureConfig.getXadesSignatureId(), transforms, XADES_TYPE, null, null);
index 92db8fe18a47e4be70a5556b5a63d596af7e2b07..c571686f51ec525a5391b28dd787633dd1b6658b 100644 (file)
@@ -116,7 +116,10 @@ public final class POIDataSamples {
         return _instHSMF;
     }
 
-    public static POIDataSamples getXmlDSignInstance(){
+    public static POIDataSamples getXmlDSignInstance() {
+        if (System.getProperty(TEST_PROPERTY) == null) {
+            System.setProperty(TEST_PROPERTY, "../../test-data");
+        }
         if(_instXmlDSign == null) _instXmlDSign = new POIDataSamples("xmldsign");
         return _instXmlDSign;
     }