aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/sl
diff options
context:
space:
mode:
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/BKUHeader.java32
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java47
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java48
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java9
4 files changed, 107 insertions, 29 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUHeader.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUHeader.java
new file mode 100644
index 00000000..7733e78a
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUHeader.java
@@ -0,0 +1,32 @@
+package at.gv.egiz.sl.util;
+
+public class BKUHeader {
+ private String name;
+ private String value;
+
+ public BKUHeader(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + " = " + getValue();
+ }
+}
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 8907711a..e1c7bf40 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
@@ -31,6 +31,7 @@ import java.nio.charset.Charset;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
+import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
@@ -69,7 +70,8 @@ public class BKUSLConnector extends BaseSLConnector {
return builder.build();
}
- private String performHttpRequestToBKU(String xmlRequest, RequestPackage pack, SignParameter parameter)
+ private String performHttpRequestToBKU(String xmlRequest,
+ RequestPackage pack, SignParameter parameter)
throws ClientProtocolException, IOException, IllegalStateException {
CloseableHttpClient client = null;
try {
@@ -82,16 +84,17 @@ public class BKUSLConnector extends BaseSLConnector {
entityBuilder.addTextBody(XMLREQUEST, xmlRequest,
ContentType.TEXT_XML);
- if(parameter != null) {
+ if (parameter != null) {
String transactionId = parameter.getTransactionId();
- if(transactionId != null) {
+ if (transactionId != null) {
entityBuilder.addTextBody("TransactionId_", transactionId);
}
}
-
- if(pack != null && pack.getSignatureData() != null) {
- entityBuilder.addBinaryBody("fileupload",
- PDFUtils.blackOutSignature(pack.getSignatureData(), pack.getByteRange()));
+
+ if (pack != null && pack.getSignatureData() != null) {
+ entityBuilder.addBinaryBody("fileupload", PDFUtils
+ .blackOutSignature(pack.getSignatureData(),
+ pack.getByteRange()));
}
post.setEntity(entityBuilder.build());
@@ -99,6 +102,19 @@ 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);
+ }
+ }
+ }
+
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
@@ -110,20 +126,21 @@ public class BKUSLConnector extends BaseSLConnector {
rd.close();
response = null;
rd = null;
-
+
logger.trace(result.toString());
return result.toString();
} catch (PDFIOException e) {
throw new PdfAsWrappedIOException(e);
} finally {
- if(client != null) {
+ if (client != null) {
client.close();
}
}
}
public InfoboxReadResponseType sendInfoboxReadRequest(
- InfoboxReadRequestType request, SignParameter parameter) throws PdfAsException {
+ InfoboxReadRequestType request, SignParameter parameter)
+ throws PdfAsException {
JAXBElement<?> element = null;
String slRequest;
try {
@@ -131,7 +148,8 @@ public class BKUSLConnector extends BaseSLConnector {
.createInfoboxReadRequest(request));
logger.trace(slRequest);
- String slResponse = performHttpRequestToBKU(slRequest, null, parameter);
+ String slResponse = performHttpRequestToBKU(slRequest, null,
+ parameter);
element = (JAXBElement<?>) SLMarschaller
.unmarshalFromString(slResponse);
@@ -161,8 +179,8 @@ public class BKUSLConnector extends BaseSLConnector {
throw new PdfAsException("error.pdf.io.03");
}
- public CreateCMSSignatureResponseType sendCMSRequest(
- RequestPackage pack, SignParameter parameter) throws PdfAsException {
+ public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack,
+ SignParameter parameter) throws PdfAsException {
JAXBElement<?> element = null;
String slRequest;
try {
@@ -170,7 +188,8 @@ public class BKUSLConnector extends BaseSLConnector {
.createCreateCMSSignatureRequest(pack.getRequestType()));
logger.debug(slRequest);
- String slResponse = performHttpRequestToBKU(slRequest, pack, parameter);
+ String slResponse = performHttpRequestToBKU(slRequest, pack,
+ parameter);
element = (JAXBElement<?>) SLMarschaller
.unmarshalFromString(slResponse);
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 19dc3d76..49a450af 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
@@ -31,6 +31,7 @@ import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.egiz.pdfas.common.exceptions.ErrorConstants;
import at.gv.egiz.pdfas.common.exceptions.PDFASError;
import at.gv.egiz.pdfas.common.exceptions.PdfAsErrorCarrier;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
@@ -48,7 +49,9 @@ import at.gv.egiz.sl.schema.InfoboxReadResponseType;
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);
@@ -58,7 +61,8 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
this.connector = connector;
}
- public X509Certificate getCertificate(SignParameter parameter) throws PdfAsException {
+ public X509Certificate getCertificate(SignParameter parameter)
+ throws PdfAsException {
X509Certificate certificate = null;
try {
InfoboxReadRequestType request = connector
@@ -83,25 +87,43 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
return certificate;
}
- public byte[] sign(byte[] input, int[] byteRange,
- SignParameter parameter, RequestedSignature requestedSignature) throws PdfAsException {
- RequestPackage pack = connector.createCMSRequest(
- input, byteRange, parameter);
- CreateCMSSignatureResponseType response = connector
- .sendCMSRequest(pack, parameter);
-
+ public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter,
+ RequestedSignature requestedSignature) throws PdfAsException {
+ RequestPackage pack = connector.createCMSRequest(input, byteRange,
+ parameter);
+ CreateCMSSignatureResponseType response = connector.sendCMSRequest(
+ pack, parameter);
+
+ Iterator<BKUHeader> bkuHeaderIt = pack.getHeaders().iterator();
+
+ requestedSignature.getStatus().getMetaInformations()
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE);
+ while (bkuHeaderIt.hasNext()) {
+ BKUHeader header = bkuHeaderIt.next();
+ if ("Server".equalsIgnoreCase(header.getName())) {
+ requestedSignature
+ .getStatus()
+ .getMetaInformations()
+ .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION,
+ header.getValue());
+ break;
+ }
+ }
+
VerifyResult verifyResult;
try {
- verifyResult = SignatureUtils.verifySignature(response.getCMSSignature(), input);
+ verifyResult = SignatureUtils.verifySignature(
+ response.getCMSSignature(), input);
} catch (PDFASError e) {
throw new PdfAsErrorCarrier(e);
}
- if(!StreamUtils.dataCompare(requestedSignature.getCertificate().getFingerprintSHA(),
- ((X509Certificate)verifyResult.getSignerCertificate()).getFingerprintSHA())) {
+ 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 fccd800d..f08184d2 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,12 +23,16 @@
******************************************************************************/
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;
@@ -48,6 +52,7 @@ public class RequestPackage {
public void setByteRange(int[] byteRange) {
this.byteRange = byteRange;
}
-
-
+ public List<BKUHeader> getHeaders() {
+ return headers;
+ }
}