diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-10-06 11:11:09 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-10-06 11:11:09 +0200 |
commit | 75ce8c3a91d8b80bcc6bc7bd6e083606215f7262 (patch) | |
tree | 43f26870124fc83f817e807963733e5ab1f2f85a /pdf-over-signer/src/main | |
parent | a0f9a3dabdb4cdfbbb2257b9e6277d4c5fee4a34 (diff) | |
download | pdf-over-75ce8c3a91d8b80bcc6bc7bd6e083606215f7262.tar.gz pdf-over-75ce8c3a91d8b80bcc6bc7bd6e083606215f7262.tar.bz2 pdf-over-75ce8c3a91d8b80bcc6bc7bd6e083606215f7262.zip |
re-do the #52 hack to avoid dependency on atruststatus
Diffstat (limited to 'pdf-over-signer/src/main')
-rw-r--r-- | pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java | 15 | ||||
-rw-r--r-- | pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 16 |
2 files changed, 22 insertions, 9 deletions
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java index 7dd2fedc..1396255a 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java @@ -91,8 +91,7 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } catch (SignatureException e) { throw new PDFIOException("error.pdf.io.03", e); } catch (UserCancelledException e) { - // TODO: find out how to communicate this out to PDF-AS? - throw new PDFIOException("error.pdf.io.03", e); + throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen."); } if (element == null) { @@ -108,12 +107,16 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { throw new PdfAsException("error.pdf.io.03"); } + /** hack cf. #52 */ + public static Exception originalExceptionSwallowedByPDFASNPE = null; /* (non-Javadoc) * @see at.gv.egiz.sl.util.ISLConnector#sendCMSRequest(at.gv.egiz.sl.util.RequestPackage, at.gv.egiz.pdfas.lib.api.sign.SignParameter) */ @Override public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack, SignParameter parameter) throws PdfAsException { + /* outermost try blocks are a hack cf. #52 */ +try { try { JAXBElement<?> element = null; try { @@ -145,8 +148,7 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } catch (SignatureException e) { throw new PDFIOException("error.pdf.io.03", e); } catch (UserCancelledException e) { - // TODO: find out how to communicate this out to PDF-AS? - throw new PDFIOException("error.pdf.io.03", e); + throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen."); } if (element == null) { @@ -161,9 +163,10 @@ public class PdfAs4BKUSLConnector extends BaseSLConnector { } else if (element.getValue() instanceof ErrorResponseType) { ErrorResponseType errorResponseType = (ErrorResponseType) element .getValue(); - throw new SLPdfAsException(errorResponseType.getErrorCode(), - errorResponseType.getInfo()); + throw new SLPdfAsException(errorResponseType.getErrorCode(), errorResponseType.getInfo()); } throw new PdfAsException("error.pdf.io.03"); +} finally { originalExceptionSwallowedByPDFASNPE = null; } } catch (Exception e) { originalExceptionSwallowedByPDFASNPE = e; throw e; } } + } diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java index 561452a4..7afa4ec5 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -1,6 +1,7 @@ package at.asit.pdfover.signer.pdfas; import java.io.ByteArrayOutputStream; +import java.util.Objects; import java.util.UUID; import javax.activation.DataSource; @@ -155,13 +156,22 @@ public class PdfAs4Signer { result.setSignedDocument(new ByteArrayDocumentSource(state.output.toByteArray())); return result; } - } catch (PdfAsException | PDFASError e) { - { // TODO hack around pdf-as not handling this error code properly cf. #124 + } catch (PdfAsException | PDFASError ex) { + // workaround for PDF-AS nullpointerexception intercepting the actual exception + // cf. issue #52 + // this is a bit of a hack... + Exception e = ex; + { + if ((e instanceof PDFASError) && (e.getCause() instanceof NullPointerException)) + e = Objects.requireNonNullElse(PdfAs4BKUSLConnector.originalExceptionSwallowedByPDFASNPE, e); + } + + { Throwable rootCause = e; while (rootCause.getCause() != null) rootCause = rootCause.getCause(); try { /* error code 60xx is user cancellation */ - int errorCode = Integer.parseInt(((SLPdfAsException)rootCause).getMessage().split(":",2)[0].trim()); + int errorCode = ((SLPdfAsException)rootCause).getCode(); if ((6000 <= errorCode) && (errorCode <= 6099)) throw new UserCancelledException(); } catch (ClassCastException e2) { /* fall through to wrapped throw */} |