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:
parent
6aae53935a
commit
85963a56f7
@ -18,13 +18,7 @@ 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.ArrayList;
|
import java.util.*;
|
||||||
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;
|
||||||
@ -49,14 +43,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 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
|
* A lookup of internal relationships to avoid
|
||||||
@ -94,6 +88,8 @@ public final class PackageRelationshipCollection implements
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
PackageRelationshipCollection() {
|
PackageRelationshipCollection() {
|
||||||
|
relationshipsByID = new TreeMap<String, PackageRelationship>();
|
||||||
|
relationshipsByType = new TreeMap<String, PackageRelationship>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,18 +104,20 @@ public final class PackageRelationshipCollection implements
|
|||||||
* @param filter
|
* @param filter
|
||||||
* Relationship type filter.
|
* Relationship type filter.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(PackageRelationshipCollection coll, String filter) {
|
public PackageRelationshipCollection(PackageRelationshipCollection coll,
|
||||||
|
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) throws InvalidFormatException {
|
public PackageRelationshipCollection(OPCPackage container)
|
||||||
|
throws InvalidFormatException {
|
||||||
this(container, null);
|
this(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +130,8 @@ 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) throws InvalidFormatException {
|
public PackageRelationshipCollection(PackagePart part)
|
||||||
|
throws InvalidFormatException {
|
||||||
this(part._container, part);
|
this(part._container, part);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,15 +147,16 @@ 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) throws InvalidFormatException {
|
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
|
||||||
if (container == null) {
|
throws InvalidFormatException {
|
||||||
|
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,7 +179,8 @@ 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) throws InvalidOperationException {
|
private static PackagePartName getRelationshipPartName(PackagePart part)
|
||||||
|
throws InvalidOperationException {
|
||||||
PackagePartName partName;
|
PackagePartName partName;
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
partName = PackagingURIHelper.PACKAGE_ROOT_PART_NAME;
|
||||||
@ -262,15 +263,13 @@ 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;
|
||||||
@ -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() {
|
public int size() {
|
||||||
return relationshipsByID.size();
|
return relationshipsByID.values().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,14 +324,12 @@ 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 */
|
||||||
|
|
||||||
@ -381,7 +378,6 @@ 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();
|
||||||
}
|
}
|
||||||
@ -398,9 +394,8 @@ 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 = null; // signatureConfig.getPackageSignatureId() + "-signature-value";
|
String signatureValueId = 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,46 +40,27 @@ 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)) {
|
if (!(e instanceof MutationEvent)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
MutationEvent mutEvt = (MutationEvent)e;
|
MutationEvent mutEvt = (MutationEvent)e;
|
||||||
EventTarget et = mutEvt.getTarget();
|
EventTarget et = mutEvt.getTarget();
|
||||||
if (!(et instanceof Element)) {
|
if (!(et instanceof Element)) return;
|
||||||
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
|
||||||
@ -105,7 +86,6 @@ public class SignatureMarshalListener implements EventListener, SignatureConfigu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSignatureConfig(SignatureConfig signatureConfig) {
|
public void setSignatureConfig(SignatureConfig signatureConfig) {
|
||||||
this.signatureConfig = signatureConfig;
|
this.signatureConfig = signatureConfig;
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,6 @@ 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;
|
||||||
@ -49,7 +46,6 @@ 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;
|
||||||
@ -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.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;
|
||||||
@ -76,12 +71,12 @@ 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(
|
||||||
@ -104,15 +99,16 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
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, ID_PACKAGE_OBJECT, null, null);
|
XMLObject xo = getSignatureFactory().newXMLObject(objectContent, objectId, null, null);
|
||||||
objects.add(xo);
|
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);
|
references.add(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +121,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) {
|
||||||
final String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
|
String baseUri = pp.getPartName().getName().replaceFirst("(.*)/_rels/.*", "$1");
|
||||||
|
|
||||||
PackageRelationshipCollection prc;
|
PackageRelationshipCollection prc;
|
||||||
try {
|
try {
|
||||||
@ -148,19 +144,21 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSignedRelationship(relationshipType)) {
|
if (!isSignedRelationship(relationshipType)) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameterSpec.addRelationshipReference(relationship.getId());
|
parameterSpec.addRelationshipReference(relationship.getId());
|
||||||
|
|
||||||
String partName = normalizePartName(relationship.getTargetURI(), baseUri);
|
// TODO: find a better way ...
|
||||||
|
String partName = relationship.getTargetURI().toString();
|
||||||
// We only digest a part once.
|
if (!partName.startsWith(baseUri)) {
|
||||||
if (digestedPartNames.contains(partName)) {
|
partName = baseUri + 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;
|
String contentType;
|
||||||
try {
|
try {
|
||||||
@ -177,45 +175,25 @@ public class OOXMLSignatureFacet extends SignatureFacet {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String uri = partName + "?ContentType=" + contentType;
|
if (!digestedPartNames.contains(partName)) {
|
||||||
Reference reference = newReference(uri, null, null, null, null);
|
// We only digest a part once.
|
||||||
manifestReferences.add(reference);
|
String uri = partName + "?ContentType=" + contentType;
|
||||||
|
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 = normalizePartName(pp.getPartName().getURI(), baseUri)
|
String uri = pp.getPartName().getName()
|
||||||
+ "?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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -242,8 +220,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, null);
|
.newSignatureProperties(signaturePropertyContent,
|
||||||
// "id-signature-time-" + signatureConfig.getExecutionTime());
|
"id-signature-time-" + signatureConfig.getExecutionTime());
|
||||||
objectContent.add(signatureProperties);
|
objectContent.add(signatureProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,25 +233,7 @@ 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);
|
||||||
|
|
||||||
@ -308,33 +268,208 @@ 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);
|
||||||
String rt = relationshipType.replaceFirst(".*/relationships/", "");
|
for (String signedTypeExtension : signed) {
|
||||||
return (signed.contains(rt) || rt.endsWith("customXml"));
|
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).
|
* Office 2010 list of signed types (extensions).
|
||||||
*/
|
*/
|
||||||
private static final Set<String> signed = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
|
public static final String[] signed = {
|
||||||
"activeXControlBinary","aFChunk","attachedTemplate","attachedToolbars","audio","calcChain","chart","chartColorStyle",
|
"powerPivotData", //
|
||||||
"chartLayout","chartsheet","chartStyle","chartUserShapes","commentAuthors","comments","connections","connectorXml",
|
"activeXControlBinary", //
|
||||||
"control","ctrlProp","customData","customData","customProperty","customXml","diagram","diagramColors",
|
"attachedToolbars", //
|
||||||
"diagramColorsHeader","diagramData","diagramDrawing","diagramLayout","diagramLayoutHeader","diagramQuickStyle",
|
"connectorXml", //
|
||||||
"diagramQuickStyleHeader","dialogsheet","dictionary","documentParts","downRev","drawing","endnotes","externalLink",
|
"downRev", //
|
||||||
"externalLinkPath","font","fontTable","footer","footnotes","functionPrototypes","glossaryDocument","graphicFrameDoc",
|
"functionPrototypes", //
|
||||||
"groupShapeXml","handoutMaster","hdphoto","header","hyperlink","image","ink","inkXml","keyMapCustomizations",
|
"graphicFrameDoc", //
|
||||||
"legacyDiagramText","legacyDocTextInfo","mailMergeHeaderSource","mailMergeRecipientData","mailMergeSource","media",
|
"groupShapeXml", //
|
||||||
"notesMaster","notesSlide","numbering","officeDocument","officeDocument","oleObject","package","pictureXml",
|
"ink", //
|
||||||
"pivotCacheDefinition","pivotCacheRecords","pivotTable","powerPivotData","presProps","printerSettings","queryTable",
|
"keyMapCustomizations", //
|
||||||
"recipientData","settings","shapeXml","sharedStrings","sheetMetadata","slicer","slicer","slicerCache","slicerCache",
|
"legacyDiagramText", //
|
||||||
"slide","slideLayout","slideMaster","slideUpdateInfo","slideUpdateUrl","smartTags","styles","stylesWithEffects",
|
"legacyDocTextInfo", //
|
||||||
"table","tableSingleCells","tableStyles","tags","theme","themeOverride","timeline","timelineCache","transform",
|
"officeDocument", //
|
||||||
"ui/altText","ui/buttonSize","ui/controlID","ui/description","ui/enabled","ui/extensibility","ui/extensibility",
|
"pictureXml", //
|
||||||
"ui/helperText","ui/imageID","ui/imageMso","ui/keyTip","ui/label","ui/lcid","ui/loud","ui/pressed","ui/progID",
|
"shapeXml", //
|
||||||
"ui/ribbonID","ui/showImage","ui/showLabel","ui/supertip","ui/target","ui/text","ui/title","ui/tooltip",
|
"smartTags", //
|
||||||
"ui/userCustomization","ui/visible","userXmlData","vbaProject","video","viewProps","vmlDrawing",
|
"ui/altText", //
|
||||||
"volatileDependencies","webSettings","wordVbaData","worksheet","wsSortMap","xlBinaryIndex",
|
"ui/buttonSize", //
|
||||||
"xlExternalLinkPath/xlAlternateStartup","xlExternalLinkPath/xlLibrary","xlExternalLinkPath/xlPathMissing",
|
"ui/controlID", //
|
||||||
"xlExternalLinkPath/xlStartup","xlIntlMacrosheet","xlMacrosheet","xmlMaps"
|
"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" //
|
||||||
|
};
|
||||||
}
|
}
|
@ -25,8 +25,6 @@
|
|||||||
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;
|
||||||
@ -91,16 +89,7 @@ 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();
|
||||||
@ -174,13 +163,15 @@ 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) {
|
||||||
Element el = doc.createElementNS(OO_DIGSIG_NS, "mdssi:RelationshipReference");
|
RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
|
||||||
el.setAttributeNS(XML_NS, "xmlns:mdssi", OO_DIGSIG_NS);
|
relRef.addNewRelationshipReference().setSourceId(sourceId);
|
||||||
el.setAttribute("SourceId", sourceId);
|
Node n = relRef.getRelationshipReference().getDomNode();
|
||||||
parentNode.appendChild(el);
|
n = doc.importNode(n, true);
|
||||||
|
parentNode.appendChild(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.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
|
||||||
@ -427,8 +426,7 @@ 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("Packager Shell Object");
|
ole1.setProgId("Package");
|
||||||
ole1.setDvAspect(STDvAspect.DVASPECT_ICON);
|
|
||||||
ole1.setShapeId(shapeId);
|
ole1.setShapeId(shapeId);
|
||||||
ole1.setId(olePR.getId());
|
ole1.setId(olePR.getId());
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ 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;
|
||||||
@ -55,9 +54,6 @@ 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;
|
||||||
@ -122,67 +118,6 @@ 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