aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/sl
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-31 09:38:35 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-31 09:38:35 +0100
commitfed2e4a84d0d7e3ffa714e7c0685247be76715fb (patch)
treeafb10f68483b2faa42c41a93bf94cc70db08cb1b /pdf-as-lib/src/main/java/at/gv/egiz/sl
parentd72748087e8a7272b68a1b5e7c2d1b7c239515d9 (diff)
downloadpdf-as-4-fed2e4a84d0d7e3ffa714e7c0685247be76715fb.tar.gz
pdf-as-4-fed2e4a84d0d7e3ffa714e7c0685247be76715fb.tar.bz2
pdf-as-4-fed2e4a84d0d7e3ffa714e7c0685247be76715fb.zip
better integration of Process Information
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/sl')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java30
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java88
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java9
3 files changed, 71 insertions, 56 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java
index e1c7bf40..15d2fb38 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java
@@ -42,6 +42,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.egiz.pdfas.common.exceptions.ErrorConstants;
import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException;
@@ -49,6 +50,7 @@ import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException;
import at.gv.egiz.pdfas.common.utils.PDFUtils;
import at.gv.egiz.pdfas.lib.api.Configuration;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.lib.impl.BKUHeaderHolder;
import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType;
import at.gv.egiz.sl.schema.ErrorResponseType;
import at.gv.egiz.sl.schema.InfoboxReadRequestType;
@@ -59,6 +61,8 @@ public class BKUSLConnector extends BaseSLConnector {
private static final Logger logger = LoggerFactory
.getLogger(BKUSLConnector.class);
+ public static final String SIGNATURE_DEVICE = "BKU";
+
private String bkuUrl;
public BKUSLConnector(Configuration config) {
@@ -102,17 +106,23 @@ public class BKUSLConnector extends BaseSLConnector {
logger.debug("Response Code : "
+ response.getStatusLine().getStatusCode());
- if(pack != null) {
- Header[] headers = response.getAllHeaders();
-
- if (headers != null) {
- for (int i = 0; i < headers.length; i++) {
- BKUHeader hdr = new BKUHeader(headers[i].getName(), headers[i].getValue());
- logger.debug("Response Header : {}",
- hdr.toString());
- pack.getHeaders().add(hdr);
+ if (parameter instanceof BKUHeaderHolder) {
+ BKUHeaderHolder holder = (BKUHeaderHolder) parameter;
+ Header[] headers = response.getAllHeaders();
+
+ if (headers != null) {
+ for (int i = 0; i < headers.length; i++) {
+ BKUHeader hdr = new BKUHeader(headers[i].getName(),
+ headers[i].getValue());
+ logger.debug("Response Header : {}", hdr.toString());
+ holder.getProcessInfo().add(hdr);
+ }
}
- }
+
+ BKUHeader hdr = new BKUHeader(ErrorConstants.STATUS_INFO_SIGDEVICE,
+ SIGNATURE_DEVICE);
+ logger.debug("Response Header : {}", hdr.toString());
+ holder.getProcessInfo().add(hdr);
}
BufferedReader rd = new BufferedReader(new InputStreamReader(
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java
index 0b6b1fff..96877828 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java
@@ -42,6 +42,7 @@ import at.gv.egiz.pdfas.common.utils.StreamUtils;
import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
+import at.gv.egiz.pdfas.lib.impl.BKUHeaderHolder;
import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature;
import at.gv.egiz.pdfas.lib.util.SignatureUtils;
import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType;
@@ -53,8 +54,6 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
public static final String SL_USE_BASE64 = "";
- public static final String SIGNATURE_DEVICE = "BKU";
-
private static final Logger logger = LoggerFactory
.getLogger(ISignatureConnectorSLWrapper.class);
@@ -86,7 +85,7 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
}
} catch (CertificateException e) {
throw new PdfAsSignatureException("error.pdf.sig.01", e);
- }
+ }
return certificate;
}
@@ -94,49 +93,62 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
RequestedSignature requestedSignature) throws PdfAsException {
RequestPackage pack = connector.createCMSRequest(input, byteRange,
parameter);
- CreateCMSSignatureResponseType response = connector.sendCMSRequest(
- pack, parameter);
+ try {
+ CreateCMSSignatureResponseType response = connector.sendCMSRequest(
+ pack, parameter);
+
+ VerifyResult verifyResult;
+ try {
+ verifyResult = SignatureUtils.verifySignature(
+ response.getCMSSignature(), input);
+ if (SettingsUtils.getBooleanValue(requestedSignature
+ .getStatus().getSettings(),
+ IConfigurationConstants.KEEP_INVALID_SIGNATURE, false)) {
+ Base64 b64 = new Base64();
+ requestedSignature
+ .getStatus()
+ .getMetaInformations()
+ .put(ErrorConstants.STATUS_INFO_INVALIDSIG,
+ b64.encodeToString(response
+ .getCMSSignature()));
+ }
+ } catch (PDFASError e) {
+ throw new PdfAsErrorCarrier(e);
+ }
- Iterator<BKUHeader> bkuHeaderIt = pack.getHeaders().iterator();
+ if (!StreamUtils.dataCompare(requestedSignature.getCertificate()
+ .getFingerprintSHA(), ((X509Certificate) verifyResult
+ .getSignerCertificate()).getFingerprintSHA())) {
+ throw new PdfAsSignatureException("Certificates missmatch!");
+ }
- requestedSignature.getStatus().getMetaInformations()
- .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE);
- while (bkuHeaderIt.hasNext()) {
- BKUHeader header = bkuHeaderIt.next();
- if ("Server".equalsIgnoreCase(header.getName())) {
- requestedSignature
+ return response.getCMSSignature();
+ } finally {
+ if (parameter instanceof BKUHeaderHolder) {
+ BKUHeaderHolder holder = (BKUHeaderHolder) parameter;
+
+ Iterator<BKUHeader> bkuHeaderIt = holder.getProcessInfo()
+ .iterator();
+
+ while (bkuHeaderIt.hasNext()) {
+ BKUHeader header = bkuHeaderIt.next();
+ if ("Server".equalsIgnoreCase(header.getName())) {
+ requestedSignature
+ .getStatus()
+ .getMetaInformations()
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION,
+ header.getValue());
+ } else if (ErrorConstants.STATUS_INFO_SIGDEVICE.equalsIgnoreCase(header.getName())) {
+ requestedSignature
.getStatus()
.getMetaInformations()
- .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION,
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICE,
header.getValue());
- break;
- }
- }
-
- VerifyResult verifyResult;
- try {
- verifyResult = SignatureUtils.verifySignature(
- response.getCMSSignature(), input);
- if(SettingsUtils.getBooleanValue(requestedSignature.getStatus().getSettings(),
- IConfigurationConstants.KEEP_INVALID_SIGNATURE, false)) {
- Base64 b64 = new Base64();
- requestedSignature
- .getStatus()
- .getMetaInformations()
- .put(ErrorConstants.STATUS_INFO_INVALIDSIG,
- b64.encodeToString(response.getCMSSignature()));
+ }
+ }
}
- } catch (PDFASError e) {
- throw new PdfAsErrorCarrier(e);
- }
-
- if (!StreamUtils.dataCompare(requestedSignature.getCertificate()
- .getFingerprintSHA(), ((X509Certificate) verifyResult
- .getSignerCertificate()).getFingerprintSHA())) {
- throw new PdfAsSignatureException("Certificates missmatch!");
}
- return response.getCMSSignature();
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java
index f08184d2..c7c778bb 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java
@@ -23,17 +23,13 @@
******************************************************************************/
package at.gv.egiz.sl.util;
-import java.util.ArrayList;
-import java.util.List;
-
import at.gv.egiz.sl.schema.CreateCMSSignatureRequestType;
public class RequestPackage {
private CreateCMSSignatureRequestType requestType;
private byte[] signatureData;
private int[] byteRange;
- private List<BKUHeader> headers = new ArrayList<BKUHeader>();
-
+
public CreateCMSSignatureRequestType getRequestType() {
return requestType;
}
@@ -52,7 +48,4 @@ public class RequestPackage {
public void setByteRange(int[] byteRange) {
this.byteRange = byteRange;
}
- public List<BKUHeader> getHeaders() {
- return headers;
- }
}