rollback invalid commit - r1799740

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1799742 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-06-24 09:20:02 +00:00
parent 6aae53935a
commit 85963a56f7
7 changed files with 286 additions and 252 deletions

View File

@ -18,13 +18,7 @@ package org.apache.poi.openxml4j.opc;
import java.net.URI;
import java.net.URISyntaxException;
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 java.util.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
@ -49,14 +43,14 @@ public final class PackageRelationshipCollection implements
private final static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
/**
* Package relationships by ID.
* Package relationships ordered by ID.
*/
private final Map<String, PackageRelationship> relationshipsByID = new LinkedHashMap<String, PackageRelationship>();
private TreeMap<String, PackageRelationship> relationshipsByID;
/**
* Package relationships by type.
* Package relationships ordered by type.
*/
private final Map<String, PackageRelationship> relationshipsByType = new LinkedHashMap<String, PackageRelationship>();
private TreeMap<String, PackageRelationship> relationshipsByType;
/**
* A lookup of internal relationships to avoid
@ -94,6 +88,8 @@ public final class PackageRelationshipCollection implements
* Constructor.
*/
PackageRelationshipCollection() {
relationshipsByID = new TreeMap<String, PackageRelationship>();
relationshipsByType = new TreeMap<String, PackageRelationship>();
}
/**
@ -108,18 +104,20 @@ public final class PackageRelationshipCollection implements
* @param filter
* Relationship type filter.
*/
public PackageRelationshipCollection(PackageRelationshipCollection coll, String filter) {
public PackageRelationshipCollection(PackageRelationshipCollection coll,
String filter) {
this();
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);
}
@ -132,7 +130,8 @@ 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);
}
@ -148,15 +147,16 @@ 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 {
if (container == null) {
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
throws InvalidFormatException {
this();
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,7 +179,8 @@ 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;
@ -262,15 +263,13 @@ 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;
@ -288,10 +287,10 @@ public final class PackageRelationshipCollection implements
}
/**
* Get the number of relationships in the collection.
* Get the numbe rof relationships in the collection.
*/
public int size() {
return relationshipsByID.size();
return relationshipsByID.values().size();
}
/**
@ -325,14 +324,12 @@ 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 */
@ -381,7 +378,6 @@ public final class PackageRelationshipCollection implements
/**
* Get this collection's iterator.
*/
@Override
public Iterator<PackageRelationship> iterator() {
return relationshipsByID.values().iterator();
}
@ -398,9 +394,8 @@ public final class PackageRelationshipCollection implements
public Iterator<PackageRelationship> iterator(String typeFilter) {
ArrayList<PackageRelationship> retArr = new ArrayList<PackageRelationship>();
for (PackageRelationship rel : relationshipsByID.values()) {
if (rel.getRelationshipType().equals(typeFilter)) {
if (rel.getRelationshipType().equals(typeFilter))
retArr.add(rel);
}
}
return retArr.iterator();
}

View File

@ -511,7 +511,7 @@ public class SignatureInfo implements SignatureConfigurable {
/*
* JSR105 ds:Signature creation
*/
String signatureValueId = null; // signatureConfig.getPackageSignatureId() + "-signature-value";
String signatureValueId = signatureConfig.getPackageSignatureId() + "-signature-value";
javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory
.newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(),
signatureValueId);

View File

@ -40,46 +40,27 @@ 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
@ -105,7 +86,6 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu
}
}
@Override
public void setSignatureConfig(SignatureConfig signatureConfig) {
this.signatureConfig = signatureConfig;
}

View File

