From 7e13c51fb1c225b61c05239d4d44824622bce275 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Fri, 24 Oct 2014 14:53:55 +0200 Subject: Test cases added --- .../java/at/gv/egiz/pdfas/cli/test/CorruptPDF.java | 77 ++++++++++++++++++++++ .../egiz/pdfas/cli/test/ProduceSignBlockImg.java | 33 ++++++++++ 2 files changed, 110 insertions(+) create mode 100644 pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/CorruptPDF.java create mode 100644 pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/ProduceSignBlockImg.java (limited to 'pdf-as-cli/src/test/java') diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/CorruptPDF.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/CorruptPDF.java new file mode 100644 index 00000000..b107474f --- /dev/null +++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/CorruptPDF.java @@ -0,0 +1,77 @@ +package at.gv.egiz.pdfas.cli.test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +import javax.activation.DataSource; +import javax.activation.FileDataSource; + +import at.gv.egiz.pdfas.common.exceptions.PDFASError; +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import at.gv.egiz.pdfas.lib.api.PdfAsFactory; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.impl.PdfAsImpl; +import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; +import at.gv.egiz.sl.util.BKUSLConnector; + +public class CorruptPDF { + + public static void main(String[] args) throws IOException, PDFASError { + final File CFG_FOLDER = new File( + "/home/afitzek/.pdfas"); + + final File OUT_FOLDER = new File("/home/afitzek/tmp"); + + final String PROFILE = "UNTERSCHREIBE_AT_Q_EN"; + + final File LOGO = new File(CFG_FOLDER, + "images/WIRELESS_MONTENEGRO_logo.png"); + + final String SCALE_TO_FIT = "41.102;31.802"; + + final File FILE_TO_BE_SIGNED = new File("/home/afitzek/empty.pdf"); + + PdfAsImpl pdfAsImpl = new PdfAsImpl(CFG_FOLDER); + + FileOutputStream fout = new FileOutputStream(new File(OUT_FOLDER, + PROFILE + ".pdf")); + + DataSource toBeSignedDataSource = new FileDataSource(FILE_TO_BE_SIGNED); + + Configuration configuration = pdfAsImpl.getConfiguration(); + + //configuration.setValue(REGISTER_PROVIDER, Boolean.toString(true)); + + PdfAs pdfAsApi = PdfAsFactory.createPdfAs((ISettings) configuration); + + Configuration config = pdfAsApi.getConfiguration(); + + if (SCALE_TO_FIT != null) { + + config.setValue("sig_obj." + PROFILE + + ".table.main.Style.imagescaletofit", SCALE_TO_FIT); + + } + + config.setValue("sig_obj." + PROFILE + ".value.SIG_LABEL", + LOGO.getCanonicalPath()); + + SignParameter signParameters = PdfAsFactory.createSignParameter(config, + toBeSignedDataSource, fout); + + signParameters.setSignatureProfileId(PROFILE); + + signParameters.setPlainSigner(new PAdESSigner( + new BKUSLConnector(config))); + + pdfAsApi.sign(signParameters); + + fout.flush(); + + fout.close(); + } + +} diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/ProduceSignBlockImg.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/ProduceSignBlockImg.java new file mode 100644 index 00000000..a39a0a40 --- /dev/null +++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/ProduceSignBlockImg.java @@ -0,0 +1,33 @@ +package at.gv.egiz.pdfas.cli.test; + +import iaik.x509.X509Certificate; + +import java.awt.Image; +import java.awt.image.RenderedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.cert.CertificateException; + +import javax.imageio.ImageIO; + +import at.gv.egiz.pdfas.common.exceptions.PDFASError; +import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import at.gv.egiz.pdfas.lib.api.PdfAsFactory; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; + +public class ProduceSignBlockImg { + public static void main(String[] args) throws IOException, PDFASError, CertificateException { + PdfAs pdfAs = PdfAsFactory.createPdfAs(new File("/home/afitzek/.pdfas")); + + Configuration cfg = pdfAs.getConfiguration(); + + SignParameter signParameter = PdfAsFactory.createSignParameter(cfg, null, null); + + X509Certificate crt = new X509Certificate(new FileInputStream("/home/afitzek/qualified.cer")); + + Image img = pdfAs.generateVisibleSignaturePreview(signParameter, crt, 256); + ImageIO.write((RenderedImage) img, "png", new File("/tmp/block.png")); + } +} -- cgit v1.2.3