aboutsummaryrefslogtreecommitdiff
path: root/signature-standards
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-11-12 12:26:10 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-11-12 12:26:10 +0100
commit7b2e2b640b0f392183f7927f692936950d3fabfc (patch)
treeffd4acccb62f2679ff613bf0cd8cd0850186b465 /signature-standards
parentdd43264f702c5e0351cc63835862c55f3e847634 (diff)
downloadpdf-as-4-7b2e2b640b0f392183f7927f692936950d3fabfc.tar.gz
pdf-as-4-7b2e2b640b0f392183f7927f692936950d3fabfc.tar.bz2
pdf-as-4-7b2e2b640b0f392183f7927f692936950d3fabfc.zip
SecurityLayer commands included
Diffstat (limited to 'signature-standards')
-rw-r--r--signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSigner.java72
-rw-r--r--signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/package-info.java8
-rw-r--r--signature-standards/sigs-pcks7detached/src/main/java/at/gv/egiz/pdfas/sigs/pkcs7detached/PKCS7DetachedSigner.java10
3 files changed, 87 insertions, 3 deletions
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<InfoboxAssocArrayPairType> 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);
}
}