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
This commit is contained in:
parent
61b0ecbd4b
commit
6aae53935a
@ -18,7 +18,13 @@ package org.apache.poi.openxml4j.opc;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
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.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
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);
|
private final static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package relationships ordered by ID.
|
* Package relationships by ID.
|
||||||
*/
|
*/
|
||||||
private TreeMap<String, PackageRelationship> relationshipsByID;
|
private final Map<String, PackageRelationship> relationshipsByID = new LinkedHashMap<String, PackageRelationship>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package relationships ordered by type.
|
* Package relationships by type.
|
||||||
*/
|
*/
|
||||||
private TreeMap<String, PackageRelationship> relationshipsByType;
|
private final Map<String, PackageRelationship> relationshipsByType = new LinkedHashMap<String, PackageRelationship>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lookup of internal relationships to avoid
|
* A lookup of internal relationships to avoid
|
||||||
@ -88,8 +94,6 @@ public final class PackageRelationshipCollection implements
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
PackageRelationshipCollection() {
|
PackageRelationshipCollection() {
|
||||||
relationshipsByID = new TreeMap<String, PackageRelationship>();
|
|
||||||
relationshipsByType = new TreeMap<String, PackageRelationship>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,20 +108,18 @@ public final class PackageRelationshipCollection implements
|
|||||||
* @param filter
|
* @param filter
|
||||||
* Relationship type filter.
|
* Relationship type filter.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(PackageRelationshipCollection coll,
|
public PackageRelationshipCollection(PackageRelationshipCollection coll, String filter) {
|
||||||
String filter) {
|
|
||||||
this();
|
|
||||||
for (PackageRelationship rel : coll.relationshipsByID.values()) {
|
for (PackageRelationship rel : coll.relationshipsByID.values()) {
|
||||||
if (filter == null || rel.getRelationshipType().equals(filter))
|
if (filter == null || rel.getRelationshipType().equals(filter)) {
|
||||||
addRelationship(rel);
|
addRelationship(rel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(OPCPackage container)
|
public PackageRelationshipCollection(OPCPackage container) throws InvalidFormatException {
|
||||||
throws InvalidFormatException {
|
|
||||||
this(container, null);
|
this(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +132,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
* @throws InvalidOperationException
|
* @throws InvalidOperationException
|
||||||
* Throws if the specified part is a relationship part.
|
* Throws if the specified part is a relationship part.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(PackagePart part)
|
public PackageRelationshipCollection(PackagePart part) throws InvalidFormatException {
|
||||||
throws InvalidFormatException {
|
|
||||||
this(part._container, part);
|
this(part._container, part);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,16 +148,15 @@ public final class PackageRelationshipCollection implements
|
|||||||
* If an error occurs during the parsing of the relatinships
|
* If an error occurs during the parsing of the relatinships
|
||||||
* part fo the specified part.
|
* part fo the specified part.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
|
public PackageRelationshipCollection(OPCPackage container, PackagePart part) throws InvalidFormatException {
|
||||||
throws InvalidFormatException {
|
if (container == null) {
|
||||||
this();
|
|
||||||
|
|
||||||
if (container == null)
|
|
||||||
throw new IllegalArgumentException("container needs to be specified");
|
throw new IllegalArgumentException("container needs to be specified");
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the specified part is not a relationship part
|
// Check if the specified part is not a relationship part
|
||||||
if (part != null && part.isRelationshipPart())
|
if (part != null && part.isRelationshipPart()) {
|
||||||
throw new IllegalArgumentException("part");
|
throw new IllegalArgumentException("part");
|
||||||
|
}
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.sourcePart = part;
|
this.sourcePart = part;
|
||||||
@ -179,8 +179,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
* @throws InvalidOperationException
|
* @throws InvalidOperationException
|
||||||
* Throws if the specified part is a relationship part.
|
* Throws if the specified part is a relationship part.
|
||||||
*/
|
*/
|
||||||
private static PackagePartName getRelationshipPartName(PackagePart part)
|
private static PackagePartName getRelationshipPartName(PackagePart part) throws InvalidOperationException {
|
||||||
throws InvalidOperationException {
|
|
||||||
PackagePartName partName;
|
PackagePartName partName;
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
||||||
@ -263,13 +262,15 @@ public final class PackageRelationshipCollection implements
|
|||||||
* Must be a value between [0-relationships_count-1]
|
* Must be a value between [0-relationships_count-1]
|
||||||
*/
|
*/
|
||||||
public PackageRelationship getRelationship(int index) {
|
public PackageRelationship getRelationship(int index) {
|
||||||
if (index < 0 || index > relationshipsByID.values().size())
|
if (index < 0 || index > relationshipsByID.values().size()) {
|
||||||
throw new IllegalArgumentException("index");
|
throw new IllegalArgumentException("index");
|
||||||
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (PackageRelationship rel : relationshipsByID.values()) {
|
for (PackageRelationship rel : relationshipsByID.values()) {
|
||||||
if (index == i++)
|
if (index == i++) {
|
||||||
return rel;
|
return rel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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() {
|
public int size() {
|
||||||
return relationshipsByID.values().size();
|
return relationshipsByID.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,12 +325,14 @@ public final class PackageRelationshipCollection implements
|
|||||||
|
|
||||||
/* Check OPC Compliance */
|
/* Check OPC Compliance */
|
||||||
// Check Rule M4.1
|
// Check Rule M4.1
|
||||||
if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
|
if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES)) {
|
||||||
if (!fCorePropertiesRelationship)
|
if (!fCorePropertiesRelationship) {
|
||||||
fCorePropertiesRelationship = true;
|
fCorePropertiesRelationship = true;
|
||||||
else
|
} else {
|
||||||
throw new InvalidFormatException(
|
throw new InvalidFormatException(
|
||||||
"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
|
"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* End OPC Compliance */
|
/* End OPC Compliance */
|
||||||
|
|
||||||
@ -378,6 +381,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
/**
|
/**
|
||||||
* Get this collection's iterator.
|
* Get this collection's iterator.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Iterator<PackageRelationship> iterator() {
|
public Iterator<PackageRelationship> iterator() {
|
||||||
return relationshipsByID.values().iterator();
|
return relationshipsByID.values().iterator();
|
||||||
}
|
}
|
||||||
@ -394,8 +398,9 @@ public final class PackageRelationshipCollection implements
|
|||||||
public Iterator<PackageRelationship> iterator(String typeFilter) {
|
public Iterator<PackageRelationship> iterator(String typeFilter) {
|
||||||
ArrayList<PackageRelationship> retArr = new ArrayList<PackageRelationship>();
|
ArrayList<PackageRelationship> retArr = new ArrayList<PackageRelationship>();
|
||||||
for (PackageRelationship rel : relationshipsByID.values()) {
|
for (PackageRelationship rel : relationshipsByID.values()) {
|
||||||
if (rel.getRelationshipType().equals(typeFilter))
|
if (rel.getRelationshipType().equals(typeFilter)) {
|
||||||
retArr.add(rel);
|
retArr.add(rel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return retArr.iterator();
|
return retArr.iterator();
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ public class SignatureInfo implements SignatureConfigurable {
|
|||||||
/*
|
/*
|
||||||
* JSR105 ds:Signature creation
|
* JSR105 ds:Signature creation
|
||||||
*/
|
*/
|
||||||
String signatureValueId = signatureConfig.getPackageSignatureId() + "-signature-value";
|
String signatureValueId = null; // signatureConfig.getPackageSignatureId() + "-signature-value";
|
||||||
javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory
|
javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory
|
||||||
.newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(),
|
.newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(),
|
||||||
signatureValueId);
|
signatureValueId);
|
||||||
|
@ -40,27 +40,46 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu
|
|||||||
this.target.set(target);
|
this.target.set(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
if (!(e instanceof MutationEvent)) return;
|
if (!(e instanceof MutationEvent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MutationEvent mutEvt = (MutationEvent)e;
|
MutationEvent mutEvt = (MutationEvent)e;
|
||||||
EventTarget et = mutEvt.getTarget();
|
EventTarget et = mutEvt.getTarget();
|
||||||
if (!(et instanceof Element)) return;
|
if (!(et instanceof Element)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
handleElement((Element)et);
|
handleElement((Element)et);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleElement(Element el) {
|
public void handleElement(Element el) {
|
||||||
EventTarget target = this.target.get();
|
EventTarget target = this.target.get();
|
||||||
String packageId = signatureConfig.getPackageSignatureId();
|
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")) {
|
if (el.hasAttribute("Id")) {
|
||||||
el.setIdAttribute("Id", true);
|
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
|
// helper method to keep it in one place
|
||||||
@ -86,6 +105,7 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setSignatureConfig(SignatureConfig signatureConfig) {
|
public void setSignatureConfig(SignatureConfig signatureConfig) {
|
||||||
this.signatureConfig = signatureConfig;
|
this.signatureConfig = signatureConfig;
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
This product contains an ASLv2 licensed version of the OOXML signer
|
This product contains an ASLv2 licensed version of the OOXML signer
|
||||||
package from the eID Applet project
|
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.
|
Copyright (C) 2008-2014 FedICT.
|
||||||
================================================================= */
|
================================================================= */
|
||||||
|
|
||||||
package org.apache.poi.poifs.crypt.dsig.facets;
|
package org.apache.poi.poifs.crypt.dsig.facets;
|
||||||
|
|
||||||
@ -29,6 +29,9 @@ import java.net.URISyntaxException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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.XMLObject;
|
||||||
import javax.xml.crypto.dsig.XMLSignatureException;
|
import javax.xml.crypto.dsig.XMLSignatureException;
|
||||||
|
|
||||||
|
import org.apache.poi.hpsf.ClassID;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
import org.apache.poi.openxml4j.opc.ContentTypes;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
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.LocaleUtil;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
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.CTSignatureTime;
|
||||||
import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument;
|
import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@ -70,13 +75,13 @@ import com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Office OpenXML Signature Facet implementation.
|
* 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>
|
* @see <a href="http://msdn.microsoft.com/en-us/library/cc313071.aspx">[MS-OFFCRYPTO]: Office Document Cryptography Structure</a>
|
||||||
*/
|
*/
|
||||||
public class OOXMLSignatureFacet extends SignatureFacet {
|
public class OOXMLSignatureFacet extends SignatureFacet {
|
||||||
|
|
||||||
private static final POILogger LOG = POILogFactory.getLogger(OOXMLSignatureFacet.class);
|
private static final POILogger LOG = POILogFactory.getLogger(OOXMLSignatureFacet.class);
|
||||||
|
private static final String ID_PACKAGE_OBJECT = "idPackageObject";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preSign(
|
public void preSign(
|
||||||
@ -98,17 +103,16 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
List<Reference> manifestReferences = new ArrayList<Reference>();
|
List<Reference> manifestReferences = new ArrayList<Reference>();
|
||||||
addManifestReferences(manifestReferences);
|
addManifestReferences(manifestReferences);
|
||||||
Manifest manifest = getSignatureFactory().newManifest(manifestReferences);
|
Manifest manifest = getSignatureFactory().newManifest(manifestReferences);
|
||||||
|
|
||||||
String objectId = "idPackageObject"; // really has to be this value.
|
|
||||||
List<XMLStructure> objectContent = new ArrayList<XMLStructure>();
|
List<XMLStructure> objectContent = new ArrayList<XMLStructure>();
|
||||||
objectContent.add(manifest);
|
objectContent.add(manifest);
|
||||||
|
|
||||||
addSignatureTime(document, objectContent);
|
addSignatureTime(document, objectContent);
|
||||||
|
|
||||||
XMLObject xo = getSignatureFactory().newXMLObject(objectContent, objectId, null, null);
|
XMLObject xo = getSignatureFactory().newXMLObject(objectContent, ID_PACKAGE_OBJECT, null, null);
|
||||||
objects.add(xo);
|
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);
|
references.add(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
|
|
||||||
Set<String> digestedPartNames = new HashSet<String>();
|
Set<String> digestedPartNames = new HashSet<String>();
|
||||||
for (PackagePart pp : relsEntryNames) {
|
for (PackagePart pp : relsEntryNames) {
|
||||||
String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
|
final String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
|
||||||
|
|
||||||
PackageRelationshipCollection prc;
|
PackageRelationshipCollection prc;
|
||||||
try {
|
try {
|
||||||
@ -130,11 +134,11 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new XMLSignatureException("Invalid relationship descriptor: "+pp.getPartName().getName(), e);
|
throw new XMLSignatureException("Invalid relationship descriptor: "+pp.getPartName().getName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec();
|
RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec();
|
||||||
for (PackageRelationship relationship : prc) {
|
for (PackageRelationship relationship : prc) {
|
||||||
String relationshipType = relationship.getRelationshipType();
|
String relationshipType = relationship.getRelationshipType();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ECMA-376 Part 2 - 3rd edition
|
* ECMA-376 Part 2 - 3rd edition
|
||||||
* 13.2.4.16 Manifest Element
|
* 13.2.4.16 Manifest Element
|
||||||
@ -144,22 +148,20 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSignedRelationship(relationshipType)) continue;
|
if (!isSignedRelationship(relationshipType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
parameterSpec.addRelationshipReference(relationship.getId());
|
parameterSpec.addRelationshipReference(relationship.getId());
|
||||||
|
|
||||||
// TODO: find a better way ...
|
String partName = normalizePartName(relationship.getTargetURI(), baseUri);
|
||||||
String partName = relationship.getTargetURI().toString();
|
|
||||||
if (!partName.startsWith(baseUri)) {
|
// We only digest a part once.
|
||||||
partName = baseUri + partName;
|
if (digestedPartNames.contains(partName)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
digestedPartNames.add(partName);
|
||||||
partName = new URI(partName).normalize().getPath().replace('\\', '/');
|
|
||||||
LOG.log(POILogger.DEBUG, "part name: " + partName);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new XMLSignatureException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
String contentType;
|
String contentType;
|
||||||
try {
|
try {
|
||||||
PackagePartName relName = PackagingURIHelper.createPartName(partName);
|
PackagePartName relName = PackagingURIHelper.createPartName(partName);
|
||||||
@ -168,32 +170,52 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new XMLSignatureException(e);
|
throw new XMLSignatureException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationshipType.endsWith("customXml")
|
if (relationshipType.endsWith("customXml")
|
||||||
&& !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) {
|
&& !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) {
|
||||||
LOG.log(POILogger.DEBUG, "skipping customXml with content type: " + contentType);
|
LOG.log(POILogger.DEBUG, "skipping customXml with content type: " + contentType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!digestedPartNames.contains(partName)) {
|
String uri = partName + "?ContentType=" + contentType;
|
||||||
// We only digest a part once.
|
Reference reference = newReference(uri, null, null, null, null);
|
||||||
String uri = partName + "?ContentType=" + contentType;
|
manifestReferences.add(reference);
|
||||||
Reference reference = newReference(uri, null, null, null, null);
|
|
||||||
manifestReferences.add(reference);
|
|
||||||
digestedPartNames.add(partName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameterSpec.hasSourceIds()) {
|
if (parameterSpec.hasSourceIds()) {
|
||||||
List<Transform> transforms = new ArrayList<Transform>();
|
List<Transform> transforms = new ArrayList<Transform>();
|
||||||
transforms.add(newTransform(RelationshipTransformService.TRANSFORM_URI, parameterSpec));
|
transforms.add(newTransform(RelationshipTransformService.TRANSFORM_URI, parameterSpec));
|
||||||
transforms.add(newTransform(CanonicalizationMethod.INCLUSIVE));
|
transforms.add(newTransform(CanonicalizationMethod.INCLUSIVE));
|
||||||
String uri = pp.getPartName().getName()
|
String uri = normalizePartName(pp.getPartName().getURI(), baseUri)
|
||||||
+ "?ContentType=application/vnd.openxmlformats-package.relationships+xml";
|
+ "?ContentType=application/vnd.openxmlformats-package.relationships+xml";
|
||||||
Reference reference = newReference(uri, transforms, null, null, null);
|
Reference reference = newReference(uri, transforms, null, null, null);
|
||||||
manifestReferences.add(reference);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -220,8 +242,8 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();
|
List<SignatureProperty> signaturePropertyContent = new ArrayList<SignatureProperty>();
|
||||||
signaturePropertyContent.add(signatureTimeSignatureProperty);
|
signaturePropertyContent.add(signatureTimeSignatureProperty);
|
||||||
SignatureProperties signatureProperties = getSignatureFactory()
|
SignatureProperties signatureProperties = getSignatureFactory()
|
||||||
.newSignatureProperties(signaturePropertyContent,
|
.newSignatureProperties(signaturePropertyContent, null);
|
||||||
"id-signature-time-" + signatureConfig.getExecutionTime());
|
// "id-signature-time-" + signatureConfig.getExecutionTime());
|
||||||
objectContent.add(signatureProperties);
|
objectContent.add(signatureProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,10 +255,28 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
|
|
||||||
SignatureInfoV1Document sigV1 = SignatureInfoV1Document.Factory.newInstance();
|
SignatureInfoV1Document sigV1 = SignatureInfoV1Document.Factory.newInstance();
|
||||||
CTSignatureInfoV1 ctSigV1 = sigV1.addNewSignatureInfoV1();
|
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);
|
Element n = (Element)document.importNode(ctSigV1.getDomNode(), true);
|
||||||
n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS);
|
n.setAttributeNS(XML_NS, XMLConstants.XMLNS_ATTRIBUTE, MS_DIGSIG_NS);
|
||||||
|
|
||||||
List<XMLStructure> signatureInfoContent = new ArrayList<XMLStructure>();
|
List<XMLStructure> signatureInfoContent = new ArrayList<XMLStructure>();
|
||||||
signatureInfoContent.add(new DOMStructure(n));
|
signatureInfoContent.add(new DOMStructure(n));
|
||||||
SignatureProperty signatureInfoSignatureProperty = getSignatureFactory()
|
SignatureProperty signatureInfoSignatureProperty = getSignatureFactory()
|
||||||
@ -268,208 +308,33 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
|
|
||||||
protected static boolean isSignedRelationship(String relationshipType) {
|
protected static boolean isSignedRelationship(String relationshipType) {
|
||||||
LOG.log(POILogger.DEBUG, "relationship type: " + relationshipType);
|
LOG.log(POILogger.DEBUG, "relationship type: " + relationshipType);
|
||||||
for (String signedTypeExtension : signed) {
|
String rt = relationshipType.replaceFirst(".*/relationships/", "");
|
||||||
if (relationshipType.endsWith(signedTypeExtension)) {
|
return (signed.contains(rt) || rt.endsWith("customXml"));
|
||||||
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).
|
* Office 2010 list of signed types (extensions).
|
||||||
*/
|
*/
|
||||||
public static final String[] signed = {
|
private static final Set<String> signed = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
|
||||||
"powerPivotData", //
|
"activeXControlBinary","aFChunk","attachedTemplate","attachedToolbars","audio","calcChain","chart","chartColorStyle",
|
||||||
"activeXControlBinary", //
|
"chartLayout","chartsheet","chartStyle","chartUserShapes","commentAuthors","comments","connections","connectorXml",
|
||||||
"attachedToolbars", //
|
"control","ctrlProp","customData","customData","customProperty","customXml","diagram","diagramColors",
|
||||||
"connectorXml", //
|
"diagramColorsHeader","diagramData","diagramDrawing","diagramLayout","diagramLayoutHeader","diagramQuickStyle",
|
||||||
"downRev", //
|
"diagramQuickStyleHeader","dialogsheet","dictionary","documentParts","downRev","drawing","endnotes","externalLink",
|
||||||
"functionPrototypes", //
|
"externalLinkPath","font","fontTable","footer","footnotes","functionPrototypes","glossaryDocument","graphicFrameDoc",
|
||||||
"graphicFrameDoc", //
|
"groupShapeXml","handoutMaster","hdphoto","header","hyperlink","image","ink","inkXml","keyMapCustomizations",
|
||||||
"groupShapeXml", //
|
"legacyDiagramText","legacyDocTextInfo","mailMergeHeaderSource","mailMergeRecipientData","mailMergeSource","media",
|
||||||
"ink", //
|
"notesMaster","notesSlide","numbering","officeDocument","officeDocument","oleObject","package","pictureXml",
|
||||||
"keyMapCustomizations", //
|
"pivotCacheDefinition","pivotCacheRecords","pivotTable","powerPivotData","presProps","printerSettings","queryTable",
|
||||||
"legacyDiagramText", //
|
"recipientData","settings","shapeXml","sharedStrings","sheetMetadata","slicer","slicer","slicerCache","slicerCache",
|
||||||
"legacyDocTextInfo", //
|
"slide","slideLayout","slideMaster","slideUpdateInfo","slideUpdateUrl","smartTags","styles","stylesWithEffects",
|
||||||
"officeDocument", //
|
"table","tableSingleCells","tableStyles","tags","theme","themeOverride","timeline","timelineCache","transform",
|
||||||
"pictureXml", //
|
"ui/altText","ui/buttonSize","ui/controlID","ui/description","ui/enabled","ui/extensibility","ui/extensibility",
|
||||||
"shapeXml", //
|
"ui/helperText","ui/imageID","ui/imageMso","ui/keyTip","ui/label","ui/lcid","ui/loud","ui/pressed","ui/progID",
|
||||||
"smartTags", //
|
"ui/ribbonID","ui/showImage","ui/showLabel","ui/supertip","ui/target","ui/text","ui/title","ui/tooltip",
|
||||||
"ui/altText", //
|
"ui/userCustomization","ui/visible","userXmlData","vbaProject","video","viewProps","vmlDrawing",
|
||||||
"ui/buttonSize", //
|
"volatileDependencies","webSettings","wordVbaData","worksheet","wsSortMap","xlBinaryIndex",
|
||||||
"ui/controlID", //
|
"xlExternalLinkPath/xlAlternateStartup","xlExternalLinkPath/xlLibrary","xlExternalLinkPath/xlPathMissing",
|
||||||
"ui/description", //
|
"xlExternalLinkPath/xlStartup","xlIntlMacrosheet","xlMacrosheet","xmlMaps"
|
||||||
"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" //
|
|
||||||
};
|
|
||||||
}
|
}
|
@ -25,6 +25,8 @@
|
|||||||
package org.apache.poi.poifs.crypt.dsig.services;
|
package org.apache.poi.poifs.crypt.dsig.services;
|
||||||
|
|
||||||
import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
|
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.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -89,7 +91,16 @@ public class RelationshipTransformService extends TransformService {
|
|||||||
public static class RelationshipTransformParameterSpec implements TransformParameterSpec {
|
public static class RelationshipTransformParameterSpec implements TransformParameterSpec {
|
||||||
List<String> sourceIds = new ArrayList<String>();
|
List<String> sourceIds = new ArrayList<String>();
|
||||||
public void addRelationshipReference(String relationshipId) {
|
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() {
|
public boolean hasSourceIds() {
|
||||||
return !sourceIds.isEmpty();
|
return !sourceIds.isEmpty();
|
||||||
@ -163,15 +174,13 @@ public class RelationshipTransformService extends TransformService {
|
|||||||
LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
|
LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
|
||||||
DOMStructure domParent = (DOMStructure) parent;
|
DOMStructure domParent = (DOMStructure) parent;
|
||||||
Element parentNode = (Element)domParent.getNode();
|
Element parentNode = (Element)domParent.getNode();
|
||||||
// parentNode.setAttributeNS(XML_NS, "xmlns:mdssi", XML_DIGSIG_NS);
|
|
||||||
Document doc = parentNode.getOwnerDocument();
|
Document doc = parentNode.getOwnerDocument();
|
||||||
|
|
||||||
for (String sourceId : this.sourceIds) {
|
for (String sourceId : this.sourceIds) {
|
||||||
RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
|
Element el = doc.createElementNS(OO_DIGSIG_NS, "mdssi:RelationshipReference");
|
||||||
relRef.addNewRelationshipReference().setSourceId(sourceId);
|
el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);
|
||||||
Node n = relRef.getRelationshipReference().getDomNode();
|
el.setAttribute("SourceId", sourceId);
|
||||||
n = doc.importNode(n, true);
|
parentNode.appendChild(el);
|
||||||
parentNode.appendChild(n);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.CTOleObject;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjects;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjects;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDvAspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a SpreadsheetML drawing
|
* Represents a SpreadsheetML drawing
|
||||||
@ -426,7 +427,8 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
|
|||||||
CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
|
CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
|
||||||
|
|
||||||
CTOleObject ole1 = oo.addNewOleObject();
|
CTOleObject ole1 = oo.addNewOleObject();
|
||||||
ole1.setProgId("Package");
|
ole1.setProgId("Packager Shell Object");
|
||||||
|
ole1.setDvAspect(STDvAspect.DVASPECT_ICON);
|
||||||
ole1.setShapeId(shapeId);
|
ole1.setShapeId(shapeId);
|
||||||
ole1.setId(olePR.getId());
|
ole1.setId(olePR.getId());
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ import java.net.URL;
|
|||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
import java.security.MessageDigest;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
import java.security.cert.X509CRL;
|
import java.security.cert.X509CRL;
|
||||||
@ -54,6 +55,9 @@ import java.util.Collections;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POITestCase;
|
import org.apache.poi.POITestCase;
|
||||||
@ -118,6 +122,67 @@ public class TestSignatureInfo {
|
|||||||
additionalJar == null || additionalJar.trim().length() == 0);
|
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
|
@Test
|
||||||
public void office2007prettyPrintedRels() throws Exception {
|
public void office2007prettyPrintedRels() throws Exception {
|
||||||
OPCPackage pkg = OPCPackage.open(testdata.getFile("office2007prettyPrintedRels.docx"), PackageAccess.READ);
|
OPCPackage pkg = OPCPackage.open(testdata.getFile("office2007prettyPrintedRels.docx"), PackageAccess.READ);
|
||||||
|
Loading…
Reference in New Issue
Block a user