]> source.dussan.org Git - poi.git/commitdiff
Moved prefix logic in one place
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 28 Sep 2014 00:30:05 +0000 (00:30 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 28 Sep 2014 00:30:05 +0000 (00:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/xml_signature@1628029 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalListener.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/KeyInfoSignatureFacet.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/OOXMLSignatureFacet.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java

index 6878cde43649c44e6414250f0bfae803ab753d5f..880efa10eda10b372bd93703ff5aaf74e576c21e 100644 (file)
@@ -35,7 +35,6 @@ import javax.xml.crypto.dsig.CanonicalizationMethod;
 import org.apache.poi.EncryptedDocumentException;\r
 import org.apache.poi.openxml4j.opc.OPCPackage;\r
 import org.apache.poi.poifs.crypt.HashAlgorithm;\r
-import org.apache.poi.poifs.crypt.dsig.SignatureInfo.SignCreationListener;\r
 import org.apache.poi.poifs.crypt.dsig.facets.KeyInfoSignatureFacet;\r
 import org.apache.poi.poifs.crypt.dsig.facets.OOXMLSignatureFacet;\r
 import org.apache.poi.poifs.crypt.dsig.facets.Office2010SignatureFacet;\r
@@ -162,7 +161,7 @@ public class SignatureConfig {
         if (onlyValidation) return;\r
 \r
         if (signCreationListener == null) {\r
-            signCreationListener = new SignCreationListener();\r
+            signCreationListener = new SignatureMarshalListener();\r
         }\r
         \r
         if (signCreationListener instanceof SignatureConfigurable) {\r
index 6798067f3f817e19564df6aa5076b3cdbc46aa87..f846187ee6d8ceac6bb751186f9718c8eefe9a4c 100644 (file)
@@ -24,9 +24,7 @@
 \r
 package org.apache.poi.poifs.crypt.dsig;\r
 \r
-import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.OO_DIGSIG_NS;\r
 import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_DIGSIG_NS;\r
-import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_NS;\r
 import static org.apache.xml.security.signature.XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160;\r
 import static org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;\r
 import static org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;\r
@@ -82,6 +80,7 @@ import org.apache.jcp.xml.dsig.internal.dom.DOMReference;
 import org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo;\r
 import org.apache.poi.EncryptedDocumentException;\r
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
+import org.apache.poi.openxml4j.opc.ContentTypes;\r
 import org.apache.poi.openxml4j.opc.OPCPackage;\r
 import org.apache.poi.openxml4j.opc.PackagePart;\r
 import org.apache.poi.openxml4j.opc.PackagePartName;\r
@@ -107,12 +106,9 @@ import org.apache.xmlbeans.XmlOptions;
 import org.w3.x2000.x09.xmldsig.SignatureDocument;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
-import org.w3c.dom.Node;\r
 import org.w3c.dom.NodeList;\r
-import org.w3c.dom.events.Event;\r
 import org.w3c.dom.events.EventListener;\r
 import org.w3c.dom.events.EventTarget;\r
-import org.w3c.dom.events.MutationEvent;\r
 import org.xml.sax.SAXException;\r
 \r
 public class SignatureInfo implements SignatureConfigurable {\r
@@ -203,38 +199,6 @@ public class SignatureInfo implements SignatureConfigurable {
         }\r
     }\r
     \r
-    protected static class SignCreationListener implements EventListener, SignatureConfigurable {\r
-        ThreadLocal<EventTarget> target = new ThreadLocal<EventTarget>();\r
-        SignatureConfig signatureConfig;\r
-        public void setEventTarget(EventTarget target) {\r
-            this.target.set(target);\r
-        }\r
-        public void handleEvent(Event e) {\r
-            if (e instanceof MutationEvent) {\r
-                MutationEvent mutEvt = (MutationEvent)e;\r
-                EventTarget et = mutEvt.getTarget();\r
-                if (et instanceof Element) {\r
-                    Element el = (Element)mutEvt.getTarget();\r
-                    String packageId = signatureConfig.getPackageSignatureId();\r
-                    if (el.hasAttribute("Id")) {\r
-                        el.setIdAttribute("Id", true);\r
-                        \r
-                        if (packageId.equals(el.getAttribute("Id"))) {\r
-                            target.get().removeEventListener("DOMSubtreeModified", this, false);\r
-                            el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);\r
-                            target.get().addEventListener("DOMSubtreeModified", this, false);\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        \r
-        public void setSignatureConfig(SignatureConfig signatureConfig) {\r
-            this.signatureConfig = signatureConfig;\r
-        }\r
-    }\r
-    \r
-    \r
     public SignatureInfo() {\r
         initXmlProvider();        \r
     }\r
@@ -360,14 +324,6 @@ public class SignatureInfo implements SignatureConfigurable {
         throw new RuntimeException("JRE doesn't support default xml signature provider - set jsr105Provider system property!");\r
     }\r
     \r
-    public static void setPrefix(Node el, String ns, String prefix) {\r
-        if (ns.equals(el.getNamespaceURI())) el.setPrefix(prefix);\r
-        NodeList nl = el.getChildNodes();\r
-        for (int i=0; i<nl.getLength(); i++) {\r
-            setPrefix(nl.item(i), ns, prefix);\r
-        }\r
-    }\r
-    \r
     protected byte[] getHashMagic() {\r
         switch (signatureConfig.getDigestAlgo()) {\r
         case sha1: return SHA1_DIGEST_INFO_PREFIX;\r
@@ -424,10 +380,10 @@ public class SignatureInfo implements SignatureConfigurable {
         EventTarget target = (EventTarget)document;\r
         EventListener creationListener = signatureConfig.getSignCreationListener();\r
         if (creationListener != null) {\r
-            if (creationListener instanceof SignCreationListener) {\r
-                ((SignCreationListener)creationListener).setEventTarget(target);\r
+            if (creationListener instanceof SignatureMarshalListener) {\r
+                ((SignatureMarshalListener)creationListener).setEventTarget(target);\r
             }\r
-            target.addEventListener("DOMSubtreeModified", creationListener, false);\r
+            SignatureMarshalListener.setListener(target, creationListener, true);\r
         }\r
         \r
         /*\r
@@ -442,7 +398,7 @@ public class SignatureInfo implements SignatureConfigurable {
         for (Map.Entry<String,String> me : signatureConfig.getNamespacePrefixes().entrySet()) {\r
             xmlSignContext.putNamespacePrefix(me.getKey(), me.getValue());\r
         }\r
-        xmlSignContext.setDefaultNamespacePrefix(signatureConfig.getNamespacePrefixes().get(XML_DIGSIG_NS));\r
+        xmlSignContext.setDefaultNamespacePrefix(""); // signatureConfig.getNamespacePrefixes().get(XML_DIGSIG_NS));\r
         \r
         XMLSignatureFactory signatureFactory = SignatureInfo.getSignatureFactory();\r
 \r
@@ -611,10 +567,9 @@ public class SignatureInfo implements SignatureConfigurable {
             throw new IOException(e);\r
         }\r
         \r
-        String sigContentType = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml";\r
         PackagePart sigPart = pkg.getPart(sigPartName);\r
         if (sigPart == null) {\r
-            sigPart = pkg.createPart(sigPartName, sigContentType);\r
+            sigPart = pkg.createPart(sigPartName, ContentTypes.DIGITAL_SIGNATURE_XML_SIGNATURE_PART);\r
         }\r
         \r
         OutputStream os = sigPart.getOutputStream();\r
@@ -622,11 +577,10 @@ public class SignatureInfo implements SignatureConfigurable {
         sigDoc.save(os, xo);\r
         os.close();\r
         \r
-        String sigsContentType = "application/vnd.openxmlformats-package.digital-signature-origin";\r
         PackagePart sigsPart = pkg.getPart(sigsPartName);\r
         if (sigsPart == null) {\r
             // touch empty marker file\r
-            sigsPart = pkg.createPart(sigsPartName, sigsContentType);\r
+            sigsPart = pkg.createPart(sigsPartName, ContentTypes.DIGITAL_SIGNATURE_ORIGIN_PART);\r
         }\r
         \r
         PackageRelationshipCollection relCol = pkg.getRelationshipsByType(PackageRelationshipTypes.DIGITAL_SIGNATURE_ORIGIN);\r
diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalListener.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalListener.java
new file mode 100644 (file)
index 0000000..f0f43c6
--- /dev/null
@@ -0,0 +1,92 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.poifs.crypt.dsig;\r
+\r
+import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.OO_DIGSIG_NS;\r
+import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_NS;\r
+\r
+import org.apache.poi.poifs.crypt.dsig.SignatureConfig.SignatureConfigurable;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
+import org.w3c.dom.events.Event;\r
+import org.w3c.dom.events.EventListener;\r
+import org.w3c.dom.events.EventTarget;\r
+import org.w3c.dom.events.MutationEvent;\r
+\r
+/**\r
+ * This listener class is used, to modify the to be digested xml document,\r
+ * e.g. to register id attributes or set prefixes for registered namespaces\r
+ */\r
+public class SignatureMarshalListener implements EventListener, SignatureConfigurable {\r
+    ThreadLocal<EventTarget> target = new ThreadLocal<EventTarget>();\r
+    SignatureConfig signatureConfig;\r
+    public void setEventTarget(EventTarget target) {\r
+        this.target.set(target);\r
+    }\r
+    \r
+    public void handleEvent(Event e) {\r
+        if (!(e instanceof MutationEvent)) return;\r
+        MutationEvent mutEvt = (MutationEvent)e;\r
+        EventTarget et = mutEvt.getTarget();\r
+        if (!(et instanceof Element)) return;\r
+        handleElement((Element)et);\r
+    }\r
+\r
+    public void handleElement(Element el) {\r
+        EventTarget target = this.target.get();\r
+        String packageId = signatureConfig.getPackageSignatureId();\r
+        if (el.hasAttribute("Id")) {\r
+            el.setIdAttribute("Id", true);\r
+        }\r
+\r
+        setListener(target, this, false);\r
+        if (packageId.equals(el.getAttribute("Id"))) {\r
+            el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);\r
+        }\r
+        setPrefix(el);\r
+        setListener(target, this, true);\r
+    }\r
+\r
+    // helper method to keep it in one place\r
+    public static void setListener(EventTarget target, EventListener listener, boolean enabled) {\r
+        String type = "DOMSubtreeModified";\r
+        boolean useCapture = false;\r
+        if (enabled) {\r
+            target.addEventListener(type, listener, useCapture);\r
+        } else {\r
+            target.removeEventListener(type, listener, useCapture);\r
+        }\r
+    }\r
+    \r
+    protected void setPrefix(Node el) {\r
+        String prefix = signatureConfig.getNamespacePrefixes().get(el.getNamespaceURI());\r
+        if (prefix != null && el.getPrefix() == null) {\r
+            el.setPrefix(prefix);\r
+        }\r
+        \r
+        NodeList nl = el.getChildNodes();\r
+        for (int i=0; i<nl.getLength(); i++) {\r
+            setPrefix(nl.item(i));\r
+        }\r
+    }\r
+    \r
+    public void setSignatureConfig(SignatureConfig signatureConfig) {\r
+        this.signatureConfig = signatureConfig;\r
+    }\r
+}
\ No newline at end of file
index a7e2c3ac6363ec1bb047a2b85c509d78e3268ae0..2bdcc4022acbecc75cb76c71796569053e2cefd2 100644 (file)
@@ -31,9 +31,9 @@ import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
 import javax.xml.crypto.MarshalException;\r
-import javax.xml.crypto.dom.DOMCryptoContext;\r
 import javax.xml.crypto.dom.DOMStructure;\r
 import javax.xml.crypto.dsig.Reference;\r
 import javax.xml.crypto.dsig.XMLObject;\r
@@ -139,11 +139,12 @@ public class KeyInfoSignatureFacet implements SignatureFacet {
 \r
         Element n = document.getDocumentElement();\r
         DOMSignContext domSignContext = new DOMSignContext(key, n, nextSibling);\r
-        DOMCryptoContext domCryptoContext = domSignContext;\r
-        domCryptoContext.putNamespacePrefix(XML_DIGSIG_NS, "xd");\r
+        for (Map.Entry<String,String> me : signatureConfig.getNamespacePrefixes().entrySet()) {\r
+            domSignContext.putNamespacePrefix(me.getKey(), me.getValue());\r
+        }\r
+        \r
         DOMStructure domStructure = new DOMStructure(n);\r
-        // how to set nextSibling??? - marshal is ignoring nextSibling in DOMSignContext\r
-        domKeyInfo.marshal(domStructure, domCryptoContext);\r
+        domKeyInfo.marshal(domStructure, domSignContext);\r
         \r
         // move keyinfo into the right place\r
         if (nextSibling != null) {\r
index 868c4224d4ee08b77190854b1cb96a136850c45a..b30c077641e6c91dfd5dd52fef668624052836d1 100644 (file)
@@ -24,8 +24,6 @@
 \r
 package org.apache.poi.poifs.crypt.dsig.facets;\r
 \r
-import static org.apache.poi.poifs.crypt.dsig.SignatureInfo.setPrefix;\r
-\r
 import java.io.IOException;\r
 import java.net.URI;\r
 import java.net.URISyntaxException;\r
@@ -40,6 +38,7 @@ import java.util.List;
 import java.util.Set;\r
 import java.util.TimeZone;\r
 \r
+import javax.xml.XMLConstants;\r
 import javax.xml.crypto.XMLStructure;\r
 import javax.xml.crypto.dom.DOMStructure;\r
 import javax.xml.crypto.dsig.CanonicalizationMethod;\r
@@ -104,11 +103,12 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         addSignatureInfo(document, signatureFactory, references, objects);\r
     }\r
 \r
-    private void addManifestObject(Document document,\r
-            XMLSignatureFactory signatureFactory,\r
-            List<Reference> references,\r
-            List<XMLObject> objects) throws NoSuchAlgorithmException,\r
-            InvalidAlgorithmParameterException, IOException, URISyntaxException, XmlException {\r
+    protected void addManifestObject(\r
+        Document document\r
+        , XMLSignatureFactory signatureFactory\r
+        , List<Reference> references\r
+        , List<XMLObject> objects)\r
+    throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException, URISyntaxException, XmlException {\r
 \r
         List<Reference> manifestReferences = new ArrayList<Reference>();\r
         addManifestReferences(signatureFactory, manifestReferences);\r
@@ -129,14 +129,13 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         references.add(reference);\r
     }\r
 \r
-    private void addManifestReferences(XMLSignatureFactory signatureFactory, List<Reference> manifestReferences)\r
-            throws IOException, NoSuchAlgorithmException,\r
-            InvalidAlgorithmParameterException, URISyntaxException, XmlException {\r
+    protected void addManifestReferences\r
+        (XMLSignatureFactory signatureFactory, List<Reference> manifestReferences)\r
+    throws IOException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, URISyntaxException, XmlException {\r
 \r
-        OPCPackage ooxml = this.signatureConfig.getOpcPackage();\r
+        OPCPackage ooxml = signatureConfig.getOpcPackage();\r
         List<PackagePart> relsEntryNames = ooxml.getPartsByContentType(ContentTypes.RELATIONSHIPS_PART);\r
 \r
-\r
         DigestMethod digestMethod = signatureFactory.newDigestMethod(signatureConfig.getDigestAlgo().xmlSignUri, null);\r
         Set<String> digestedPartNames = new HashSet<String>();\r
         for (PackagePart pp : relsEntryNames) {\r
@@ -154,12 +153,12 @@ public class OOXMLSignatureFacet implements SignatureFacet {
             for (PackageRelationship relationship : prc) {\r
                 String relationshipType = relationship.getRelationshipType();\r
                 \r
+                /*\r
+                 * ECMA-376 Part 2 - 3rd edition\r
+                 * 13.2.4.16 Manifest Element\r
+                 * "The producer shall not create a Manifest element that references any data outside of the package."\r
+                 */\r
                 if (TargetMode.EXTERNAL == relationship.getTargetMode()) {\r
-                    /*\r
-                     * ECMA-376 Part 2 - 3rd edition\r
-                     * 13.2.4.16 Manifest Element\r
-                     * "The producer shall not create a Manifest element that references any data outside of the package."\r
-                     */\r
                     continue;\r
                 }\r
 \r
@@ -180,6 +179,7 @@ public class OOXMLSignatureFacet implements SignatureFacet {
                 } catch (InvalidFormatException e) {\r
                     throw new IOException(e);\r
                 }\r
+                \r
                 if (relationshipType.endsWith("customXml")\r
                     && !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) {\r
                     LOG.log(POILogger.DEBUG, "skipping customXml with content type: " + contentType);\r
@@ -198,11 +198,11 @@ public class OOXMLSignatureFacet implements SignatureFacet {
             if (parameterSpec.hasSourceIds()) {\r
                 List<Transform> transforms = new ArrayList<Transform>();\r
                 transforms.add(signatureFactory.newTransform(\r
-                        RelationshipTransformService.TRANSFORM_URI,\r
-                        parameterSpec));\r
+                    RelationshipTransformService.TRANSFORM_URI,\r
+                    parameterSpec));\r
                 transforms.add(signatureFactory.newTransform(\r
-                        CanonicalizationMethod.INCLUSIVE,\r
-                        (TransformParameterSpec) null));\r
+                    CanonicalizationMethod.INCLUSIVE,\r
+                    (TransformParameterSpec) null));\r
                 String uri = pp.getPartName().getName()\r
                     + "?ContentType=application/vnd.openxmlformats-package.relationships+xml";\r
                 Reference reference = signatureFactory.newReference(uri, digestMethod, transforms, null, null);\r
@@ -212,15 +212,16 @@ public class OOXMLSignatureFacet implements SignatureFacet {
     }\r
 \r
 \r
-    private void addSignatureTime(Document document,\r
-            XMLSignatureFactory signatureFactory,\r
-            List<XMLStructure> objectContent) {\r
+    protected void addSignatureTime(\r
+        Document document\r
+        , XMLSignatureFactory signatureFactory\r
+        , List<XMLStructure> objectContent) {\r
         /*\r
          * SignatureTime\r
          */\r
         DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");\r
         fmt.setTimeZone(TimeZone.getTimeZone("UTC"));\r
-        String nowStr = fmt.format(this.signatureConfig.getExecutionTime());\r
+        String nowStr = fmt.format(signatureConfig.getExecutionTime());\r
         LOG.log(POILogger.DEBUG, "now: " + nowStr);\r
 \r
         SignatureTimeDocument sigTime = SignatureTimeDocument.Factory.newInstance();\r
@@ -228,24 +229,21 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         ctTime.setFormat("YYYY-MM-DDThh:mm:ssTZD");\r
         ctTime.setValue(nowStr);\r
 \r
-        // TODO: find better method to have xmlbeans + export the prefix\r
         Element n = (Element)document.importNode(ctTime.getDomNode(),true);\r
-        setPrefix(n, OO_DIGSIG_NS, "mdssi");\r
-        \r
         List<XMLStructure> signatureTimeContent = new ArrayList<XMLStructure>();\r
         signatureTimeContent.add(new DOMStructure(n));\r
         SignatureProperty signatureTimeSignatureProperty = signatureFactory\r
-                .newSignatureProperty(signatureTimeContent, "#" + signatureConfig.getPackageSignatureId(),\r
-                        "idSignatureTime");\r
+            .newSignatureProperty(signatureTimeContent, "#" + signatureConfig.getPackageSignatureId(),\r
+            "idSignatureTime");\r
         List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();\r
         signaturePropertyContent.add(signatureTimeSignatureProperty);\r
         SignatureProperties signatureProperties = signatureFactory\r
-                .newSignatureProperties(signaturePropertyContent,\r
-                        "id-signature-time-" + signatureConfig.getExecutionTime());\r
+            .newSignatureProperties(signaturePropertyContent,\r
+            "id-signature-time-" + signatureConfig.getExecutionTime());\r
         objectContent.add(signatureProperties);\r
     }\r
 \r
-    private void addSignatureInfo(Document document,\r
+    protected void addSignatureInfo(Document document,\r
         XMLSignatureFactory signatureFactory,\r
         List<Reference> references,\r
         List<XMLObject> objects)\r
@@ -256,18 +254,18 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         CTSignatureInfoV1 ctSigV1 = sigV1.addNewSignatureInfoV1();\r
         ctSigV1.setManifestHashAlgorithm(signatureConfig.getDigestAlgo().xmlSignUri);\r
         Element n = (Element)document.importNode(ctSigV1.getDomNode(), true);\r
-        n.setAttributeNS(XML_NS, "xmlns", "http://schemas.microsoft.com/office/2006/digsig");\r
+        n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS);\r
         \r
         List<XMLStructure> signatureInfoContent = new ArrayList<XMLStructure>();\r
         signatureInfoContent.add(new DOMStructure(n));\r
         SignatureProperty signatureInfoSignatureProperty = signatureFactory\r
-                .newSignatureProperty(signatureInfoContent, "#" + signatureConfig.getPackageSignatureId(),\r
-                        "idOfficeV1Details");\r
+            .newSignatureProperty(signatureInfoContent, "#" + signatureConfig.getPackageSignatureId(),\r
+            "idOfficeV1Details");\r
 \r
         List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();\r
         signaturePropertyContent.add(signatureInfoSignatureProperty);\r
         SignatureProperties signatureProperties = signatureFactory\r
-                .newSignatureProperties(signaturePropertyContent, null);\r
+            .newSignatureProperties(signaturePropertyContent, null);\r
         objectContent.add(signatureProperties);\r
 \r
         String objectId = "idOfficeObject";\r
@@ -284,61 +282,17 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         // empty\r
     }\r
 \r
-    public static String getRelationshipReferenceURI(String zipEntryName) {\r
-\r
+    protected static String getRelationshipReferenceURI(String zipEntryName) {\r
         return "/"\r
-                + zipEntryName\r
-                + "?ContentType=application/vnd.openxmlformats-package.relationships+xml";\r
+            + zipEntryName\r
+            + "?ContentType=application/vnd.openxmlformats-package.relationships+xml";\r
     }\r
 \r
-    public static String getResourceReferenceURI(String resourceName,\r
-            String contentType) {\r
-\r
+    protected static String getResourceReferenceURI(String resourceName, String contentType) {\r
         return "/" + resourceName + "?ContentType=" + contentType;\r
     }\r
 \r
-    public static String[] contentTypes = {\r
-\r
-            /*\r
-             * Word\r
-             */\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",\r
-            "application/vnd.openxmlformats-officedocument.theme+xml",\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",\r
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",\r
-\r
-            /*\r
-             * Word 2010\r
-             */\r
-            "application/vnd.ms-word.stylesWithEffects+xml",\r
-\r
-            /*\r
-             * Excel\r
-             */\r
-            "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",\r
-            "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",\r
-            "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",\r
-            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",\r
-\r
-            /*\r
-             * Powerpoint\r
-             */\r
-            "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml",\r
-            "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml",\r
-            "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",\r
-            "application/vnd.openxmlformats-officedocument.presentationml.slide+xml",\r
-            "application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml",\r
-\r
-            /*\r
-             * Powerpoint 2010\r
-             */\r
-            "application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml",\r
-            "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml" };\r
-\r
-    public static boolean isSignedRelationship(String relationshipType) {\r
+    protected static boolean isSignedRelationship(String relationshipType) {\r
         LOG.log(POILogger.DEBUG, "relationship type: " + relationshipType);\r
         for (String signedTypeExtension : signed) {\r
             if (relationshipType.endsWith(signedTypeExtension)) {\r
@@ -351,155 +305,197 @@ public class OOXMLSignatureFacet implements SignatureFacet {
         }\r
         return false;\r
     }\r
+    \r
+    public static final String[] contentTypes = {\r
+        /*\r
+         * Word\r
+         */\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",\r
+        "application/vnd.openxmlformats-officedocument.theme+xml",\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",\r
+        "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",\r
+\r
+        /*\r
+         * Word 2010\r
+         */\r
+        "application/vnd.ms-word.stylesWithEffects+xml",\r
+\r
+        /*\r
+         * Excel\r
+         */\r
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",\r
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",\r
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",\r
+        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",\r
+\r
+        /*\r
+         * Powerpoint\r
+         */\r
+        "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml",\r
+        "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml",\r
+        "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",\r
+        "application/vnd.openxmlformats-officedocument.presentationml.slide+xml",\r
+        "application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml",\r
+\r
+        /*\r
+         * Powerpoint 2010\r
+         */\r
+        "application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml",\r
+        "application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"\r
+    };\r
 \r
     /**\r
      * Office 2010 list of signed types (extensions).\r
      */\r
-    public static String[] signed = { "powerPivotData", //\r
-            "activeXControlBinary", //\r
-            "attachedToolbars", //\r
-            "connectorXml", //\r
-            "downRev", //\r
-            "functionPrototypes", //\r
-            "graphicFrameDoc", //\r
-            "groupShapeXml", //\r
-            "ink", //\r
-            "keyMapCustomizations", //\r
-            "legacyDiagramText", //\r
-            "legacyDocTextInfo", //\r
-            "officeDocument", //\r
-            "pictureXml", //\r
-            "shapeXml", //\r
-            "smartTags", //\r
-            "ui/altText", //\r
-            "ui/buttonSize", //\r
-            "ui/controlID", //\r
-            "ui/description", //\r
-            "ui/enabled", //\r
-            "ui/extensibility", //\r
-            "ui/helperText", //\r
-            "ui/imageID", //\r
-            "ui/imageMso", //\r
-            "ui/keyTip", //\r
-            "ui/label", //\r
-            "ui/lcid", //\r
-            "ui/loud", //\r
-            "ui/pressed", //\r
-            "ui/progID", //\r
-            "ui/ribbonID", //\r
-            "ui/showImage", //\r
-            "ui/showLabel", //\r
-            "ui/supertip", //\r
-            "ui/target", //\r
-            "ui/text", //\r
-            "ui/title", //\r
-            "ui/tooltip", //\r
-            "ui/userCustomization", //\r
-            "ui/visible", //\r
-            "userXmlData", //\r
-            "vbaProject", //\r
-            "wordVbaData", //\r
-            "wsSortMap", //\r
-            "xlBinaryIndex", //\r
-            "xlExternalLinkPath/xlAlternateStartup", //\r
-            "xlExternalLinkPath/xlLibrary", //\r
-            "xlExternalLinkPath/xlPathMissing", //\r
-            "xlExternalLinkPath/xlStartup", //\r
-            "xlIntlMacrosheet", //\r
-            "xlMacrosheet", //\r
-            "customData", //\r
-            "diagramDrawing", //\r
-            "hdphoto", //\r
-            "inkXml", //\r
-            "media", //\r
-            "slicer", //\r
-            "slicerCache", //\r
-            "stylesWithEffects", //\r
-            "ui/extensibility", //\r
-            "chartColorStyle", //\r
-            "chartLayout", //\r
-            "chartStyle", //\r
-            "dictionary", //\r
-            "timeline", //\r
-            "timelineCache", //\r
-            "aFChunk", //\r
-            "attachedTemplate", //\r
-            "audio", //\r
-            "calcChain", //\r
-            "chart", //\r
-            "chartsheet", //\r
-            "chartUserShapes", //\r
-            "commentAuthors", //\r
-            "comments", //\r
-            "connections", //\r
-            "control", //\r
-            "customProperty", //\r
-            "customXml", //\r
-            "diagramColors", //\r
-            "diagramData", //\r
-            "diagramLayout", //\r
-            "diagramQuickStyle", //\r
-            "dialogsheet", //\r
-            "drawing", //\r
-            "endnotes", //\r
-            "externalLink", //\r
-            "externalLinkPath", //\r
-            "font", //\r
-            "fontTable", //\r
-            "footer", //\r
-            "footnotes", //\r
-            "glossaryDocument", //\r
-            "handoutMaster", //\r
-            "header", //\r
-            "hyperlink", //\r
-            "image", //\r
-            "mailMergeHeaderSource", //\r
-            "mailMergeRecipientData", //\r
-            "mailMergeSource", //\r
-            "notesMaster", //\r
-            "notesSlide", //\r
-            "numbering", //\r
-            "officeDocument", //\r
-            "oleObject", //\r
-            "package", //\r
-            "pivotCacheDefinition", //\r
-            "pivotCacheRecords", //\r
-            "pivotTable", //\r
-            "presProps", //\r
-            "printerSettings", //\r
-            "queryTable", //\r
-            "recipientData", //\r
-            "settings", //\r
-            "sharedStrings", //\r
-            "sheetMetadata", //\r
-            "slide", //\r
-            "slideLayout", //\r
-            "slideMaster", //\r
-            "slideUpdateInfo", //\r
-            "slideUpdateUrl", //\r
-            "styles", //\r
-            "table", //\r
-            "tableSingleCells", //\r
-            "tableStyles", //\r
-            "tags", //\r
-            "theme", //\r
-            "themeOverride", //\r
-            "transform", //\r
-            "video", //\r
-            "viewProps", //\r
-            "volatileDependencies", //\r
-            "webSettings", //\r
-            "worksheet", //\r
-            "xmlMaps", //\r
-            "ctrlProp", //\r
-            "customData", //\r
-            "diagram", //\r
-            "diagramColorsHeader", //\r
-            "diagramLayoutHeader", //\r
-            "diagramQuickStyleHeader", //\r
-            "documentParts", //\r
-            "slicer", //\r
-            "slicerCache", //\r
-            "vmlDrawing" //\r
+    public static final String[] signed = {\r
+        "powerPivotData", //\r
+        "activeXControlBinary", //\r
+        "attachedToolbars", //\r
+        "connectorXml", //\r
+        "downRev", //\r
+        "functionPrototypes", //\r
+        "graphicFrameDoc", //\r
+        "groupShapeXml", //\r
+        "ink", //\r
+        "keyMapCustomizations", //\r
+        "legacyDiagramText", //\r
+        "legacyDocTextInfo", //\r
+        "officeDocument", //\r
+        "pictureXml", //\r
+        "shapeXml", //\r
+        "smartTags", //\r
+        "ui/altText", //\r
+        "ui/buttonSize", //\r
+        "ui/controlID", //\r
+        "ui/description", //\r
+        "ui/enabled", //\r
+        "ui/extensibility", //\r
+        "ui/helperText", //\r
+        "ui/imageID", //\r
+        "ui/imageMso", //\r
+        "ui/keyTip", //\r
+        "ui/label", //\r
+        "ui/lcid", //\r
+        "ui/loud", //\r
+        "ui/pressed", //\r
+        "ui/progID", //\r
+        "ui/ribbonID", //\r
+        "ui/showImage", //\r
+        "ui/showLabel", //\r
+        "ui/supertip", //\r
+        "ui/target", //\r
+        "ui/text", //\r
+        "ui/title", //\r
+        "ui/tooltip", //\r
+        "ui/userCustomization", //\r
+        "ui/visible", //\r
+        "userXmlData", //\r
+        "vbaProject", //\r
+        "wordVbaData", //\r
+        "wsSortMap", //\r
+        "xlBinaryIndex", //\r
+        "xlExternalLinkPath/xlAlternateStartup", //\r
+        "xlExternalLinkPath/xlLibrary", //\r
+        "xlExternalLinkPath/xlPathMissing", //\r
+        "xlExternalLinkPath/xlStartup", //\r
+        "xlIntlMacrosheet", //\r
+        "xlMacrosheet", //\r
+        "customData", //\r
+        "diagramDrawing", //\r
+        "hdphoto", //\r
+        "inkXml", //\r
+        "media", //\r
+        "slicer", //\r
+        "slicerCache", //\r
+        "stylesWithEffects", //\r
+        "ui/extensibility", //\r
+        "chartColorStyle", //\r
+        "chartLayout", //\r
+        "chartStyle", //\r
+        "dictionary", //\r
+        "timeline", //\r
+        "timelineCache", //\r
+        "aFChunk", //\r
+        "attachedTemplate", //\r
+        "audio", //\r
+        "calcChain", //\r
+        "chart", //\r
+        "chartsheet", //\r
+        "chartUserShapes", //\r
+        "commentAuthors", //\r
+        "comments", //\r
+        "connections", //\r
+        "control", //\r
+        "customProperty", //\r
+        "customXml", //\r
+        "diagramColors", //\r
+        "diagramData", //\r
+        "diagramLayout", //\r
+        "diagramQuickStyle", //\r
+        "dialogsheet", //\r
+        "drawing", //\r
+        "endnotes", //\r
+        "externalLink", //\r
+        "externalLinkPath", //\r
+        "font", //\r
+        "fontTable", //\r
+        "footer", //\r
+        "footnotes", //\r
+        "glossaryDocument", //\r
+        "handoutMaster", //\r
+        "header", //\r
+        "hyperlink", //\r
+        "image", //\r
+        "mailMergeHeaderSource", //\r
+        "mailMergeRecipientData", //\r
+        "mailMergeSource", //\r
+        "notesMaster", //\r
+        "notesSlide", //\r
+        "numbering", //\r
+        "officeDocument", //\r
+        "oleObject", //\r
+        "package", //\r
+        "pivotCacheDefinition", //\r
+        "pivotCacheRecords", //\r
+        "pivotTable", //\r
+        "presProps", //\r
+        "printerSettings", //\r
+        "queryTable", //\r
+        "recipientData", //\r
+        "settings", //\r
+        "sharedStrings", //\r
+        "sheetMetadata", //\r
+        "slide", //\r
+        "slideLayout", //\r
+        "slideMaster", //\r
+        "slideUpdateInfo", //\r
+        "slideUpdateUrl", //\r
+        "styles", //\r
+        "table", //\r
+        "tableSingleCells", //\r
+        "tableStyles", //\r
+        "tags", //\r
+        "theme", //\r
+        "themeOverride", //\r
+        "transform", //\r
+        "video", //\r
+        "viewProps", //\r
+        "volatileDependencies", //\r
+        "webSettings", //\r
+        "worksheet", //\r
+        "xmlMaps", //\r
+        "ctrlProp", //\r
+        "customData", //\r
+        "diagram", //\r
+        "diagramColorsHeader", //\r
+        "diagramLayoutHeader", //\r
+        "diagramQuickStyleHeader", //\r
+        "documentParts", //\r
+        "slicer", //\r
+        "slicerCache", //\r
+        "vmlDrawing" //\r
     };\r
 }
\ No newline at end of file
index abf5c6f1d1cddaf8274c1680f90521b542d5399c..576fa9f514407012cbf5beef226a0008d78366c9 100644 (file)
@@ -24,8 +24,6 @@
 \r
 package org.apache.poi.poifs.crypt.dsig.facets;\r
 \r
-import static org.apache.poi.poifs.crypt.dsig.SignatureInfo.setPrefix;\r
-\r
 import java.security.InvalidAlgorithmParameterException;\r
 import java.security.MessageDigest;\r
 import java.security.NoSuchAlgorithmException;\r
@@ -206,14 +204,10 @@ public class XAdESSignatureFacet implements SignatureFacet {
             }\r
         }\r
 \r
-        // marshall XAdES QualifyingProperties\r
-        // ((Element)qualifyingProperties.getSignedProperties().getDomNode()).setIdAttribute("Id", true);\r
-\r
         // add XAdES ds:Object\r
         List<XMLStructure> xadesObjectContent = new ArrayList<XMLStructure>();\r
-        Element qualDocEl = (Element)document.importNode(qualifyingProperties.getDomNode(), true);\r
-        qualDocEl.setAttributeNS(XML_NS, "xmlns:xd", XADES_132_NS);\r
-        setPrefix(qualDocEl, XADES_132_NS, "xd");\r
+        Element qualDocElSrc = (Element)qualifyingProperties.getDomNode();\r
+        Element qualDocEl = (Element)document.importNode(qualDocElSrc, true);\r
         xadesObjectContent.add(new DOMStructure(qualDocEl));\r
         XMLObject xadesObject = signatureFactory.newXMLObject(xadesObjectContent, null, null, null);\r
         objects.add(xadesObject);\r
index 7c5d0dff181f6b21f406942e39609968e19783fc..dea586463b870abc2e3f7cefa826f55473c283e3 100644 (file)
@@ -24,9 +24,6 @@
 \r
 package org.apache.poi.poifs.crypt.dsig.services;\r
 \r
-import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_DIGSIG_NS;\r
-import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_NS;\r
-\r
 import java.io.ByteArrayInputStream;\r
 import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
@@ -171,8 +168,6 @@ public class RelationshipTransformService extends TransformService {
             RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();\r
             relRef.addNewRelationshipReference().setSourceId(sourceId);\r
             Node n = relRef.getRelationshipReference().getDomNode();\r
-            // TODO: is there a more elegant way to do this?\r
-            n.setPrefix("mdssi");\r
             n = doc.importNode(n, true);\r
             parentNode.appendChild(n);\r
         }\r