Search in sources :

Example 11 with SignatureInfo

use of org.apache.poi.poifs.crypt.dsig.SignatureInfo in project poi by apache.

the class TestSignatureInfo method bug58630.

@Test
public void bug58630() throws Exception {
    // test deletion of sheet 0 and signing
    File tpl = copy(testdata.getFile("bug58630.xlsx"));
    SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook) WorkbookFactory.create(tpl), 10);
    wb1.setCompressTempFiles(true);
    wb1.removeSheetAt(0);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    wb1.write(os);
    wb1.close();
    OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(os.toByteArray()));
    initKeyPair("Test", "CN=Test");
    SignatureConfig signatureConfig = new SignatureConfig();
    signatureConfig.setKey(keyPair.getPrivate());
    signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
    signatureConfig.setOpcPackage(pkg);
    SignatureInfo si = new SignatureInfo();
    si.setSignatureConfig(signatureConfig);
    si.confirmSignature();
    assertTrue("invalid signature", si.verifySignature());
    pkg.close();
}
Also used : SignatureInfo(org.apache.poi.poifs.crypt.dsig.SignatureInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SignatureConfig(org.apache.poi.poifs.crypt.dsig.SignatureConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Aggregations

SignatureConfig (org.apache.poi.poifs.crypt.dsig.SignatureConfig)11 SignatureInfo (org.apache.poi.poifs.crypt.dsig.SignatureInfo)11 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)10 Test (org.junit.Test)10 X509Certificate (java.security.cert.X509Certificate)7 ArrayList (java.util.ArrayList)7 SignaturePart (org.apache.poi.poifs.crypt.dsig.SignatureInfo.SignaturePart)7 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)2 SignatureDocument (org.w3.x2000.x09.xmldsig.SignatureDocument)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 KeyStore (java.security.KeyStore)1