aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/sl/util
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/sl/util')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java32
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java157
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java11
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java15
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java30
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java2
6 files changed, 170 insertions, 77 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 c0a0b8aa..afceb96f 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
@@ -37,18 +37,19 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.pdfbox.exceptions.WrappedIOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
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.sl.CreateCMSSignatureRequestType;
-import at.gv.egiz.sl.CreateCMSSignatureResponseType;
-import at.gv.egiz.sl.ErrorResponseType;
-import at.gv.egiz.sl.InfoboxReadRequestType;
-import at.gv.egiz.sl.InfoboxReadResponseType;
+import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType;
+import at.gv.egiz.sl.schema.ErrorResponseType;
+import at.gv.egiz.sl.schema.InfoboxReadRequestType;
+import at.gv.egiz.sl.schema.InfoboxReadResponseType;
public class BKUSLConnector extends BaseSLConnector {
@@ -68,7 +69,7 @@ public class BKUSLConnector extends BaseSLConnector {
return builder.build();
}
- private String performHttpRequestToBKU(String xmlRequest)
+ private String performHttpRequestToBKU(String xmlRequest, RequestPackage pack)
throws ClientProtocolException, IOException, IllegalStateException {
CloseableHttpClient client = null;
try {
@@ -80,6 +81,10 @@ public class BKUSLConnector extends BaseSLConnector {
entityBuilder.addTextBody(XMLREQUEST, xmlRequest,
ContentType.TEXT_XML);
+ if(pack != null && pack.getSignatureData() != null) {
+ entityBuilder.addBinaryBody("fileupload",
+ PDFUtils.blackOutSignature(pack.getSignatureData(), pack.getByteRange()));
+ }
post.setEntity(entityBuilder.build());
HttpResponse response = client.execute(post);
@@ -94,9 +99,14 @@ public class BKUSLConnector extends BaseSLConnector {
while ((line = rd.readLine()) != null) {
result.append(line);
}
-
+ rd.close();
+ response = null;
+ rd = null;
+
logger.trace(result.toString());
return result.toString();
+ } catch (PDFIOException e) {
+ throw new WrappedIOException(e);
} finally {
if(client != null) {
client.close();
@@ -113,7 +123,7 @@ public class BKUSLConnector extends BaseSLConnector {
.createInfoboxReadRequest(request));
logger.trace(slRequest);
- String slResponse = performHttpRequestToBKU(slRequest);
+ String slResponse = performHttpRequestToBKU(slRequest, null);
element = (JAXBElement<?>) SLMarschaller
.unmarshalFromString(slResponse);
@@ -144,15 +154,15 @@ public class BKUSLConnector extends BaseSLConnector {
}
public CreateCMSSignatureResponseType sendCMSRequest(
- CreateCMSSignatureRequestType request) throws PdfAsException {
+ RequestPackage pack) throws PdfAsException {
JAXBElement<?> element = null;
String slRequest;
try {
slRequest = SLMarschaller.marshalToString(of
- .createCreateCMSSignatureRequest(request));
+ .createCreateCMSSignatureRequest(pack.getRequestType()));
logger.debug(slRequest);
- String slResponse = performHttpRequestToBKU(slRequest);
+ String slResponse = performHttpRequestToBKU(slRequest, pack);
element = (JAXBElement<?>) SLMarschaller
.unmarshalFromString(slResponse);
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java
index d8aa2672..5321ed51 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java
@@ -30,36 +30,41 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
import at.gv.egiz.pdfas.common.utils.PDFUtils;
-import at.gv.egiz.sl.Base64OptRefContentType;
-import at.gv.egiz.sl.CMSDataObjectRequiredMetaType;
-import at.gv.egiz.sl.CreateCMSSignatureRequestType;
-import at.gv.egiz.sl.ExcludedByteRangeType;
-import at.gv.egiz.sl.InfoboxReadParamsAssocArrayType;
-import at.gv.egiz.sl.InfoboxReadParamsAssocArrayType.ReadValue;
-import at.gv.egiz.sl.InfoboxReadRequestType;
-import at.gv.egiz.sl.MetaInfoType;
-import at.gv.egiz.sl.ObjectFactory;
+import at.gv.egiz.sl.schema.Base64OptRefContentType;
+import at.gv.egiz.sl.schema.Base64XMLLocRefContentType;
+import at.gv.egiz.sl.schema.Base64XMLLocRefOptRefContentType;
+import at.gv.egiz.sl.schema.CMSDataObjectOptionalMetaType;
+import at.gv.egiz.sl.schema.CMSDataObjectRequiredMetaType;
+import at.gv.egiz.sl.schema.CreateCMSSignatureRequestType;
+import at.gv.egiz.sl.schema.DataObjectInfoType;
+import at.gv.egiz.sl.schema.ExcludedByteRangeType;
+import at.gv.egiz.sl.schema.InfoboxReadParamsAssocArrayType;
+import at.gv.egiz.sl.schema.InfoboxReadParamsAssocArrayType.ReadValue;
+import at.gv.egiz.sl.schema.InfoboxReadRequestType;
+import at.gv.egiz.sl.schema.MetaInfoType;
+import at.gv.egiz.sl.schema.ObjectFactory;
public abstract class BaseSLConnector implements ISLConnector {
- private static final Logger logger = LoggerFactory.getLogger(BaseSLConnector.class);
-
+ private static final Logger logger = LoggerFactory
+ .getLogger(BaseSLConnector.class);
+
public static final String SecureSignatureKeypair = "SecureSignatureKeypair";
-
+
public static final String PDF_MIME_TYPE = "application/pdf";
public static final String PDF_MIME_TYPE_DESC = "Adobe PDF-File";
-
+
public static final String DETACHED = "detached";
-
+
public static final String XMLREQUEST = "XMLRequest";
-
+
protected ObjectFactory of = new ObjectFactory();
-
+
public InfoboxReadRequestType createInfoboxReadRequest() {
InfoboxReadRequestType request = new InfoboxReadRequestType();
request.setInfoboxIdentifier("Certificates");
InfoboxReadParamsAssocArrayType readData = new InfoboxReadParamsAssocArrayType();
-
+
ReadValue readValue = new ReadValue();
readValue.setKey(SecureSignatureKeypair);
@@ -67,40 +72,88 @@ public abstract class BaseSLConnector implements ISLConnector {
request.setAssocArrayParameters(readData);
return request;
}
-
- public CreateCMSSignatureRequestType createCMSRequest(byte[] signatureData, int[] byteRange) throws PDFIOException {
- byte[] data = PDFUtils.blackOutSignature(signatureData, byteRange);
-
- int[] exclude_range = PDFUtils.buildExcludeRange(byteRange);
- logger.info("Exclude Byte Range: " + exclude_range[0] + " " + exclude_range[1]);
-
- // == MetaInfoType
- MetaInfoType metaInfoType = new MetaInfoType();
- metaInfoType.setMimeType(PDF_MIME_TYPE);
-
- // == Base64OptRefContentType
- Base64OptRefContentType base64OptRefContentType = new Base64OptRefContentType();
- base64OptRefContentType.setBase64Content(data);
-
- // == CMSDataObjectRequiredMetaType
- CMSDataObjectRequiredMetaType cmsDataObjectRequiredMetaType = new CMSDataObjectRequiredMetaType();
- cmsDataObjectRequiredMetaType.setMetaInfo(metaInfoType);
- cmsDataObjectRequiredMetaType.setContent(base64OptRefContentType);
- if(byteRange.length > 0) {
- ExcludedByteRangeType excludeByteRange = new ExcludedByteRangeType();
- excludeByteRange.setFrom(new BigInteger(String.valueOf(exclude_range[0])));
- excludeByteRange.setTo(new BigInteger(String.valueOf(exclude_range[1])));
- cmsDataObjectRequiredMetaType.setExcludedByteRange(excludeByteRange);
- }
-
-
- // == CreateCMSSignatureRequestType
- CreateCMSSignatureRequestType request = new CreateCMSSignatureRequestType();
- request.setKeyboxIdentifier(SecureSignatureKeypair);
- request.setDataObject(cmsDataObjectRequiredMetaType);
- request.setStructure(DETACHED);
-
- return request;
- }
+ public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange)
+ throws PDFIOException {
+ //if (base64) {
+ byte[] data = PDFUtils.blackOutSignature(signatureData, byteRange);
+
+ int[] exclude_range = PDFUtils.buildExcludeRange(byteRange);
+ logger.info("Exclude Byte Range: " + exclude_range[0] + " "
+ + exclude_range[1]);
+
+ // == MetaInfoType
+ MetaInfoType metaInfoType = new MetaInfoType();
+ metaInfoType.setMimeType(PDF_MIME_TYPE);
+
+ // == Base64OptRefContentType
+ Base64OptRefContentType base64OptRefContentType = new Base64OptRefContentType();
+ base64OptRefContentType.setBase64Content(data);
+
+ // == CMSDataObjectRequiredMetaType
+ CMSDataObjectRequiredMetaType cmsDataObjectRequiredMetaType = new CMSDataObjectRequiredMetaType();
+ cmsDataObjectRequiredMetaType.setMetaInfo(metaInfoType);
+ cmsDataObjectRequiredMetaType.setContent(base64OptRefContentType);
+ if (byteRange.length > 0) {
+ ExcludedByteRangeType excludeByteRange = new ExcludedByteRangeType();
+ excludeByteRange.setFrom(new BigInteger(String
+ .valueOf(exclude_range[0])));
+ excludeByteRange.setTo(new BigInteger(String
+ .valueOf(exclude_range[1])));
+ cmsDataObjectRequiredMetaType
+ .setExcludedByteRange(excludeByteRange);
+ }
+
+ // == CreateCMSSignatureRequestType
+ CreateCMSSignatureRequestType request = new CreateCMSSignatureRequestType();
+ request.setKeyboxIdentifier(SecureSignatureKeypair);
+ request.setDataObject(cmsDataObjectRequiredMetaType);
+ request.setStructure(DETACHED);
+
+ RequestPackage pack = new RequestPackage();
+
+ pack.setRequestType(request);
+ return pack;
+ /*} else {
+ RequestPackage pack = new RequestPackage();
+ pack.setSignatureData(signatureData);
+ pack.setByteRange(byteRange);
+
+ int[] exclude_range = PDFUtils.buildExcludeRange(byteRange);
+ logger.info("Exclude Byte Range: " + exclude_range[0] + " "
+ + exclude_range[1]);
+
+ // == MetaInfoType
+ MetaInfoType metaInfoType = new MetaInfoType();
+ metaInfoType.setMimeType(PDF_MIME_TYPE);
+
+ // == File RefContentType
+ Base64XMLLocRefOptRefContentType base64OptRefContentType = new Base64XMLLocRefOptRefContentType();
+ base64OptRefContentType.setLocRefContent("formdata:fileupload");
+
+ DataObjectInfoType cmsObject = new DataObjectInfoType();
+ cmsObject.setDataObject(base64OptRefContentType);
+ // == CMSDataObjectRequiredMetaType
+ CMSDataObjectRequiredMetaType cmsDataObjectRequiredMetaType = new CMSDataObjectRequiredMetaType();
+ cmsDataObjectRequiredMetaType.setMetaInfo(metaInfoType);
+ cmsDataObjectRequiredMetaType.setContent(value);
+ if (byteRange.length > 0) {
+ ExcludedByteRangeType excludeByteRange = new ExcludedByteRangeType();
+ excludeByteRange.setFrom(new BigInteger(String
+ .valueOf(exclude_range[0])));
+ excludeByteRange.setTo(new BigInteger(String
+ .valueOf(exclude_range[1])));
+ cmsObject.
+ .setExcludedByteRange(excludeByteRange);
+ }
+
+ // == CreateCMSSignatureRequestType
+ CreateCMSSignatureRequestType request = new CreateCMSSignatureRequestType();
+ request.setKeyboxIdentifier(SecureSignatureKeypair);
+ request.setDataObject(cmsDataObjectRequiredMetaType);
+ request.setStructure(DETACHED);
+ pack.setRequestType(request);
+ return pack;
+ }*/
+ }
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java
index 779787eb..120f2f73 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java
@@ -25,15 +25,14 @@ package at.gv.egiz.sl.util;
import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
-import at.gv.egiz.sl.CreateCMSSignatureRequestType;
-import at.gv.egiz.sl.CreateCMSSignatureResponseType;
-import at.gv.egiz.sl.InfoboxReadRequestType;
-import at.gv.egiz.sl.InfoboxReadResponseType;
+import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType;
+import at.gv.egiz.sl.schema.InfoboxReadRequestType;
+import at.gv.egiz.sl.schema.InfoboxReadResponseType;
public interface ISLConnector {
public InfoboxReadRequestType createInfoboxReadRequest();
public InfoboxReadResponseType sendInfoboxReadRequest(InfoboxReadRequestType request) throws PdfAsException;
- public CreateCMSSignatureRequestType createCMSRequest(byte[] signatureData, int[] byteRange) throws PDFIOException;
- public CreateCMSSignatureResponseType sendCMSRequest(CreateCMSSignatureRequestType request) throws PdfAsException;
+ public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange) throws PDFIOException;
+ public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack) throws PdfAsException;
}
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 edd7555e..1b9fad2a 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
@@ -40,14 +40,15 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException;
import at.gv.egiz.pdfas.lib.impl.verify.VerifyResultImpl;
-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.schema.CreateCMSSignatureResponseType;
+import at.gv.egiz.sl.schema.InfoboxAssocArrayPairType;
+import at.gv.egiz.sl.schema.InfoboxReadRequestType;
+import at.gv.egiz.sl.schema.InfoboxReadResponseType;
public class ISignatureConnectorSLWrapper implements ISignatureConnector {
+ public static final String SL_USE_BASE64 = "";
+
private static final Logger logger = LoggerFactory
.getLogger(ISignatureConnectorSLWrapper.class);
@@ -83,10 +84,10 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector {
}
public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException {
- CreateCMSSignatureRequestType request = connector.createCMSRequest(
+ RequestPackage pack = connector.createCMSRequest(
input, byteRange);
CreateCMSSignatureResponseType response = connector
- .sendCMSRequest(request);
+ .sendCMSRequest(pack);
try {
SignedData signedData = new SignedData(new ByteArrayInputStream(
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
new file mode 100644
index 00000000..e1318aa2
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/RequestPackage.java
@@ -0,0 +1,30 @@
+package at.gv.egiz.sl.util;
+
+import at.gv.egiz.sl.schema.CreateCMSSignatureRequestType;
+
+public class RequestPackage {
+ private CreateCMSSignatureRequestType requestType;
+ private byte[] signatureData;
+ private int[] byteRange;
+
+ public CreateCMSSignatureRequestType getRequestType() {
+ return requestType;
+ }
+ public void setRequestType(CreateCMSSignatureRequestType requestType) {
+ this.requestType = requestType;
+ }
+ public byte[] getSignatureData() {
+ return signatureData;
+ }
+ public void setSignatureData(byte[] signatureData) {
+ this.signatureData = signatureData;
+ }
+ public int[] getByteRange() {
+ return byteRange;
+ }
+ public void setByteRange(int[] byteRange) {
+ this.byteRange = byteRange;
+ }
+
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java
index b62dbfc0..992cee46 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java
@@ -39,7 +39,7 @@ public class SLMarschaller {
static {
try {
- JAXBContext context = JAXBContext.newInstance("at.gv.egiz.sl");
+ JAXBContext context = JAXBContext.newInstance("at.gv.egiz.sl.schema");
marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");