import java.util.List;\r
import java.util.Locale;\r
import java.util.Set;\r
-import java.util.TimeZone;\r
\r
import javax.xml.XMLConstants;\r
import javax.xml.crypto.XMLStructure;\r
references.add(reference);\r
}\r
\r
+ @SuppressWarnings("resource")\r
protected void addManifestReferences(List<Reference> manifestReferences)\r
throws XMLSignatureException {\r
\r
parameterSpec.addRelationshipReference(relationship.getId());\r
\r
// TODO: find a better way ...\r
- String partName = baseUri + relationship.getTargetURI().toString();\r
+ String partName = relationship.getTargetURI().toString();\r
+ if (!partName.startsWith(baseUri)) {\r
+ partName = baseUri + partName;\r
+ }\r
try {\r
partName = new URI(partName).normalize().getPath().replace('\\', '/');\r
LOG.log(POILogger.DEBUG, "part name: " + partName);\r
import static org.junit.Assert.assertNotNull;\r
import static org.junit.Assert.assertTrue;\r
\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
import java.io.File;\r
import java.io.FileInputStream;\r
import java.io.FileOutputStream;\r
import org.apache.poi.poifs.crypt.dsig.services.RevocationDataService;\r
import org.apache.poi.poifs.crypt.dsig.services.TimeStampService;\r
import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;\r
+import org.apache.poi.ss.usermodel.WorkbookFactory;\r
import org.apache.poi.util.DocumentHelper;\r
import org.apache.poi.util.IOUtils;\r
import org.apache.poi.util.LocaleUtil;\r
import org.apache.poi.util.POILogFactory;\r
import org.apache.poi.util.POILogger;\r
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;\r
import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
import org.apache.xmlbeans.XmlObject;\r
import org.bouncycastle.asn1.x509.KeyUsage;\r
public void testManipulation() throws Exception {\r
// sign & validate\r
String testFile = "hello-world-unsigned.xlsx";\r
+ @SuppressWarnings("resource")\r
OPCPackage pkg = OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE);\r
sign(pkg, "Test", "CN=Test", 1);\r
\r
try {\r
si.confirmSignature();\r
} catch (RuntimeException e) {\r
+ pkg.close();\r
// only allow a ConnectException because of timeout, we see this in Jenkins from time to time...\r
if(e.getCause() == null) {\r
throw e;\r
}\r
}\r
}\r
+\r
+ @Test\r
+ public void bug58630() throws Exception {\r
+ // test deletion of sheet 0 and signing\r
+ File tpl = copy(testdata.getFile("bug58630.xlsx"));\r
+ SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook)WorkbookFactory.create(tpl), 10);\r
+ wb1.setCompressTempFiles(true);\r
+ wb1.removeSheetAt(0);\r
+ ByteArrayOutputStream os = new ByteArrayOutputStream();\r
+ wb1.write(os);\r
+ wb1.close();\r
+ OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(os.toByteArray()));\r
+ \r
+ initKeyPair("Test", "CN=Test");\r
+ SignatureConfig signatureConfig = new SignatureConfig();\r
+ signatureConfig.setKey(keyPair.getPrivate());\r
+ signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));\r
+ signatureConfig.setOpcPackage(pkg);\r
+ \r
+ SignatureInfo si = new SignatureInfo();\r
+ si.setSignatureConfig(signatureConfig);\r
+ si.confirmSignature();\r
+ assertTrue("invalid signature", si.verifySignature());\r
+ \r
+ pkg.close();\r
+ }\r
\r
\r
private void sign(OPCPackage pkgCopy, String alias, String signerDn, int signerCount) throws Exception {\r