@ -29,9 +29,6 @@ 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;
@ -49,7 +46,6 @@ 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;
@ -64,7 +60,6 @@ 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;
@ -76,12 +71,12 @@ import com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document;
/**
* Office OpenXML Signature Facet implementation.
*
* @author fcorneli
* @see <a href="http://msdn.microsoft.com/en-us/library/cc313071.aspx">[MS-OFFCRYPTO]: Office Document Cryptography Structure</a>
*/
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(
@ -104,15 +99,16 @@ public class OOXMLSignatureFacet extends SignatureFacet {
addManifestReferences(manifestReferences);
Manifest manifest = getSignatureFactory().newManifest(manifestReferences);
String objectId = "idPackageObject"; // really has to be this value.
List<XMLStructure> objectContent = new ArrayList<XMLStructure>();
objectContent.add(manifest);
addSignatureTime(document, objectContent);
XMLObject xo = getSignatureFactory().newXMLObject(objectContent, ID_PACKAGE_OBJECT, null, null);
XMLObject xo = getSignatureFactory().newXMLObject(objectContent, objectId, null, null);
objects.add(xo);
Reference reference = newReference("#"+ID_PACKAGE_OBJECT, null, XML_DIGSIG_NS+"Object", null, null);
Reference reference = newReference("#" + objectId, null, XML_DIGSIG_NS+"Object", null, null);
references.add(reference);
}
@ -125,7 +121,7 @@ public class OOXMLSignatureFacet extends SignatureFacet {
Set<String> digestedPartNames = new HashSet<String>();
for (PackagePart pp : relsEntryNames) {
final String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
PackageRelationshipCollection prc;
try {
@ -148,19 +144,21 @@ public class OOXMLSignatureFacet extends SignatureFacet {
continue;
}
if (!isSignedRelationship(relationshipType)) {
continue;
}
if (!isSignedRelationship(relationshipType)) continue;
parameterSpec.addRelationshipReference(relationship.getId());
String partName = normalizePartName(relationship.getTargetURI(), baseUri);
// We only digest a part once.
if (digestedPartNames.contains(partName)) {
continue;
// TODO: find a better way ...
String partName = relationship.getTargetURI().toString();
if (!partName.startsWith(baseUri)) {
partName = baseUri + partName;
}
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 {
@ -177,45 +175,25 @@ public class OOXMLSignatureFacet extends SignatureFacet {
continue;
}
String uri = partName + "?ContentType=" + contentType;
Reference reference = newReference(uri, null, null, null, null);
manifestReferences.add(reference);
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);
}
}
if (parameterSpec.hasSourceIds()) {
List<Transform> transforms = new ArrayList<Transform>();
transforms.add(newTransform(RelationshipTransformService.TRANSFORM_URI, parameterSpec));
transforms.add(newTransform(CanonicalizationMethod.INCLUSIVE));
String uri = normalizePartName(pp.getPartName().getURI(), baseUri)
String uri = pp.getPartName().getName()
+ "?ContentType=application/vnd.openxmlformats-package.relationships+xml";
Reference reference = newReference(uri, transforms, null, null, null);
manifestReferences.add(reference);
}
}
Collections.sort(manifestReferences, new Comparator<Reference>() {
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;
}
@ -242,8 +220,8 @@ public class OOXMLSignatureFacet extends SignatureFacet {
List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();
signaturePropertyContent.add(signatureTimeSignatureProperty);
SignatureProperties signatureProperties = getSignatureFactory()
.newSignatureProperties(signaturePropertyContent, null);
// "id-signature-time-" + signatureConfig.getExecutionTime());
.newSignatureProperties(signaturePropertyContent,
"id-signature-time-" + signatureConfig.getExecutionTime());
objectContent.add(signatureProperties);
}
@ -255,25 +233,7 @@ public class OOXMLSignatureFacet extends SignatureFacet {
SignatureInfoV1Document sigV1 = SignatureInfoV1Document.Factory.newInstance();
CTSignatureInfoV1 ctSigV1 = sigV1.addNewSignatureInfoV1();
// 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);
ctSigV1.setManifestHashAlgorithm(signatureConfig.getDigestMethodUri());
Element n = (Element)document.importNode(ctSigV1.getDomNode(), true);
n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS);
@ -308,33 +268,208 @@ public class OOXMLSignatureFacet extends SignatureFacet {
protected static boolean isSignedRelationship(String relationshipType) {
LOG.log(POILogger.DEBUG, "relationship type: " + relationshipType);
String rt = relationshipType.replaceFirst(".*/relationships/", "");
return (signed.contains(rt) || rt.endsWith("customXml"));
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;
}
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).
*/
private static final Set<String> signed = Collections.unmodifiableSet(new HashSet<String>(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"
)));
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" //
};
}

