From bb7c5a1c9a6610303bef4bca4584747dbdda5c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Tue, 20 Aug 2024 18:14:18 +0200 Subject: [PATCH] fix: check if creating signature field is possible --- .../slovensko/autogram/util/PDFUtils.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java index ff0f0365..73ac97c3 100644 --- a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java @@ -9,15 +9,23 @@ public class PDFUtils { public static boolean isPdfAndPasswordProtected(DSSDocument document) { - if (document.getMimeType().equals(MimeTypeEnum.PDF)) { - try { - PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document); + if (!document.getMimeType().equals(MimeTypeEnum.PDF)) + return false; + + try { + PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document); + + // document is protected against modification without password + if (!reader.canCreateSignatureField()) { reader.close(); - } catch (InvalidPasswordException e) { return true; - } catch (IOException e) { } - } + + reader.close(); + } catch (InvalidPasswordException e) { + return true; + } catch (IOException e) {} + return false; }