From 6aae53935afbc1834ec7df7ee3be66da92e6a956 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sat, 24 Jun 2017 09:03:00 +0000 Subject: [PATCH] release prepare for 3.17-beta1 - pin documentation git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1799740 13f79535-47bb-0310-9956-ffa450edef68 --- .../opc/PackageRelationshipCollection.java | 67 ++-- .../poi/poifs/crypt/dsig/SignatureInfo.java | 2 +- .../crypt/dsig/SignatureMarshalListener.java | 38 +- .../dsig/facets/OOXMLSignatureFacet.java | 339 ++++++------------ .../RelationshipTransformService.java | 23 +- .../poi/xssf/usermodel/XSSFDrawing.java | 4 +- .../poi/poifs/crypt/TestSignatureInfo.java | 65 ++++ 7 files changed, 252 insertions(+), 286 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java index 912a3d5b8..cd89b4314 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java @@ -18,7 +18,13 @@ package org.apache.poi.openxml4j.opc; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; +import java.util.TreeMap; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; @@ -43,14 +49,14 @@ public final class PackageRelationshipCollection implements private final static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class); /** - * Package relationships ordered by ID. + * Package relationships by ID. */ - private TreeMap relationshipsByID; + private final Map relationshipsByID = new LinkedHashMap(); /** - * Package relationships ordered by type. + * Package relationships by type. */ - private TreeMap relationshipsByType; + private final Map relationshipsByType = new LinkedHashMap(); /** * A lookup of internal relationships to avoid @@ -88,8 +94,6 @@ public final class PackageRelationshipCollection implements * Constructor. */ PackageRelationshipCollection() { - relationshipsByID = new TreeMap(); - relationshipsByType = new TreeMap(); } /** @@ -104,20 +108,18 @@ public final class PackageRelationshipCollection implements * @param filter * Relationship type filter. */ - public PackageRelationshipCollection(PackageRelationshipCollection coll, - String filter) { - this(); + public PackageRelationshipCollection(PackageRelationshipCollection coll, String filter) { for (PackageRelationship rel : coll.relationshipsByID.values()) { - if (filter == null || rel.getRelationshipType().equals(filter)) + if (filter == null || rel.getRelationshipType().equals(filter)) { addRelationship(rel); + } } } /** * Constructor. */ - public PackageRelationshipCollection(OPCPackage container) - throws InvalidFormatException { + public PackageRelationshipCollection(OPCPackage container) throws InvalidFormatException { this(container, null); } @@ -130,8 +132,7 @@ public final class PackageRelationshipCollection implements * @throws InvalidOperationException * Throws if the specified part is a relationship part. */ - public PackageRelationshipCollection(PackagePart part) - throws InvalidFormatException { + public PackageRelationshipCollection(PackagePart part) throws InvalidFormatException { this(part._container, part); } @@ -147,16 +148,15 @@ public final class PackageRelationshipCollection implements * If an error occurs during the parsing of the relatinships * part fo the specified part. */ - public PackageRelationshipCollection(OPCPackage container, PackagePart part) - throws InvalidFormatException { - this(); - - if (container == null) + public PackageRelationshipCollection(OPCPackage container, PackagePart part) throws InvalidFormatException { + if (container == null) { throw new IllegalArgumentException("container needs to be specified"); + } // Check if the specified part is not a relationship part - if (part != null && part.isRelationshipPart()) + if (part != null && part.isRelationshipPart()) { throw new IllegalArgumentException("part"); + } this.container = container; this.sourcePart = part; @@ -179,8 +179,7 @@ public final class PackageRelationshipCollection implements * @throws InvalidOperationException * Throws if the specified part is a relationship part. */ - private static PackagePartName getRelationshipPartName(PackagePart part) - throws InvalidOperationException { + private static PackagePartName getRelationshipPartName(PackagePart part) throws InvalidOperationException { PackagePartName partName; if (part == null) { partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME; @@ -263,13 +262,15 @@ public final class PackageRelationshipCollection implements * Must be a value between [0-relationships_count-1] */ public PackageRelationship getRelationship(int index) { - if (index < 0 || index > relationshipsByID.values().size()) + if (index < 0 || index > relationshipsByID.values().size()) { throw new IllegalArgumentException("index"); + } int i = 0; for (PackageRelationship rel : relationshipsByID.values()) { - if (index == i++) + if (index == i++) { return rel; + } } return null; @@ -287,10 +288,10 @@ public final class PackageRelationshipCollection implements } /** - * Get the numbe rof relationships in the collection. + * Get the number of relationships in the collection. */ public int size() { - return relationshipsByID.values().size(); + return relationshipsByID.size(); } /** @@ -324,12 +325,14 @@ public final class PackageRelationshipCollection implements /* Check OPC Compliance */ // Check Rule M4.1 - if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES)) - if (!fCorePropertiesRelationship) + if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES)) { + if (!fCorePropertiesRelationship) { fCorePropertiesRelationship = true; - else + } else { throw new InvalidFormatException( "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !"); + } + } /* End OPC Compliance */ @@ -378,6 +381,7 @@ public final class PackageRelationshipCollection implements /** * Get this collection's iterator. */ + @Override public Iterator iterator() { return relationshipsByID.values().iterator(); } @@ -394,8 +398,9 @@ public final class PackageRelationshipCollection implements public Iterator iterator(String typeFilter) { ArrayList retArr = new ArrayList(); for (PackageRelationship rel : relationshipsByID.values()) { - if (rel.getRelationshipType().equals(typeFilter)) + if (rel.getRelationshipType().equals(typeFilter)) { retArr.add(rel); + } } return retArr.iterator(); } 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 d7f648fae..03fc868fb 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 @@ -511,7 +511,7 @@ public class SignatureInfo implements SignatureConfigurable { /* * JSR105 ds:Signature creation */ - String signatureValueId = signatureConfig.getPackageSignatureId() + "-signature-value"; + String signatureValueId = null; // signatureConfig.getPackageSignatureId() + "-signature-value"; javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory .newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(), signatureValueId); 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 index 3b21eb865..ba11776b7 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalListener.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalListener.java @@ -40,27 +40,46 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu this.target.set(target); } + @Override public void handleEvent(Event e) { - if (!(e instanceof MutationEvent)) return; + if (!(e instanceof MutationEvent)) { + return; + } MutationEvent mutEvt = (MutationEvent)e; EventTarget et = mutEvt.getTarget(); - if (!(et instanceof Element)) return; + if (!(et instanceof Element)) { + return; + } handleElement((Element)et); } public void handleElement(Element el) { EventTarget target = this.target.get(); String packageId = signatureConfig.getPackageSignatureId(); + + setListener(target, this, false); +// if (packageId.equals(el.getAttribute("Id"))) { +// el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS); +// } + if (OO_DIGSIG_NS.equals(el.getNamespaceURI()) && !OO_DIGSIG_NS.equals(el.getParentNode().getNamespaceURI())) { + if (!el.hasAttributeNS(XML_NS, "mdssi")) { + el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS); + } + } + setPrefix(el); + if ("X509Certificate".equals(el.getLocalName())) { + String x509 = el.getTextContent(); + x509 = x509.replaceAll("\\s", ""); + el.setTextContent(x509); + } +// if ("SignatureValue".equals(el.getLocalName())) { +// el.removeAttribute("Id"); +// } + setListener(target, this, true); + 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 @@ -86,6 +105,7 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu } } + @Override public void setSignatureConfig(SignatureConfig signatureConfig) { this.signatureConfig = signatureConfig; } 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 5affefc07..be7d0787b 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 @@ -18,9 +18,9 @@ /* ==================================================================== This product contains an ASLv2 licensed version of the OOXML signer package from the eID Applet project - http://code.google.com/p/eid-applet/source/browse/trunk/README.txt + http://code.google.com/p/eid-applet/source/browse/trunk/README.txt Copyright (C) 2008-2014 FedICT. - ================================================================= */ + ================================================================= */ package org.apache.poi.poifs.crypt.dsig.facets; @@ -29,6 +29,9 @@ import java.net.URISyntaxException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -46,6 +49,7 @@ import javax.xml.crypto.dsig.Transform; import javax.xml.crypto.dsig.XMLObject; import javax.xml.crypto.dsig.XMLSignatureException; +import org.apache.poi.hpsf.ClassID; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.ContentTypes; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -60,6 +64,7 @@ import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService.Rel import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.apache.xmlbeans.XmlCursor; import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.CTSignatureTime; import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument; import org.w3c.dom.Document; @@ -70,13 +75,13 @@ import com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document; /** * Office OpenXML Signature Facet implementation. - * - * @author fcorneli + * * @see [MS-OFFCRYPTO]: Office Document Cryptography Structure */ public class OOXMLSignatureFacet extends SignatureFacet { private static final POILogger LOG = POILogFactory.getLogger(OOXMLSignatureFacet.class); + private static final String ID_PACKAGE_OBJECT = "idPackageObject"; @Override public void preSign( @@ -98,17 +103,16 @@ public class OOXMLSignatureFacet extends SignatureFacet { List manifestReferences = new ArrayList(); addManifestReferences(manifestReferences); Manifest manifest = getSignatureFactory().newManifest(manifestReferences); - - String objectId = "idPackageObject"; // really has to be this value. + List objectContent = new ArrayList(); objectContent.add(manifest); addSignatureTime(document, objectContent); - XMLObject xo = getSignatureFactory().newXMLObject(objectContent, objectId, null, null); + XMLObject xo = getSignatureFactory().newXMLObject(objectContent, ID_PACKAGE_OBJECT, null, null); objects.add(xo); - Reference reference = newReference("#" + objectId, null, XML_DIGSIG_NS+"Object", null, null); + Reference reference = newReference("#"+ID_PACKAGE_OBJECT, null, XML_DIGSIG_NS+"Object", null, null); references.add(reference); } @@ -121,7 +125,7 @@ public class OOXMLSignatureFacet extends SignatureFacet { Set digestedPartNames = new HashSet(); for (PackagePart pp : relsEntryNames) { - String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1"); + final String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1"); PackageRelationshipCollection prc; try { @@ -130,11 +134,11 @@ public class OOXMLSignatureFacet extends SignatureFacet { } catch (InvalidFormatException e) { throw new XMLSignatureException("Invalid relationship descriptor: "+pp.getPartName().getName(), e); } - + RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec(); for (PackageRelationship relationship : prc) { String relationshipType = relationship.getRelationshipType(); - + /* * ECMA-376 Part 2 - 3rd edition * 13.2.4.16 Manifest Element @@ -144,22 +148,20 @@ public class OOXMLSignatureFacet extends SignatureFacet { continue; } - if (!isSignedRelationship(relationshipType)) continue; + if (!isSignedRelationship(relationshipType)) { + continue; + } parameterSpec.addRelationshipReference(relationship.getId()); - // TODO: find a better way ... - String partName = relationship.getTargetURI().toString(); - if (!partName.startsWith(baseUri)) { - partName = baseUri + partName; + String partName = normalizePartName(relationship.getTargetURI(), baseUri); + + // We only digest a part once. + if (digestedPartNames.contains(partName)) { + continue; } - try { - partName = new URI(partName).normalize().getPath().replace('\\', '/'); - LOG.log(POILogger.DEBUG, "part name: " + partName); - } catch (URISyntaxException e) { - throw new XMLSignatureException(e); - } - + digestedPartNames.add(partName); + String contentType; try { PackagePartName relName = PackagingURIHelper.createPartName(partName); @@ -168,32 +170,52 @@ public class OOXMLSignatureFacet extends SignatureFacet { } catch (InvalidFormatException e) { throw new XMLSignatureException(e); } - + if (relationshipType.endsWith("customXml") && !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) { LOG.log(POILogger.DEBUG, "skipping customXml with content type: " + contentType); continue; } - - if (!digestedPartNames.contains(partName)) { - // We only digest a part once. - String uri = partName + "?ContentType=" + contentType; - Reference reference = newReference(uri, null, null, null, null); - manifestReferences.add(reference); - digestedPartNames.add(partName); - } + + String uri = partName + "?ContentType=" + contentType; + Reference reference = newReference(uri, null, null, null, null); + manifestReferences.add(reference); } - + if (parameterSpec.hasSourceIds()) { List transforms = new ArrayList(); transforms.add(newTransform(RelationshipTransformService.TRANSFORM_URI, parameterSpec)); transforms.add(newTransform(CanonicalizationMethod.INCLUSIVE)); - String uri = pp.getPartName().getName() + String uri = normalizePartName(pp.getPartName().getURI(), baseUri) + "?ContentType=application/vnd.openxmlformats-package.relationships+xml"; Reference reference = newReference(uri, transforms, null, null, null); manifestReferences.add(reference); } } + + Collections.sort(manifestReferences, new Comparator() { + public int compare(Reference o1, Reference o2) { + return o1.getURI().compareTo(o2.getURI()); + } + }); + } + + /** + * Normalize a URI/part name + * TODO: find a better way ... + */ + private static String normalizePartName(URI partName, String baseUri) throws XMLSignatureException { + String pn = partName.toASCIIString(); + if (!pn.startsWith(baseUri)) { + pn = baseUri + pn; + } + try { + pn = new URI(pn).normalize().getPath().replace('\\', '/'); + LOG.log(POILogger.DEBUG, "part name: " + pn); + } catch (URISyntaxException e) { + throw new XMLSignatureException(e); + } + return pn; } @@ -220,8 +242,8 @@ public class OOXMLSignatureFacet extends SignatureFacet { List signaturePropertyContent = new ArrayList(); signaturePropertyContent.add(signatureTimeSignatureProperty); SignatureProperties signatureProperties = getSignatureFactory() - .newSignatureProperties(signaturePropertyContent, - "id-signature-time-" + signatureConfig.getExecutionTime()); + .newSignatureProperties(signaturePropertyContent, null); +// "id-signature-time-" + signatureConfig.getExecutionTime()); objectContent.add(signatureProperties); } @@ -233,10 +255,28 @@ public class OOXMLSignatureFacet extends SignatureFacet { SignatureInfoV1Document sigV1 = SignatureInfoV1Document.Factory.newInstance(); CTSignatureInfoV1 ctSigV1 = sigV1.addNewSignatureInfoV1(); - ctSigV1.setManifestHashAlgorithm(signatureConfig.getDigestMethodUri()); +// ctSigV1.setManifestHashAlgorithm(signatureConfig.getDigestMethodUri()); + XmlCursor cur = ctSigV1.newCursor(); + cur.toEndToken(); cur.beginElement("SetupID", MS_DIGSIG_NS); + cur.toNextToken(); cur.beginElement("SignatureText", MS_DIGSIG_NS); + cur.toNextToken(); cur.beginElement("SignatureImage", MS_DIGSIG_NS); + cur.toNextToken(); cur.beginElement("SignatureProviderUrl", MS_DIGSIG_NS); + cur.dispose(); + ctSigV1.setSignatureComments("Test"); + ctSigV1.setWindowsVersion("6.1"); + ctSigV1.setOfficeVersion("16.0"); + ctSigV1.setApplicationVersion("16.0"); + ctSigV1.setMonitors(1); + ctSigV1.setHorizontalResolution(3840); + ctSigV1.setVerticalResolution(2160); + ctSigV1.setColorDepth(32); + ctSigV1.setSignatureProviderId(new ClassID().toString()); + ctSigV1.setSignatureProviderDetails(9); + ctSigV1.setSignatureType(1); + Element n = (Element)document.importNode(ctSigV1.getDomNode(), true); n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS); - + List signatureInfoContent = new ArrayList(); signatureInfoContent.add(new DOMStructure(n)); SignatureProperty signatureInfoSignatureProperty = getSignatureFactory() @@ -268,208 +308,33 @@ public class OOXMLSignatureFacet extends SignatureFacet { protected static boolean isSignedRelationship(String relationshipType) { LOG.log(POILogger.DEBUG, "relationship type: " + relationshipType); - for (String signedTypeExtension : signed) { - if (relationshipType.endsWith(signedTypeExtension)) { - return true; - } - } - if (relationshipType.endsWith("customXml")) { - LOG.log(POILogger.DEBUG, "customXml relationship type"); - return true; - } - return false; + String rt = relationshipType.replaceFirst(".*/relationships/", ""); + return (signed.contains(rt) || rt.endsWith("customXml")); } - - 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 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" // - }; + private static final Set signed = Collections.unmodifiableSet(new HashSet(Arrays.asList( + "activeXControlBinary","aFChunk","attachedTemplate","attachedToolbars","audio","calcChain","chart","chartColorStyle", + "chartLayout","chartsheet","chartStyle","chartUserShapes","commentAuthors","comments","connections","connectorXml", + "control","ctrlProp","customData","customData","customProperty","customXml","diagram","diagramColors", + "diagramColorsHeader","diagramData","diagramDrawing","diagramLayout","diagramLayoutHeader","diagramQuickStyle", + "diagramQuickStyleHeader","dialogsheet","dictionary","documentParts","downRev","drawing","endnotes","externalLink", + "externalLinkPath","font","fontTable","footer","footnotes","functionPrototypes","glossaryDocument","graphicFrameDoc", + "groupShapeXml","handoutMaster","hdphoto","header","hyperlink","image","ink","inkXml","keyMapCustomizations", + "legacyDiagramText","legacyDocTextInfo","mailMergeHeaderSource","mailMergeRecipientData","mailMergeSource","media", + "notesMaster","notesSlide","numbering","officeDocument","officeDocument","oleObject","package","pictureXml", + "pivotCacheDefinition","pivotCacheRecords","pivotTable","powerPivotData","presProps","printerSettings","queryTable", + "recipientData","settings","shapeXml","sharedStrings","sheetMetadata","slicer","slicer","slicerCache","slicerCache", + "slide","slideLayout","slideMaster","slideUpdateInfo","slideUpdateUrl","smartTags","styles","stylesWithEffects", + "table","tableSingleCells","tableStyles","tags","theme","themeOverride","timeline","timelineCache","transform", + "ui/altText","ui/buttonSize","ui/controlID","ui/description","ui/enabled","ui/extensibility","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","video","viewProps","vmlDrawing", + "volatileDependencies","webSettings","wordVbaData","worksheet","wsSortMap","xlBinaryIndex", + "xlExternalLinkPath/xlAlternateStartup","xlExternalLinkPath/xlLibrary","xlExternalLinkPath/xlPathMissing", + "xlExternalLinkPath/xlStartup","xlIntlMacrosheet","xlMacrosheet","xmlMaps" + ))); } \ No newline at end of file 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 55518772f..17e88c48b 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 @@ -25,6 +25,8 @@ package org.apache.poi.poifs.crypt.dsig.services; import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; +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 java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -89,7 +91,16 @@ public class RelationshipTransformService extends TransformService { public static class RelationshipTransformParameterSpec implements TransformParameterSpec { List sourceIds = new ArrayList(); public void addRelationshipReference(String relationshipId) { - sourceIds.add(relationshipId); + /********************************* + * TEST CODE - REMOVE ME !!!!!!!!!!!!!! + */ + if ("rId2".equals(relationshipId)) { + sourceIds.add(0, relationshipId); + } else if ("rId4".equals(relationshipId)) { + sourceIds.add(2, relationshipId); + } else { + sourceIds.add(relationshipId); + } } public boolean hasSourceIds() { return !sourceIds.isEmpty(); @@ -163,15 +174,13 @@ public class RelationshipTransformService extends TransformService { LOG.log(POILogger.DEBUG, "marshallParams(parent,context)"); DOMStructure domParent = (DOMStructure) parent; Element parentNode = (Element)domParent.getNode(); - // parentNode.setAttributeNS(XML_NS, "xmlns:mdssi", XML_DIGSIG_NS); Document doc = parentNode.getOwnerDocument(); for (String sourceId : this.sourceIds) { - RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance(); - relRef.addNewRelationshipReference().setSourceId(sourceId); - Node n = relRef.getRelationshipReference().getDomNode(); - n = doc.importNode(n, true); - parentNode.appendChild(n); + Element el = doc.createElementNS(OO_DIGSIG_NS, "mdssi:RelationshipReference"); + el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS); + el.setAttribute("SourceId", sourceId); + parentNode.appendChild(el); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index 7078f3c09..6af7c3f48 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -72,6 +72,7 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObject; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjects; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDvAspect; /** * Represents a SpreadsheetML drawing @@ -426,7 +427,8 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing