diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-30 17:15:54 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-30 17:15:54 +0100 |
commit | fb3344c1e4d4ac8e8a6aa5605d052cee8cd4c3b1 (patch) | |
tree | 01e04f2f9e9286c02bbc55699d027150180bbe01 | |
parent | e123b037e65b336c677c0a66125ae85f5827417a (diff) | |
download | pdf-as-4-fb3344c1e4d4ac8e8a6aa5605d052cee8cd4c3b1.tar.gz pdf-as-4-fb3344c1e4d4ac8e8a6aa5605d052cee8cd4c3b1.tar.bz2 pdf-as-4-fb3344c1e4d4ac8e8a6aa5605d052cee8cd4c3b1.zip |
Introduced Process Information Map in PDFASError and SignResult
19 files changed, 237 insertions, 68 deletions
diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index d847f31b..a513ccf7 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -28,6 +28,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; import java.util.UUID; import javax.activation.DataSource; @@ -39,6 +40,8 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.utils.StreamUtils; @@ -111,6 +114,8 @@ public class Main { public static final String STANDARD_POSITION_STRING = "x:auto;y:auto;w:auto;p:auto;f:0"; + private static final Logger logger = LoggerFactory.getLogger(Main.class); + private static Options createOptions() { Options cliOptions = new Options(); @@ -418,6 +423,13 @@ public class Main { @SuppressWarnings("unused") SignResult result = pdfAs.sign(signParameter); + Iterator<Entry<String, String>> infoIt = result.getProcessInformations().entrySet().iterator(); + + while(infoIt.hasNext()) { + Entry<String, String> infoEntry = infoIt.next(); + logger.debug("Process Information: {} = {}", infoEntry.getKey(), infoEntry.getValue()); + } + fos.close(); System.out.println("Signed document " + outputFile); } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java index 14e1027e..8ab02028 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/ErrorConstants.java @@ -1,6 +1,9 @@ package at.gv.egiz.pdfas.common.exceptions; public interface ErrorConstants { + public static final String STATUS_INFO_SIGDEVICE = "SigDevice"; + public static final String STATUS_INFO_SIGDEVICEVERSION = "SigDeviceVersion"; + // Code below 10000 are reserved for SL Error Codes public static final long ERROR_GENERIC = 10000; diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFASError.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFASError.java index bcd3375b..a4cb0649 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFASError.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFASError.java @@ -1,5 +1,8 @@ package at.gv.egiz.pdfas.common.exceptions; +import java.util.HashMap; +import java.util.Map; + import at.gv.egiz.pdfas.common.messages.ErrorCodeResolver; /** @@ -9,48 +12,58 @@ public class PDFASError extends Exception implements ErrorConstants { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1233586898708485346L; - + /** The code. */ private long code; - + + private Map<String, String> metaInformations = new HashMap<String, String>(); + /** * Instantiates a new PDFAS error. * - * @param code the code + * @param code + * the code */ public PDFASError(long code) { super(ErrorCodeResolver.resolveMessage(code)); this.code = code; } - + /** * Instantiates a new PDFAS error. * - * @param code the code - * @param e the e + * @param code + * the code + * @param e + * the e */ public PDFASError(long code, Throwable e) { super(ErrorCodeResolver.resolveMessage(code), e); this.code = code; } - + /** * Instantiates a new PDFAS error. * - * @param code the code - * @param info the info - * @param e the e + * @param code + * the code + * @param info + * the info + * @param e + * the e */ public PDFASError(long code, String info, Throwable e) { super(info, e); this.code = code; } - + /** * Instantiates a new PDFAS error. * - * @param code the code - * @param info the info + * @param code + * the code + * @param info + * the info */ public PDFASError(long code, String info) { super(info); @@ -65,7 +78,7 @@ public class PDFASError extends Exception implements ErrorConstants { public long getCode() { return code; } - + /** * Gets the info. * @@ -74,7 +87,7 @@ public class PDFASError extends Exception implements ErrorConstants { public String getInfo() { return this.getMessage(); } - + /** * Gets the code info. * @@ -83,8 +96,18 @@ public class PDFASError extends Exception implements ErrorConstants { public String getCodeInfo() { return ErrorCodeResolver.resolveMessage(code); } - - public static String buildInfoString(long code, Object ... args) { + + /** + * Gets the meta informations for the Error. This Map + * is never null, but no information + * + * @return the meta informations + */ + public Map<String, String> getProcessInformations() { + return metaInformations; + } + + public static String buildInfoString(long code, Object... args) { return String.format(ErrorCodeResolver.resolveMessage(code), args); } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java index 8084f8f1..d2dc896e 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java @@ -24,6 +24,7 @@ package at.gv.egiz.pdfas.lib.api.sign; import java.security.cert.X509Certificate; +import java.util.Map; import at.gv.egiz.pdfas.lib.api.SignaturePosition; @@ -52,4 +53,6 @@ public interface SignResult { * return null if no position information is available. */ public SignaturePosition getSignaturePosition(); + + public Map<String, String> getProcessInformations(); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java index 6708fc5b..9b2a8d79 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/ErrorExtractor.java @@ -7,6 +7,7 @@ import at.gv.egiz.pdfas.common.exceptions.ErrorConstants; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsMOAException; import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException; +import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; public class ErrorExtractor implements ErrorConstants { @@ -48,7 +49,7 @@ public class ErrorExtractor implements ErrorConstants { return null; } - public static PDFASError searchPdfAsError(Throwable e) { + public static PDFASError searchPdfAsError(Throwable e, OperationStatus status) { Throwable cur = e; PDFASError err = null; @@ -68,6 +69,11 @@ public class ErrorExtractor implements ErrorConstants { } if(err != null) { + + if(status != null) { + err.getProcessInformations().putAll(status.getMetaInformations()); + } + return err; } @@ -89,11 +95,22 @@ public class ErrorExtractor implements ErrorConstants { } if (err != null) { + + if(status != null) { + err.getProcessInformations().putAll(status.getMetaInformations()); + } + return err; } logger.info("Cannot extract correct failure code from: ", e); - return new PDFASError(ERROR_GENERIC, e); + err = new PDFASError(ERROR_GENERIC, e); + + if(status != null) { + err.getProcessInformations().putAll(status.getMetaInformations()); + } + + return err; } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index 4828bae3..aa524cc9 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -190,7 +190,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, } catch (Throwable e) { logger.error("Failed to create signature [" + e.getMessage() + "]", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } finally { if (status != null) { status.clear(); @@ -217,7 +217,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, try { return backend.getVerifier().verify(parameter); } catch (Throwable e) { - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, null); } } @@ -230,7 +230,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, verifySignParameter(parameter); StatusRequestImpl request = new StatusRequestImpl(); - + OperationStatus status = null; try { // Status initialization if (!(parameter.getConfiguration() instanceof ISettings)) { @@ -248,7 +248,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, } ISettings settings = (ISettings) parameter.getConfiguration(); - OperationStatus status = new OperationStatus(settings, parameter, + status = new OperationStatus(settings, parameter, backend); IPdfSigner signer = backend.getPdfSigner(); @@ -267,7 +267,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, return request; } catch (Throwable e) { logger.error("startSign", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } } @@ -329,7 +329,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, } catch (Throwable e) { logger.error("process", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } } else if (request.needSignature()) { request.setNeedSignature(false); @@ -379,7 +379,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, return createSignResult(status); } catch (IOException e) { // new PdfAsException("error.pdf.sig.06", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } finally { if (status != null) { status.clear(); @@ -456,7 +456,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, .getCertificate()); result.setSignaturePosition(status.getRequestedSignature() .getSignaturePosition()); - + result.getProcessInformations().putAll(status.getMetaInformations()); return result; } @@ -499,10 +499,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants, resolution, status, requestedSignature); } catch (PdfAsException e) { logger.error("PDF-AS Exception", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } catch (Throwable e) { logger.error("Throwable Exception", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java index f713eb6a..44992c2b 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java @@ -24,6 +24,8 @@ package at.gv.egiz.pdfas.lib.impl; import java.security.cert.X509Certificate; +import java.util.HashMap; +import java.util.Map; import at.gv.egiz.pdfas.lib.api.SignaturePosition; import at.gv.egiz.pdfas.lib.api.sign.SignResult; @@ -32,6 +34,7 @@ public class SignResultImpl implements SignResult { protected X509Certificate certificate; protected SignaturePosition position; + protected Map<String, String> processInfo = new HashMap<String, String>(); public SignResultImpl() { } @@ -52,4 +55,9 @@ public class SignResultImpl implements SignResult { this.position = position; } + @Override + public Map<String, String> getProcessInformations() { + return processInfo; + } + } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java index 7b2ce69c..ecdddfa1 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -54,6 +54,7 @@ public class OperationStatus implements Serializable { private RequestedSignature requestedSignature; private Calendar signingDate; private PDFASBackend backend; + private Map<String, String> metaInformations = new HashMap<String, String>(); public OperationStatus(ISettings configuration, SignParameter signParameter, PDFASBackend backend) { this.configuration = configuration; @@ -169,4 +170,8 @@ public class OperationStatus implements Serializable { } return null; } + + public Map<String, String> getMetaInformations() { + return metaInformations; + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java index c9cab906..8226d7e9 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java @@ -92,7 +92,8 @@ public class RequestedSignature implements ICertificateProvider { public void setSignaturePosition(SignaturePosition signaturePosition) { this.signaturePosition = signaturePosition; } - - - + + public OperationStatus getStatus() { + return status; + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/util/SignatureUtils.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/util/SignatureUtils.java index cdc7f11e..14dbdd16 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/util/SignatureUtils.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/util/SignatureUtils.java @@ -46,14 +46,14 @@ public class SignatureUtils implements ErrorConstants { VerifyResultImpl verifyResult = new VerifyResultImpl(); //results.add(verifyResult); try { - logger.info("Signature Algo: {}, Digest {}", signedData + logger.debug("Signature Algo: {}, Digest {}", signedData .getSignerInfos()[0].getSignatureAlgorithm(), signedData.getSignerInfos()[0].getDigestAlgorithm()); // verify the signature for SignerInfo at index i X509Certificate signer_cert = signedData.verify(0); // if the signature is OK the certificate of the // signer is returned - logger.info("Signature OK from signer: " + logger.debug("Signature OK from signer: " + signer_cert.getSubjectDN()); verifyResult.setSignerCertificate(signer_cert); 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; + } } diff --git a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java index 4035daac..c3e417d2 100644 --- a/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java +++ b/pdf-as-moa/src/main/java/at/gv/egiz/pdfas/moa/MOAConnector.java @@ -49,6 +49,7 @@ import at.gv.e_government.reference.namespace.moa._20020822.MetaInfoType; import at.gv.e_government.reference.namespace.moa._20020822_.MOAFault; import at.gv.e_government.reference.namespace.moa._20020822_.SignatureCreationPortType; import at.gv.e_government.reference.namespace.moa._20020822_.SignatureCreationService; +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; @@ -71,6 +72,8 @@ public class MOAConnector implements ISignatureConnector, private static final Logger logger = LoggerFactory .getLogger(MOAConnector.class); + public static final String SIGNATURE_DEVICE = "MOA"; + private X509Certificate certificate; private String moaEndpoint; private String keyIdentifier; @@ -195,6 +198,12 @@ public class MOAConnector implements ISignatureConnector, sigInfo.setDataObjectInfo(dataObjectInfo); request.getSingleSignatureInfo().add(sigInfo); + requestedSignature.getStatus().getMetaInformations() + .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE); + // TODO: Find a way to get MOA-SPSS Version + requestedSignature.getStatus().getMetaInformations() + .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION, "UNKNOWN"); + CreateCMSSignatureResponseType response; try { response = creationPort.createCMSSignature(request); diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index 655a144e..0aa6d9a3 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -622,10 +622,10 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { return cutOut; } catch (PdfAsException e) { logger.error("PDF-AS Exception", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } catch (Throwable e) { logger.error("Throwable Exception", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, status); } } } diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/pdfbox/PDFBOXVerifier.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/pdfbox/PDFBOXVerifier.java index 037dd5d8..85ff2d87 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/pdfbox/PDFBOXVerifier.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/pdfbox/PDFBOXVerifier.java @@ -154,10 +154,10 @@ public class PDFBOXVerifier implements VerifyBackend { return result; } catch (IOException e) { logger.error("Failed to verify document", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, null); } catch (PdfAsException e) { logger.error("Failed to verify document", e); - throw ErrorExtractor.searchPdfAsError(e); + throw ErrorExtractor.searchPdfAsError(e, null); } finally { if (doc != null) { try { diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index caf6a967..7b49c644 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -620,7 +620,7 @@ public class PdfAsHelper { || connector.equals("mobilebku")) { BKUSLConnector bkuSLConnector = (BKUSLConnector) session .getAttribute(PDF_SL_CONNECTOR); - + if (statusRequest.needCertificate()) { logger.debug("Needing Certificate from BKU"); // build SL Request to read certificate diff --git a/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSignerKeystore.java b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSignerKeystore.java index f49e54a0..d50a2c95 100644 --- a/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSignerKeystore.java +++ b/signature-standards/sigs-pades/src/main/java/at/gv/egiz/pdfas/sigs/pades/PAdESSignerKeystore.java @@ -58,9 +58,11 @@ import java.util.List; 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.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; +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.lib.impl.status.RequestedSignature; @@ -72,6 +74,8 @@ public class PAdESSignerKeystore implements IPlainSigner, PAdESConstants { .getLogger(PAdESSignerKeystore.class); private static final String fallBackProvider = "SunJSSE"; + + public static final String SIGNATURE_DEVICE = "JKS"; PrivateKey privKey; X509Certificate cert; @@ -277,6 +281,12 @@ public class PAdESSignerKeystore implements IPlainSigner, PAdESConstants { RequestedSignature requestedSignature) throws PdfAsException { try { logger.info("Creating PAdES signature."); + + requestedSignature.getStatus().getMetaInformations() + .put(ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE); + requestedSignature.getStatus().getMetaInformations() + .put(ErrorConstants.STATUS_INFO_SIGDEVICEVERSION, PdfAsFactory.getVersion()); + IssuerAndSerialNumber issuer = new IssuerAndSerialNumber(cert); AlgorithmID[] algorithms = CertificateUtils.getAlgorithmIDs(cert); |