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