From 7b2e2b640b0f392183f7927f692936950d3fabfc Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 12 Nov 2013 12:26:10 +0100 Subject: SecurityLayer commands included --- .../at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java | 72 ++++++++++++++++++++++ .../at/gv/egiz/pdfas/sigs/pades/package-info.java | 8 +++ .../sigs/pkcs7detached/PKCS7DetachedSigner.java | 10 ++- 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java create mode 100644 signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/package-info.java (limited to 'signature-standards') diff --git a/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java new file mode 100644 index 00000000..91237d98 --- /dev/null +++ b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java @@ -0,0 +1,72 @@ +package at.gv.egiz.pdfas.sigs.pades; + +import iaik.x509.X509Certificate; + +import java.io.IOException; +import java.security.cert.CertificateException; +import java.util.Iterator; + +import org.apache.pdfbox.exceptions.SignatureException; +import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; +import at.gv.egiz.sl.CreateCMSSignatureRequestType; +import at.gv.egiz.sl.CreateCMSSignatureResponseType; +import at.gv.egiz.sl.InfoboxAssocArrayPairType; +import at.gv.egiz.sl.InfoboxReadRequestType; +import at.gv.egiz.sl.InfoboxReadResponseType; +import at.gv.egiz.sl.util.BKUSLConnector; +import at.gv.egiz.sl.util.ISLConnector; +import at.gv.egiz.sl.util.BaseSLConnector; + +public class PAdESSigner implements IPlainSigner { + + private ISLConnector connector; + + public PAdESSigner(ISLConnector connector) { + this.connector = connector; + } + + public X509Certificate getCertificate() throws PdfAsException { + X509Certificate certificate = null; + try { + InfoboxReadRequestType request = connector + .createInfoboxReadRequest(); + InfoboxReadResponseType response = connector + .sendInfoboxReadRequest(request); + + Iterator iterator = response + .getAssocArrayData().getPair().iterator(); + + while (iterator.hasNext()) { + InfoboxAssocArrayPairType pair = iterator.next(); + if (pair.getKey().equals("SecureSignatureKeypair")) { + byte[] certData = pair.getBase64Content(); + certificate = new X509Certificate(certData); + break; + } + } + } catch (CertificateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return certificate; + } + + public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException { + CreateCMSSignatureRequestType request = connector.createCMSRequest(input, byteRange); + CreateCMSSignatureResponseType response = connector.sendCMSRequest(request); + + return response.getCMSSignature(); + } + + public String getPDFSubFilter() { + return PDSignature.SUBFILTER_ETSI_CADES_DETACHED.getName(); + } + + public String getPDFFilter() { + return PDSignature.FILTER_ADOBE_PPKLITE.getName(); + } + +} diff --git a/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/package-info.java b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/package-info.java new file mode 100644 index 00000000..5c74ace3 --- /dev/null +++ b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.sigs.pades; \ No newline at end of file diff --git a/signature-standards/sigs-pcks7detached/src/main/java/at/gv/egiz/pdfas/sigs/pkcs7detached/PKCS7DetachedSigner.java b/signature-standards/sigs-pcks7detached/src/main/java/at/gv/egiz/pdfas/sigs/pkcs7detached/PKCS7DetachedSigner.java index 864a31d1..c6b12897 100644 --- a/signature-standards/sigs-pcks7detached/src/main/java/at/gv/egiz/pdfas/sigs/pkcs7detached/PKCS7DetachedSigner.java +++ b/signature-standards/sigs-pcks7detached/src/main/java/at/gv/egiz/pdfas/sigs/pkcs7detached/PKCS7DetachedSigner.java @@ -23,7 +23,9 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.exceptions.SignatureException; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; +import at.gv.egiz.pdfas.common.exceptions.PDFIOException; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; public class PKCS7DetachedSigner implements IPlainSigner { @@ -49,7 +51,7 @@ public class PKCS7DetachedSigner implements IPlainSigner { return cert; } - public byte[] sign(byte[] input) throws SignatureException, IOException { + public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException { try { SignedDataStream signed_data_stream = new SignedDataStream( new ByteArrayInputStream(input), SignedDataStream.EXPLICIT); @@ -71,9 +73,11 @@ public class PKCS7DetachedSigner implements IPlainSigner { signed_data_stream.writeTo(baos); return baos.toByteArray(); } catch (NoSuchAlgorithmException e) { - throw new SignatureException(e); + throw new PdfAsSignatureException("", e); } catch (X509ExtensionException e) { - throw new SignatureException(e); + throw new PdfAsSignatureException("", e); + } catch (IOException e) { + throw new PDFIOException("", e); } } -- cgit v1.2.3