summaryrefslogtreecommitdiff
path: root/pdf-over-signer/pdf-over-sigpdfas4/src
diff options
context:
space:
mode:
authorTobias Kellner <imcybot@gmail.com>2015-10-07 06:17:42 +0200
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-10-08 17:56:11 +0200
commitd9b7f8f0ed2befcd0bbfa80c84c6a89e190ff481 (patch)
treedc4eaa95debfd8c139a9ead03cf5e002b944e1e8 /pdf-over-signer/pdf-over-sigpdfas4/src
parent7776caf451bc69219c1455234378c919710595b4 (diff)
downloadpdf-over-d9b7f8f0ed2befcd0bbfa80c84c6a89e190ff481.tar.gz
pdf-over-d9b7f8f0ed2befcd0bbfa80c84c6a89e190ff481.tar.bz2
pdf-over-d9b7f8f0ed2befcd0bbfa80c84c6a89e190ff481.zip
Add keystore signing
Diffstat (limited to 'pdf-over-signer/pdf-over-sigpdfas4/src')
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java13
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java48
2 files changed, 55 insertions, 6 deletions
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
index efce1c6e..344c2e7e 100644
--- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
@@ -23,6 +23,7 @@ import at.gv.egiz.pdfas.lib.api.Configuration;
import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.PdfAs;
import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
import at.gv.egiz.pdfas.sigs.pades.PAdESSigner;
import at.gv.egiz.sl.util.ISLConnector;
@@ -115,8 +116,16 @@ public class PdfAs4Signer implements Signer {
IConfigurationConstants.SL_REQUEST_TYPE_BASE64 :
IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD);
- ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector());
- param.setPlainSigner(new PAdESSigner(connector));
+ IPlainSigner signer;
+ if (sstate.hasBKUConnector()) {
+ ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector());
+ signer = new PAdESSigner(connector);
+ } else if (sstate.hasKSSigner()) {
+ signer = sstate.getKSSigner();
+ } else {
+ throw new SignatureException("SigningState doesn't have a signer");
+ }
+ param.setPlainSigner(signer);
pdfas.sign(param);
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
index ec2efdae..71be5577 100644
--- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
@@ -21,8 +21,12 @@ import java.io.ByteArrayOutputStream;
import at.asit.pdfover.signator.BkuSlConnector;
import at.asit.pdfover.signator.SLRequest;
import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SignatureException;
import at.asit.pdfover.signator.SigningState;
+import at.gv.egiz.pdfas.common.exceptions.PDFASError;
+import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore;
/**
* Signing State for PDFAS Wrapper
@@ -46,7 +50,9 @@ public class PdfAs4SigningState implements SigningState {
private ByteArrayOutputStream output;
- private BkuSlConnector connector;
+ private BkuSlConnector bkuconnector = null;
+
+ private IPlainSigner kssigner = null;
private boolean useBase64Request;
@@ -139,13 +145,47 @@ public class PdfAs4SigningState implements SigningState {
*/
@Override
public void setBKUConnector(BkuSlConnector connector) {
- this.connector = connector;
+ this.bkuconnector = connector;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#setKSSigner(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void setKSSigner(String file, String alias, String kspassword,
+ String keypassword, String type) throws SignatureException {
+ try {
+ this.kssigner = new PAdESSignerKeystore(file, alias, kspassword, keypassword, type);
+ } catch (PDFASError e) {
+ throw new SignatureException(e);
+ }
+ }
+
+ /**
+ * @return whether a BKU connector was set
+ */
+ public boolean hasBKUConnector() {
+ return this.bkuconnector != null;
}
/**
- * @return the connector
+ * @return the BKU connector
*/
public BkuSlConnector getBKUConnector() {
- return this.connector;
+ return this.bkuconnector;
+ }
+
+ /**
+ * @return whether a KS signer was set
+ */
+ public boolean hasKSSigner() {
+ return this.kssigner != null;
+ }
+
+ /**
+ * @return the KS signer
+ */
+ public IPlainSigner getKSSigner() {
+ return this.kssigner;
}
}