View File

@ -25,8 +25,6 @@
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;
@ -91,16 +89,7 @@ public class RelationshipTransformService extends TransformService {
public static class RelationshipTransformParameterSpec implements TransformParameterSpec {
List<String> sourceIds = new ArrayList<String>();
public void addRelationshipReference(String 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);
}
sourceIds.add(relationshipId);
}
public boolean hasSourceIds() {
return !sourceIds.isEmpty();
@ -174,13 +163,15 @@ 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) {
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);
RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
relRef.addNewRelationshipReference().setSourceId(sourceId);
Node n = relRef.getRelationshipReference().getDomNode();
n = doc.importNode(n, true);
parentNode.appendChild(n);
}
}

View File

@ -72,7 +72,6 @@ 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
@ -427,8 +426,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
CTOleObject ole1 = oo.addNewOleObject();
ole1.setProgId("Packager Shell Object");
ole1.setDvAspect(STDvAspect.DVASPECT_ICON);
ole1.setProgId("Package");
ole1.setShapeId(shapeId);
ole1.setId(olePR.getId());

View File

@ -44,7 +44,6 @@ import java.net.URL;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.X509CRL;
@ -55,9 +54,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.xml.bind.DatatypeConverter;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
@ -122,67 +118,6 @@ public class TestSignatureInfo {
additionalJar == null || additionalJar.trim().length() == 0);
}
@Test
public void bug61182() throws Exception {
// MessageDigest md = MessageDigest.getInstance("SHA-1");
// InputStream fis2 = new FileInputStream("tmp/sigtest/idPackageObject.xml");
// byte dig[] = md.digest(IOUtils.toByteArray(fis2));
// fis2.close();
//
// String digStr = DatatypeConverter.printBase64Binary(dig);
// System.out.println(digStr);
KeyStore keystore = KeyStore.getInstance("PKCS12");
String password = "test", alias = "test";
InputStream is = new FileInputStream("tmp/sigtest/test.pfx");
keystore.load(is, password.toCharArray());
is.close();
Key key = keystore.getKey(alias, password.toCharArray());
x509 = (X509Certificate)keystore.getCertificate(alias);
keyPair = new KeyPair(x509.getPublicKey(), (PrivateKey)key);
SignatureConfig signatureConfig = new SignatureConfig();
signatureConfig.setKey(keyPair.getPrivate());
signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
// 2017-06-21T14:03:54Z
Calendar oldCal = Calendar.getInstance(LocaleUtil.TIMEZONE_UTC, Locale.ROOT);
oldCal.set(2017, 5, 21, 14, 03, 54);
signatureConfig.setExecutionTime(oldCal.getTime());
signatureConfig.setDigestAlgo(HashAlgorithm.sha1);
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(signatureConfig);
File origFile = new File("tmp/sigtest/excel-unsigned.xlsx");
File testFile = new File("tmp/sigtest/excel-poi.xlsx");
InputStream fis = new FileInputStream(origFile);
OutputStream fos = new FileOutputStream(testFile);
IOUtils.copy(fis, fos);
fos.close();
fis.close();
OPCPackage pkg = OPCPackage.open(testFile, PackageAccess.READ_WRITE);
signatureConfig.setOpcPackage(pkg);
si.confirmSignature();
assertTrue(si.verifySignature());
pkg.close();
// OPCPackage pkgPoi = OPCPackage.open(new File("tmp/sigtest/excel-poi.xlsx"), PackageAccess.READ);
// signatureConfig.setOpcPackage(pkgPoi);
// assertTrue(si.verifySignature());
// pkgPoi.revert();
// OPCPackage pkg2016 = OPCPackage.open(new File("tmp/sigtest/excel-signed.xlsx"), PackageAccess.READ);
// signatureConfig.setOpcPackage(pkg2016);
// assertTrue(si.verifySignature());
// pkg2016.revert();
}
@Test
public void office2007prettyPrintedRels() throws Exception {
OPCPackage pkg = OPCPackage.open(testdata.getFile("office2007prettyPrintedRels.docx"), PackageAccess.READ);