Skip to content

Commit

Permalink
revert be69388 (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
iaik-jheher committed Dec 1, 2023
1 parent be69388 commit a71def1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ public InfoboxReadResponseType sendInfoboxReadRequest(
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 {

Expand Down Expand Up @@ -156,6 +160,7 @@ public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack,
throw new SLPdfAsException(errorResponseType.getErrorCode(), errorResponseType.getInfo());
}
throw new PdfAsException("error.pdf.io.03");
} finally { originalExceptionSwallowedByPDFASNPE = null; } } catch (Exception e) { originalExceptionSwallowedByPDFASNPE = e; throw e; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import iaik.x509.X509Certificate;
import lombok.extern.slf4j.Slf4j;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.Locale;
Expand Down Expand Up @@ -116,7 +118,17 @@ Image getPlaceholder() {
SignParameter param = PdfAsFactory.createSignParameter(conf, null, null);
param.setSignatureProfileId(sigProfile);

return pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4);
Image placeholder = pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4);

// WORKAROUND for #5, manually paint a black border
if ((placeholder != null) && !this.signatureProfile.equals(Profile.BASE_LOGO))
{
Graphics2D ctx = (Graphics2D)placeholder.getGraphics();
ctx.setColor(Color.BLACK);
ctx.drawRect(0, 0, placeholder.getWidth(null)-1, placeholder.getHeight(null)-1);
}

return placeholder;
}
} catch (Exception e) {
log.error("Failed to get signature placeholder", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,27 @@ else if (param.getSignatureProfileId().contains(Profile.AMTSSIGNATURBLOCK.name()
return result;
}
} catch (PdfAsException | PDFASError ex) {
Throwable rootCause = ex;
while (rootCause.getCause() != null)
rootCause = rootCause.getCause();
try { /* error code 60xx is user cancellation */
int errorCode = ((SLPdfAsException)rootCause).getCode();
if ((errorCode == 6000) || (errorCode == 6001))
throw new UserCancelledException();
} catch (ClassCastException e2) { /* fall through to wrapped throw */}
// 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 = ((SLPdfAsException)rootCause).getCode();
if ((errorCode == 6000) || (errorCode == 6001))
throw new UserCancelledException();
} catch (ClassCastException e2) { /* fall through to wrapped throw */}
}

throw new SignatureException(ex);
throw new SignatureException(e);
}
}
}

0 comments on commit a71def1

Please sign in to comment.