import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.xml.XMLConstants;
import javax.xml.crypto.URIReference;
XMLObject xo = sigFac.newXMLObject(objectContent, ID_PACKAGE_OBJECT, null, null);
objects.add(xo);
- Reference reference = newReference(signatureInfo, "#"+ID_PACKAGE_OBJECT, null, XML_DIGSIG_NS+"Object", null, null);
+ Reference reference = newReference(signatureInfo, "#"+ID_PACKAGE_OBJECT, null, XML_DIGSIG_NS+"Object");
references.add(reference);
}
* "The producer shall not create a Manifest element that references any data outside of the package."
*/
if (TargetMode.EXTERNAL == relationship.getTargetMode()) {
+ // only add the relationship but not the reference/data
+ parameterSpec.addRelationshipReference(relationship.getId());
continue;
}
}
String uri = partName + "?ContentType=" + contentType;
- Reference reference = newReference(signatureInfo, uri, null, null, null, null);
+ Reference reference = newReference(signatureInfo, uri, null, null);
manifestReferences.add(reference);
}
transforms.add(newTransform(signatureInfo, CanonicalizationMethod.INCLUSIVE));
String uri = normalizePartName(pp.getPartName().getURI(), baseUri)
+ "?ContentType=application/vnd.openxmlformats-package.relationships+xml";
- Reference reference = newReference(signatureInfo, uri, transforms, null, null, null);
+ Reference reference = newReference(signatureInfo, uri, transforms, null);
manifestReferences.add(reference);
}
}
String objectId = "idOfficeObject";
objects.add(sigFac.newXMLObject(objectContent, objectId, null, null));
- Reference reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object", null, null);
+ Reference reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object");
references.add(reference);
Base64.Encoder enc = Base64.getEncoder();
DOMStructure tn = new DOMStructure(document.createTextNode(enc.encodeToString(imageValid)));
objects.add(sigFac.newXMLObject(Collections.singletonList(tn), objectId, null, null));
- reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object", null, null);
+ reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object");
references.add(reference);
}
DOMStructure tn = new DOMStructure(document.createTextNode(enc.encodeToString(imageInvalid)));
objects.add(sigFac.newXMLObject(Collections.singletonList(tn), objectId, null, null));
- reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object", null, null);
+ reference = newReference(signatureInfo, "#" + objectId, null, XML_DIGSIG_NS+"Object");
references.add(reference);
}
}
/**
* Office 2010 list of signed types (extensions).
*/
- private static final Set<String> signed = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ private static final Set<String> signed = Stream.of(
"activeXControlBinary", "aFChunk", "attachedTemplate", "attachedToolbars", "audio", "calcChain", "chart", "chartColorStyle",
"chartLayout", "chartsheet", "chartStyle", "chartUserShapes", "commentAuthors", "comments", "connections", "connectorXml",
"control", "ctrlProp", "customData", "customData", "customProperty", "customXml", "diagram", "diagramColors",
"volatileDependencies", "webSettings", "wordVbaData", "worksheet", "wsSortMap", "xlBinaryIndex",
"xlExternalLinkPath/xlAlternateStartup", "xlExternalLinkPath/xlLibrary", "xlExternalLinkPath/xlPathMissing",
"xlExternalLinkPath/xlStartup", "xlIntlMacrosheet", "xlMacrosheet", "xmlMaps"
- )));
+ ).collect(Collectors.toSet());
}
\ No newline at end of file
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFSignatureLine;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFHyperlinkRun;
import org.apache.poi.xwpf.usermodel.XWPFSignatureLine;
import org.apache.xmlbeans.SystemProperties;
import org.apache.xmlbeans.XmlException;
}
}
+ // Test signing of external references / hyperlinks
+ @Test
+ void bug65214() throws Exception {
+ initKeyPair();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try (XWPFDocument doc = new XWPFDocument()) {
+ XWPFHyperlinkRun r = doc.createParagraph().createHyperlinkRun("http://poi.apache.org");
+ r.setText("Hyperlink");
+ r.setUnderline(UnderlinePatterns.SINGLE);
+ r.setUnderlineColor("0000FF");
+ doc.write(bos);
+ }
+
+ SignatureConfig signatureConfig = new SignatureConfig();
+ signatureConfig.setKey(keyPair.getPrivate());
+ signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
+ signatureConfig.setDigestAlgo(HashAlgorithm.sha256);
+ try (OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(bos.toByteArray()))) {
+ SignatureInfo si = new SignatureInfo();
+ si.setOpcPackage(pkg);
+ si.setSignatureConfig(signatureConfig);
+ si.confirmSignature();
+ bos.reset();
+ pkg.save(bos);
+ } catch (EncryptedDocumentException e) {
+ assumeTrue(e.getMessage().startsWith("Export Restrictions"));
+ }
+
+ try (OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(bos.toByteArray()))) {
+ SignatureInfo si = new SignatureInfo();
+ si.setOpcPackage(pkg);
+ si.setSignatureConfig(signatureConfig);
+ si.verifySignature();
+ } catch (EncryptedDocumentException e) {
+ assumeTrue(e.getMessage().startsWith("Export Restrictions"));
+ }
+ }
+
@Test
void bug58630() throws Exception {
// test deletion of sheet 0 and signing