From ff84ad3cd52b7697ac4368dc7c17368c736270c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 19 Aug 2024 19:13:40 +0200 Subject: [PATCH 01/50] feat: initial implementation of signing protected pdfs --- .../slovensko/autogram/core/Autogram.java | 10 +---- .../autogram/core/SignatureValidator.java | 5 +-- .../slovensko/autogram/core/SigningJob.java | 25 +++++++---- .../autogram/core/SigningParameters.java | 9 ++-- .../autogram/core/eforms/xdc/XDCBuilder.java | 8 ++-- .../DocumentVisualizationBuilder.java | 5 ++- .../core/visualization/PDFVisualization.java | 7 +-- .../autogram/model/ProtectedDSSDocument.java | 8 ++++ .../autogram/model/ProtectedFileDocument.java | 27 ++++++++++++ .../model/ProtectedInMemoryDocument.java | 44 +++++++++++++++++++ .../server/dto/ServerSigningParameters.java | 6 ++- .../autogram/server/dto/SignRequestBody.java | 6 +-- .../digital/slovensko/autogram/ui/UI.java | 2 + .../slovensko/autogram/ui/cli/CliUI.java | 5 +++ .../slovensko/autogram/ui/gui/GUI.java | 28 ++++++++++++ .../autogram/ui/gui/MainMenuController.java | 13 ++++-- .../autogram/util/AsicContainerUtils.java | 5 ++- .../slovensko/autogram/util/DSSUtils.java | 13 ++++-- .../slovensko/autogram/AutogramTests.java | 14 ++++-- 19 files changed, 187 insertions(+), 53 deletions(-) create mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java create mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java create mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 37ca78fa..53e99e33 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -7,7 +7,6 @@ import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; -import digital.slovensko.autogram.util.PDFUtils; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.pdfa.PDFAStructureValidator; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; @@ -19,7 +18,7 @@ import java.util.function.Consumer; public class Autogram { - private final UI ui; + public final UI ui; private final UserSettings settings; /** Current batch, should be null if no batch was started yet */ private Batch batch = null; @@ -65,13 +64,6 @@ public void checkPDFACompliance(SigningJob job) { public void startVisualization(SigningJob job) { ui.onWorkThreadDo(() -> { - if (PDFUtils.isPdfAndPasswordProtected(job.getDocument())) { - ui.onUIThreadDo(() -> { - ui.showError(new AutogramException("Nastala chyba", "Dokument je chránený heslom", "Snažíte sa podpísať dokument chránený heslom, čo je funkcionalita, ktorá nie je podporovaná.\n\nOdstráňte ochranu heslom a potom budete môcť dokument podpísať.")); - }); - return; - } - try { var visualization = DocumentVisualizationBuilder.fromJob(job, settings); ui.onUIThreadDo(() -> ui.showVisualization(visualization, this)); diff --git a/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java b/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java index 2747b6b6..de5f14c1 100644 --- a/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java +++ b/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java @@ -15,7 +15,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import eu.europa.esig.dss.enumerations.ASiCContainerType; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import eu.europa.esig.dss.simplereport.SimpleReport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +24,6 @@ import digital.slovensko.autogram.util.XMLUtils; import eu.europa.esig.dss.enumerations.SignatureLevel; -import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.service.crl.OnlineCRLSource; import eu.europa.esig.dss.service.http.commons.CommonsDataLoader; @@ -167,7 +166,7 @@ public static ValidationReports getSignatureCheckReport(SigningJob job) { return new ValidationReports(validator.validateDocument(), job); } - public static SimpleReport getSignedDocumentSimpleReport(DSSDocument document) { + public static SimpleReport getSignedDocumentSimpleReport(ProtectedDSSDocument document) { var validator = createDocumentValidator(document); if (validator == null) return null; diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 411d92fb..e3e4e26c 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -6,6 +6,8 @@ import digital.slovensko.autogram.core.eforms.xdc.XDCBuilder; import digital.slovensko.autogram.core.eforms.xdc.XDCValidator; import digital.slovensko.autogram.core.errors.AutogramException; +import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.ProtectedFileDocument; import digital.slovensko.autogram.util.Logging; import eu.europa.esig.dss.asic.cades.signature.ASiCWithCAdESService; import eu.europa.esig.dss.asic.xades.signature.ASiCWithXAdESService; @@ -24,16 +26,16 @@ public class SigningJob { private final Responder responder; - private final DSSDocument document; + private final ProtectedDSSDocument document; private final SigningParameters parameters; - private SigningJob(DSSDocument document, SigningParameters parameters, Responder responder) { + private SigningJob(ProtectedDSSDocument document, SigningParameters parameters, Responder responder) { this.document = document; this.parameters = parameters; this.responder = responder; } - public DSSDocument getDocument() { + public ProtectedDSSDocument getDocument() { return this.document; } @@ -46,7 +48,6 @@ public int getVisualizationWidth() { } public void signWithKeyAndRespond(SigningKey key) throws InterruptedException, AutogramException { - Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getName()); boolean isContainer = getParameters().getContainer() != null; var doc = switch (getParameters().getSignatureType()) { @@ -153,8 +154,8 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { return service.signDocument(getDocument(), signatureParameters, signatureValue); } - public static FileDocument createDSSFileDocumentFromFile(File file) { - var fileDocument = new FileDocument(file); + public static ProtectedFileDocument createDSSFileDocumentFromFile(File file) { + var fileDocument = new ProtectedFileDocument(file); if (fileDocument.getName().endsWith(".xdcf")) fileDocument.setMimeType(XML_DATACONTAINER_WITH_CHARSET); @@ -168,7 +169,7 @@ else if (isTxt(fileDocument.getMimeType())) return fileDocument; } - private static SigningJob build(DSSDocument document, SigningParameters params, Responder responder) { + private static SigningJob build(ProtectedDSSDocument document, SigningParameters params, Responder responder) { if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) document = XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document)); @@ -183,17 +184,23 @@ private static SigningJob build(DSSDocument document, SigningParameters params, return new SigningJob(document, params, responder); } - public static SigningJob buildFromRequest(DSSDocument document, SigningParameters params, Responder responder) { + public static SigningJob buildFromRequest(ProtectedDSSDocument document, SigningParameters params, Responder responder) { return build(document, params, responder); } public static SigningJob buildFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + return buildFromFile(file, "".toCharArray(), responder, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); + } + + public static SigningJob buildFromFile(File file, char[] password, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var document = createDSSFileDocumentFromFile(file); + document.setPassword(password); + var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); return build(document, parameters, responder); } - private static SigningParameters getParametersForFile(FileDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + private static SigningParameters getParametersForFile(ProtectedFileDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: diff --git a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java index c5f3f634..406f70f4 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java @@ -6,6 +6,7 @@ import digital.slovensko.autogram.core.errors.AutogramException; import digital.slovensko.autogram.core.errors.SigningParametersException; import digital.slovensko.autogram.core.errors.UnknownEformException; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import digital.slovensko.autogram.util.AsicContainerUtils; import digital.slovensko.autogram.core.eforms.EFormUtils; import digital.slovensko.autogram.core.eforms.xdc.XDCValidator; @@ -60,7 +61,7 @@ public static SigningParameters buildParameters( SignatureLevel level, DigestAlgorithm digestAlgorithm, ASiCContainerType container, SignaturePackaging packaging, boolean en319132, String infoCanonicalization, String propertiesCanonicalization, String keyInfoCanonicalization, EFormAttributes eFormAttributes, boolean autoLoadEform, String fsFormId, boolean checkPDFACompliance, - int preferredPreviewWidth, DSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + int preferredPreviewWidth, ProtectedDSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { if (level == null) throw new SigningParametersException("Nebol zadaný typ podpisu", "Typ/level podpisu je povinný atribút"); @@ -107,21 +108,21 @@ public static SigningParameters buildParameters( keyInfoCanonicalization, eFormAttributes, checkPDFACompliance, preferredPreviewWidth, tspSource); } - public static SigningParameters buildForPDF(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource) throws AutogramException { + public static SigningParameters buildForPDF(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.PAdES_BASELINE_B : SignatureLevel.PAdES_BASELINE_T, DigestAlgorithm.SHA256, null, null, signAsEn319132, null, null, null, null, false, null, checkPDFACompliance, 640, document, tspSource, true); } - public static SigningParameters buildForASiCWithXAdES(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + public static SigningParameters buildForASiCWithXAdES(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.XAdES_BASELINE_B : SignatureLevel.XAdES_BASELINE_T, DigestAlgorithm.SHA256, ASiCContainerType.ASiC_E, SignaturePackaging.ENVELOPING, signAsEn319132, null, null, null, null, true, EFormUtils.getFsFormIdFromFilename(document.getName()), checkPDFACompliance, 640, document, tspSource, plainXmlEnabled); } - public static SigningParameters buildForASiCWithCAdES(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + public static SigningParameters buildForASiCWithCAdES(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.CAdES_BASELINE_B : SignatureLevel.CAdES_BASELINE_T, DigestAlgorithm.SHA256, ASiCContainerType.ASiC_E, SignaturePackaging.ENVELOPING, signAsEn319132, null, null, null, null, true, diff --git a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java index b061a9a6..00e49765 100644 --- a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java @@ -4,6 +4,8 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.XsltParams; import digital.slovensko.autogram.core.errors.TransformationException; +import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.util.XMLUtils; import static digital.slovensko.autogram.core.eforms.EFormUtils.*; @@ -11,8 +13,6 @@ import static digital.slovensko.autogram.util.XMLUtils.getSecureDocumentBuilder; import eu.europa.esig.dss.enumerations.DigestAlgorithm; -import eu.europa.esig.dss.model.DSSDocument; -import eu.europa.esig.dss.model.InMemoryDocument; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -32,7 +32,7 @@ public abstract class XDCBuilder { private static final Charset ENCODING = StandardCharsets.UTF_8; - public static DSSDocument transform(SigningParameters params, String filename, Document document) { + public static ProtectedDSSDocument transform(SigningParameters params, String filename, Document document) { var identifier = params.getIdentifier(); var lastSlashIndex = identifier.lastIndexOf("/"); if (lastSlashIndex == -1) @@ -58,7 +58,7 @@ public static DSSDocument transform(SigningParameters params, String filename, D var content = getDocumentContent(transformedDocument).getBytes(ENCODING); - return new InMemoryDocument(content, getXdcfFilename(filename), AutogramMimeType.XML_DATACONTAINER_WITH_CHARSET); + return new ProtectedInMemoryDocument(content, getXdcfFilename(filename), AutogramMimeType.XML_DATACONTAINER_WITH_CHARSET); } catch (Exception e) { throw new TransformationException("Nastala chyba počas transformácie dokumentu", diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index f824958c..e9493820 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -6,6 +6,7 @@ import javax.xml.parsers.ParserConfigurationException; import digital.slovensko.autogram.core.UserSettings; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import eu.europa.esig.dss.model.DSSDocument; import org.xml.sax.SAXException; @@ -22,10 +23,10 @@ public class DocumentVisualizationBuilder { - private final DSSDocument document; + private final ProtectedDSSDocument document; private final SigningParameters parameters; - private DocumentVisualizationBuilder(DSSDocument document, SigningParameters parameters) { + private DocumentVisualizationBuilder(ProtectedDSSDocument document, SigningParameters parameters) { this.document = document; this.parameters = parameters; } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java index fde1d9ce..f0d1c86d 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java @@ -6,6 +6,7 @@ import digital.slovensko.autogram.core.SigningJob; import digital.slovensko.autogram.core.UserSettings; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import digital.slovensko.autogram.ui.Visualizer; import eu.europa.esig.dss.model.DSSDocument; import org.apache.pdfbox.pdmodel.PDDocument; @@ -15,18 +16,18 @@ import javax.imageio.ImageIO; public class PDFVisualization extends Visualization { - private final DSSDocument document; + private final ProtectedDSSDocument document; private final UserSettings settings; - public PDFVisualization(DSSDocument document, SigningJob job, UserSettings settings) { + public PDFVisualization(ProtectedDSSDocument document, SigningJob job, UserSettings settings) { super(job); this.document = document; this.settings = settings; } private ArrayList getPdfImages() throws IOException { - var pdfDocument = PDDocument.load(this.document.openStream()); + var pdfDocument = PDDocument.load(this.document.openStream(), new String(this.document.getPassword())); var pdfRenderer = new PDFRenderer(pdfDocument); var divs = new ArrayList(); for (int page = 0; page < pdfDocument.getNumberOfPages(); ++page) { diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java new file mode 100644 index 00000000..aaa9bc57 --- /dev/null +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java @@ -0,0 +1,8 @@ +package digital.slovensko.autogram.model; + +import eu.europa.esig.dss.model.DSSDocument; + +public interface ProtectedDSSDocument extends DSSDocument { + char[] getPassword(); + void setPassword(char[] password); +} diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java new file mode 100644 index 00000000..797a3e4d --- /dev/null +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java @@ -0,0 +1,27 @@ +package digital.slovensko.autogram.model; + +import eu.europa.esig.dss.model.FileDocument; + +import java.io.File; + +public class ProtectedFileDocument extends FileDocument implements ProtectedDSSDocument { + private char[] password; + + public ProtectedFileDocument(String path) { + super(path); + } + + public ProtectedFileDocument(File file) { + super(file); + } + + @Override + public char[] getPassword() { + return this.password; + } + + @Override + public void setPassword(char[] password) { + this.password = password; + } +} diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java new file mode 100644 index 00000000..ff487880 --- /dev/null +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java @@ -0,0 +1,44 @@ +package digital.slovensko.autogram.model; + +import eu.europa.esig.dss.enumerations.MimeType; +import eu.europa.esig.dss.model.InMemoryDocument; + +import java.io.InputStream; + +public class ProtectedInMemoryDocument extends InMemoryDocument implements ProtectedDSSDocument { + private char[] password; + + public ProtectedInMemoryDocument(byte[] bytes) { + super(bytes); + } + + public ProtectedInMemoryDocument(byte[] bytes, String name) { + super(bytes, name); + } + + public ProtectedInMemoryDocument(byte[] bytes, String name, MimeType mimeType) { + super(bytes, name, mimeType); + } + + public ProtectedInMemoryDocument(InputStream inputStream) { + super(inputStream); + } + + public ProtectedInMemoryDocument(InputStream inputStream, String name) { + super(inputStream, name); + } + + public ProtectedInMemoryDocument(InputStream inputStream, String name, MimeType mimeType) { + super(inputStream, name, mimeType); + } + + @Override + public char[] getPassword() { + return this.password; + } + + @Override + public void setPassword(char[] password) { + this.password = password; + } +} diff --git a/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java b/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java index baaceae9..4f0fba40 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java @@ -15,6 +15,8 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.eforms.dto.XsltParams; +import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.server.errors.MalformedBodyException; import digital.slovensko.autogram.server.errors.RequestValidationException; import digital.slovensko.autogram.server.errors.UnsupportedSignatureLevelException; @@ -133,7 +135,7 @@ public ServerSigningParameters() { this.fsFormId = null; } - public SigningParameters getSigningParameters(boolean isBase64, DSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) { + public SigningParameters getSigningParameters(boolean isBase64, ProtectedDSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) { var xsltParams = new XsltParams( transformationIdentifier, transformationLanguage, @@ -251,7 +253,7 @@ private ASiCContainerType getContainer() { return container; } - public void resolveSigningLevel(InMemoryDocument document) throws RequestValidationException { + public void resolveSigningLevel(ProtectedInMemoryDocument document) throws RequestValidationException { if (level != null) return; diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index 6e5fe870..f64550fe 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -5,10 +5,10 @@ import digital.slovensko.autogram.core.errors.TransformationParsingErrorException; import digital.slovensko.autogram.core.SigningParameters; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.server.errors.MalformedBodyException; import digital.slovensko.autogram.server.errors.RequestValidationException; import eu.europa.esig.dss.enumerations.MimeType; -import eu.europa.esig.dss.model.InMemoryDocument; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; import static digital.slovensko.autogram.core.AutogramMimeType.*; @@ -52,11 +52,11 @@ private void resolveSigningLevel() throws RequestValidationException { parameters.resolveSigningLevel(getDocument()); } - public InMemoryDocument getDocument() { + public ProtectedInMemoryDocument getDocument() { var content = decodeDocumentContent(document.getContent(), isBase64()); var filename = document.getFilename(); - return new InMemoryDocument(content, filename, getMimetype()); + return new ProtectedInMemoryDocument(content, filename, getMimetype()); } public void validateSigningParameters() throws RequestValidationException, MalformedBodyException, diff --git a/src/main/java/digital/slovensko/autogram/ui/UI.java b/src/main/java/digital/slovensko/autogram/ui/UI.java index 0f29eebe..5e6c8654 100644 --- a/src/main/java/digital/slovensko/autogram/ui/UI.java +++ b/src/main/java/digital/slovensko/autogram/ui/UI.java @@ -55,6 +55,8 @@ public interface UI { void showError(AutogramException exception); + char[] getDocumentPassword(); + char[] getKeystorePassword(); char[] getContextSpecificPassword(); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 1bc721e1..9c79d13a 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -267,6 +267,11 @@ public void showError(AutogramException e) { System.err.println(parseError(e)); } + @Override + public char[] getDocumentPassword() { + return new char[0]; + } + @Override public char[] getKeystorePassword() { return System.console().readPassword("Enter keystore password (hidden): "); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index 79f00e41..24a75817 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -199,6 +199,34 @@ public void showPkcsEidWindowsDllError(AutogramException e) { stage.show(); } + public char[] getDocumentPassword() { + var futurePassword = new FutureTask<>(() -> { + var controller = new PasswordController("Aké je heslo k dokumentu?", "Zadajte kód k dokumentu.", false, false); + var root = GUIUtils.loadFXML(controller, "password-dialog.fxml"); + + var stage = new Stage(); + stage.setTitle("Odomknutie dokumentu"); + stage.setScene(new Scene(root)); + stage.setOnCloseRequest(e -> { + refreshKeyOnAllJobs(); + enableSigningOnAllJobs(); + }); + stage.setResizable(false); + stage.initModality(Modality.APPLICATION_MODAL); + stage.showAndWait(); + + return controller.getPassword(); + }); + + Platform.runLater(futurePassword); + + try { + return futurePassword.get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + public char[] getKeystorePassword() { var futurePassword = new FutureTask<>(() -> { var controller = new PasswordController("Aký je kód k úložisku klúčov?", "Zadajte kód k úložisku klúčov.", false, true); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index 8801ca03..604f0f0d 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -110,10 +110,15 @@ private void signFiles(List list) { var filesList = getFilesList(list); if (filesList.size() == 1) { var file = filesList.get(0); - var job = SigningJob.buildFromFile(file, - new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), - userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); - autogram.sign(job); + + autogram.ui.onUIThreadDo(() -> autogram.ui.onWorkThreadDo(() -> { + char[] password = autogram.ui.getDocumentPassword(); + + var job = SigningJob.buildFromFile(file, password, + new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), + userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); + autogram.sign(job); + })); } else { autogram.batchStart(filesList.size(), new BatchGuiFileResponder(autogram, filesList, filesList.get(0).toPath().getParent().resolve("signed"), userSettings.isPdfaCompliance(), diff --git a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java index 298f3f31..15ad519b 100644 --- a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java @@ -3,6 +3,7 @@ import digital.slovensko.autogram.core.AutogramMimeType; import digital.slovensko.autogram.core.errors.MultipleOriginalDocumentsFoundException; import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import eu.europa.esig.dss.asic.xades.ASiCWithXAdESContainerExtractor; import eu.europa.esig.dss.enumerations.MimeType; import eu.europa.esig.dss.enumerations.MimeTypeEnum; @@ -15,7 +16,7 @@ import static digital.slovensko.autogram.core.AutogramMimeType.isXML; public class AsicContainerUtils { - public static DSSDocument getOriginalDocument(DSSDocument asice) throws OriginalDocumentNotFoundException, + public static ProtectedDSSDocument getOriginalDocument(ProtectedDSSDocument asice) throws OriginalDocumentNotFoundException, MultipleOriginalDocumentsFoundException { SignedDocumentValidator documentValidator; try { @@ -41,7 +42,7 @@ public static DSSDocument getOriginalDocument(DSSDocument asice) throws Original if (aSiCContent.getSignedDocuments().size() > 1) throw new MultipleOriginalDocumentsFoundException("V kontajneri bolo nájdených viacero dokumentov na podpis"); - var originalDocument = aSiCContent.getSignedDocuments().get(0); + var originalDocument = (ProtectedDSSDocument) aSiCContent.getSignedDocuments().get(0); if (isXML(originalDocument.getMimeType()) || MimeTypeEnum.BINARY.equals(originalDocument.getMimeType())) setMimeTypeFromManifest(asice, originalDocument); diff --git a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java index 34e042c1..9ed2d8c6 100644 --- a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java @@ -1,9 +1,10 @@ package digital.slovensko.autogram.util; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import eu.europa.esig.dss.asic.cades.validation.ASiCContainerWithCAdESValidatorFactory; import eu.europa.esig.dss.asic.xades.validation.ASiCContainerWithXAdESValidatorFactory; import eu.europa.esig.dss.cades.validation.CMSDocumentValidatorFactory; -import eu.europa.esig.dss.model.DSSDocument; +import eu.europa.esig.dss.pades.validation.PDFDocumentValidator; import eu.europa.esig.dss.pades.validation.PDFDocumentValidatorFactory; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import eu.europa.esig.dss.validation.SignedDocumentValidator; @@ -37,9 +38,13 @@ public static String buildTooltipLabel(DSSPrivateKeyEntry key) { return out; } - public static SignedDocumentValidator createDocumentValidator(DSSDocument document) { - if (new PDFDocumentValidatorFactory().isSupported(document)) - return new PDFDocumentValidatorFactory().create(document); + public static SignedDocumentValidator createDocumentValidator(ProtectedDSSDocument document) { + System.out.println(document.getPassword()); + if (new PDFDocumentValidatorFactory().isSupported(document)) { + var d = new PDFDocumentValidator(document); + d.setPasswordProtection(document.getPassword()); + return d; + } if (new XMLDocumentValidatorFactory().isSupported(document)) return new XMLDocumentValidatorFactory().create(document); diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index 11587f3b..c11b81aa 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -5,6 +5,7 @@ import digital.slovensko.autogram.core.errors.UnknownEformException; import digital.slovensko.autogram.core.visualization.Visualization; import digital.slovensko.autogram.drivers.TokenDriver; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.ui.gui.IgnorableException; @@ -42,7 +43,7 @@ class AutogramTests { "digital.slovensko.autogram.TestMethodSources#validOtherDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#validXadesDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#fsDPFOProvider" }) - void testSignAsiceXadesHappyScenario(InMemoryDocument document) { + void testSignAsiceXadesHappyScenario(ProtectedInMemoryDocument document) { var settings = new TestSettings(); var newUI = new FakeUI(); var autogram = new Autogram(newUI, settings); @@ -58,7 +59,7 @@ void testSignAsiceXadesHappyScenario(InMemoryDocument document) { @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#nonEformXmlProvider"}) - void testSignNonEformHappyScenario(InMemoryDocument document) { + void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) { var settings = new TestSettings(); var newUI = new FakeUI(); var autogram = new Autogram(newUI, settings); @@ -81,7 +82,7 @@ void testSignNonEformNegativeScenario(InMemoryDocument document) { @ParameterizedTest @MethodSource({"digital.slovensko.autogram.TestMethodSources#validOtherDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#validCadesDocumentsProvider"}) - void testSignAsiceCadesHappyScenario(InMemoryDocument document) { + void testSignAsiceCadesHappyScenario(ProtectedInMemoryDocument document) { var newUI = new FakeUI(); var settings = new TestSettings(); var autogram = new Autogram(newUI, settings); @@ -95,7 +96,7 @@ void testSignAsiceCadesHappyScenario(InMemoryDocument document) { @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#pdfForPadesProvider" }) - void testSignPadesHappyScenario(InMemoryDocument document) { + void testSignPadesHappyScenario(ProtectedInMemoryDocument document) { var newUI = new FakeUI(); var settings = new TestSettings(); var autogram = new Autogram(newUI, settings); @@ -255,6 +256,11 @@ public void showError(AutogramException exception) { } + @Override + public char[] getDocumentPassword() { + return null; + } + @Override public char[] getKeystorePassword() { return null; From 6d00bebe5418d012962778999d85a3761de99e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 19 Aug 2024 21:41:29 +0200 Subject: [PATCH 02/50] feat: allow protected pdfs in batch --- .../slovensko/autogram/core/Autogram.java | 23 ++++++++++++++++++- .../slovensko/autogram/core/SigningJob.java | 14 +++++------ .../autogram/model/ProtectedDSSDocument.java | 4 ++++ .../autogram/ui/BatchGuiFileResponder.java | 5 +++- .../slovensko/autogram/ui/cli/CliApp.java | 11 ++++++--- .../slovensko/autogram/ui/cli/CliUI.java | 2 +- .../autogram/ui/gui/MainMenuController.java | 10 ++++---- .../slovensko/autogram/util/DSSUtils.java | 7 +++--- 8 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 53e99e33..7ec25e63 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -4,9 +4,11 @@ import digital.slovensko.autogram.core.visualization.DocumentVisualizationBuilder; import digital.slovensko.autogram.core.visualization.UnsupportedVisualization; import digital.slovensko.autogram.drivers.TokenDriver; +import digital.slovensko.autogram.model.ProtectedDSSDocument; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; +import digital.slovensko.autogram.util.PDFUtils; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.pdfa.PDFAStructureValidator; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; @@ -18,7 +20,7 @@ import java.util.function.Consumer; public class Autogram { - public final UI ui; + private final UI ui; private final UserSettings settings; /** Current batch, should be null if no batch was started yet */ private Batch batch = null; @@ -62,6 +64,25 @@ public void checkPDFACompliance(SigningJob job) { }); } + public void handleProtectedPdfDocument(ProtectedDSSDocument document) { + if (!PDFUtils.isPdfAndPasswordProtected(document)) + return; + + var password = ui.getDocumentPassword(); + document.setPassword(password); + } + + public void handleProtectedPdfDocument(ProtectedDSSDocument document, Runnable callback) { + if (!PDFUtils.isPdfAndPasswordProtected(document)) + return; + + ui.onWorkThreadDo(() -> { + var password = ui.getDocumentPassword(); + document.setPassword(password); + callback.run(); + }); + } + public void startVisualization(SigningJob job) { ui.onWorkThreadDo(() -> { try { diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index e3e4e26c..5eb235ca 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -12,10 +12,8 @@ import eu.europa.esig.dss.asic.cades.signature.ASiCWithCAdESService; import eu.europa.esig.dss.asic.xades.signature.ASiCWithXAdESService; import eu.europa.esig.dss.cades.signature.CAdESService; -import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.model.DSSDocument; -import eu.europa.esig.dss.model.FileDocument; import eu.europa.esig.dss.pades.signature.PAdESService; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; import eu.europa.esig.dss.validation.CommonCertificateVerifier; @@ -142,6 +140,7 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { signatureParameters.setSigningCertificate(key.getCertificate()); signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); + signatureParameters.setPasswordProtection(document.getPassword()); if (signatureParameters.getSignatureLevel().equals(SignatureLevel.PAdES_BASELINE_T)) { service.setTspSource(getParameters().getTspSource()); @@ -189,13 +188,12 @@ public static SigningJob buildFromRequest(ProtectedDSSDocument document, Signing } public static SigningJob buildFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { - return buildFromFile(file, "".toCharArray(), responder, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); - } - - public static SigningJob buildFromFile(File file, char[] password, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var document = createDSSFileDocumentFromFile(file); - document.setPassword(password); + var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); + return build(document, parameters, responder); + } + public static SigningJob buildFromFileDocument(ProtectedFileDocument document, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); return build(document, parameters, responder); } @@ -228,6 +226,6 @@ private static SigningParameters getParametersForFile(ProtectedFileDocument docu } public boolean shouldCheckPDFCompliance() { - return parameters.getCheckPDFACompliance() && isPDF(document.getMimeType()); + return parameters.getCheckPDFACompliance() && isPDF(document.getMimeType()) && !document.isProtected(); } } diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java index aaa9bc57..b8f9a4bf 100644 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java @@ -5,4 +5,8 @@ public interface ProtectedDSSDocument extends DSSDocument { char[] getPassword(); void setPassword(char[] password); + + default boolean isProtected() { + return getPassword().length != 0; + } } diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index 3bd9d303..bf2bbe05 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -64,7 +64,10 @@ public void onBatchStartSuccess(Batch batch) { onAllFilesSigned(batch); }), batch); - var job = SigningJob.buildFromFile(file, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); + var document = SigningJob.createDSSFileDocumentFromFile(file); + autogram.handleProtectedPdfDocument(document); + + var job = SigningJob.buildFromFileDocument(document, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); } catch (AutogramException e) { autogram.onSigningFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 973c1385..dd07edaf 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -30,9 +30,14 @@ public static void start(CommandLine cmd) { var source = settings.getSource(); var sourceList = source.isDirectory() ? source.listFiles() : new File[] { source }; var jobs = Arrays.stream(sourceList).filter(f -> f.isFile()) - .map(f -> SigningJob.buildFromFile(f, new SaveFileResponder(f, autogram, targetPathBuilder), - settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), - settings.getTspSource(), settings.isPlainXmlEnabled())) + .map(f -> { + var document = SigningJob.createDSSFileDocumentFromFile(f); + autogram.handleProtectedPdfDocument(document); + + return SigningJob.buildFromFileDocument(document, new SaveFileResponder(f, autogram, targetPathBuilder), + settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), + settings.getTspSource(), settings.isPlainXmlEnabled()); + }) .toList(); if (settings.isPdfaCompliance()) { jobs.forEach(job -> { diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 9c79d13a..98ad6985 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -269,7 +269,7 @@ public void showError(AutogramException e) { @Override public char[] getDocumentPassword() { - return new char[0]; + return System.console().readPassword("Enter document password (hidden): "); } @Override diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index 604f0f0d..d04ccc8c 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -110,15 +110,15 @@ private void signFiles(List list) { var filesList = getFilesList(list); if (filesList.size() == 1) { var file = filesList.get(0); + var document = SigningJob.createDSSFileDocumentFromFile(file); - autogram.ui.onUIThreadDo(() -> autogram.ui.onWorkThreadDo(() -> { - char[] password = autogram.ui.getDocumentPassword(); - - var job = SigningJob.buildFromFile(file, password, + autogram.handleProtectedPdfDocument(document, () -> { + var job = SigningJob.buildFromFileDocument(document, new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); + autogram.sign(job); - })); + }); } else { autogram.batchStart(filesList.size(), new BatchGuiFileResponder(autogram, filesList, filesList.get(0).toPath().getParent().resolve("signed"), userSettings.isPdfaCompliance(), diff --git a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java index 9ed2d8c6..87954841 100644 --- a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java @@ -39,11 +39,10 @@ public static String buildTooltipLabel(DSSPrivateKeyEntry key) { } public static SignedDocumentValidator createDocumentValidator(ProtectedDSSDocument document) { - System.out.println(document.getPassword()); if (new PDFDocumentValidatorFactory().isSupported(document)) { - var d = new PDFDocumentValidator(document); - d.setPasswordProtection(document.getPassword()); - return d; + var validator = new PDFDocumentValidator(document); + validator.setPasswordProtection(document.getPassword()); + return validator; } if (new XMLDocumentValidatorFactory().isSupported(document)) From 84a311f56ba14c244bd027c03b37a6d953c85c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 19 Aug 2024 21:48:30 +0200 Subject: [PATCH 03/50] fix: proxy asic original document instead casting --- .../autogram/util/AsicContainerUtils.java | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java index 15ad519b..91ed7569 100644 --- a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java @@ -5,6 +5,7 @@ import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; import digital.slovensko.autogram.model.ProtectedDSSDocument; import eu.europa.esig.dss.asic.xades.ASiCWithXAdESContainerExtractor; +import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeType; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.model.DSSDocument; @@ -13,6 +14,10 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + import static digital.slovensko.autogram.core.AutogramMimeType.isXML; public class AsicContainerUtils { @@ -42,11 +47,59 @@ public static ProtectedDSSDocument getOriginalDocument(ProtectedDSSDocument asic if (aSiCContent.getSignedDocuments().size() > 1) throw new MultipleOriginalDocumentsFoundException("V kontajneri bolo nájdených viacero dokumentov na podpis"); - var originalDocument = (ProtectedDSSDocument) aSiCContent.getSignedDocuments().get(0); + var originalDocument = aSiCContent.getSignedDocuments().get(0); if (isXML(originalDocument.getMimeType()) || MimeTypeEnum.BINARY.equals(originalDocument.getMimeType())) setMimeTypeFromManifest(asice, originalDocument); - return originalDocument; + return new ProtectedDSSDocument() { + @Override + public char[] getPassword() { + return new char[0]; + } + + @Override + public void setPassword(char[] password) {} + + @Override + public InputStream openStream() { + return originalDocument.openStream(); + } + + @Override + public void writeTo(OutputStream outputStream) throws IOException { + originalDocument.writeTo(outputStream); + } + + @Override + public String getName() { + return originalDocument.getName(); + } + + @Override + public void setName(String s) { + originalDocument.setName(s); + } + + @Override + public MimeType getMimeType() { + return originalDocument.getMimeType(); + } + + @Override + public void setMimeType(MimeType mimeType) { + originalDocument.setMimeType(mimeType); + } + + @Override + public void save(String s) throws IOException { + originalDocument.save(s); + } + + @Override + public String getDigest(DigestAlgorithm digestAlgorithm) { + return originalDocument.getDigest(digestAlgorithm); + } + }; } private static void setMimeTypeFromManifest(DSSDocument asiceContainer, DSSDocument documentToDisplay) { From 6eed34d708652d1d76ff58956e0f07d9348ea36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 19 Aug 2024 21:58:49 +0200 Subject: [PATCH 04/50] fix: tests --- .../slovensko/autogram/AutogramTests.java | 2 +- .../autogram/SigningParametersTests.java | 38 ++-- .../slovensko/autogram/TestMethodSources.java | 167 +++++++++--------- .../autogram/TransformationTests.java | 5 +- .../slovensko/autogram/XDCBuilderTests.java | 3 +- .../autogram/core/AsicContainerTest.java | 19 +- 6 files changed, 120 insertions(+), 114 deletions(-) diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index c11b81aa..c30f0e21 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -75,7 +75,7 @@ void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) { @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#nonEformXmlProvider"}) - void testSignNonEformNegativeScenario(InMemoryDocument document) { + void testSignNonEformNegativeScenario(ProtectedInMemoryDocument document) { Assertions.assertThrows(UnknownEformException.class, () -> SigningParameters.buildForASiCWithXAdES(document, false, false, null, false)); } diff --git a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java index 39c1b2e4..5794d2c2 100644 --- a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java @@ -3,6 +3,8 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.errors.*; +import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.ASiCContainerType; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; @@ -56,7 +58,7 @@ void setDefaultValues() throws IOException { @Test void testThrowsAutogramExceptionWhenNoMimeType() throws IOException { - var document = new InMemoryDocument(generalAgendaXml); + var document = new ProtectedInMemoryDocument(generalAgendaXml); Assertions.assertThrows(SigningParametersException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping, @@ -72,7 +74,7 @@ void testThrowsAutogramExceptionWhenNoDocument() { @Test void testThrowsXMLValidationFailedWhenNoXML() { - var document = new InMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML); + var document = new ProtectedInMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML); Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping, @@ -91,7 +93,7 @@ void testThrowsAutogramExceptionWhenNoSignatureLevel() { @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(DSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(ProtectedDSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, @@ -100,7 +102,7 @@ void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(DSSDocument docume @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesInAsice(DSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesInAsice(ProtectedDSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, null, null, null, null, @@ -109,7 +111,7 @@ void testDoesNotThrowWithMinimalParametersForXadesInAsice(DSSDocument document) @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(DSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(ProtectedDSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -118,7 +120,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(DSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(ProtectedDSSDocument document) { // TODO: mock eform S3 resource Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -128,7 +130,7 @@ void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(DSSDoc @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider") - void testThrowsAutogramExceptionWithInvalidXml(DSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXml(ProtectedDSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -137,7 +139,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(DSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(ProtectedDSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -147,7 +149,7 @@ void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(DSSDocument docu @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#nonEFormXmlProvider") - void testThrowsUnknownEformExceptionWithInvalidXmlEform(DSSDocument document) { + void testThrowsUnknownEformExceptionWithInvalidXmlEform(ProtectedDSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(UnknownEformException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -158,7 +160,7 @@ void testThrowsUnknownEformExceptionWithInvalidXmlEform(DSSDocument document) { @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlSchema(DSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlSchema(ProtectedDSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -167,7 +169,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(DSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(ProtectedDSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -177,7 +179,7 @@ void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(DSSDocumen @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testThrowsAutogramExceptionWithUnknownEformXml(DSSDocument document) { + void testThrowsAutogramExceptionWithUnknownEformXml(ProtectedDSSDocument document) { Assertions.assertThrows(EFormException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, null, null, null, new EFormAttributes(null, null, null, @@ -187,7 +189,7 @@ false, null, null, null, new EFormAttributes(null, null, null, @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#unknownEfomXmlProvider") - void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(DSSDocument document) { + void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(ProtectedDSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, true, @@ -196,7 +198,7 @@ void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(DSSDocument @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider") - void testThrowsAutogramExceptionWithMismatchedDigestsXml(DSSDocument document) { + void testThrowsAutogramExceptionWithMismatchedDigestsXml(ProtectedDSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -206,7 +208,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider", "digital.slovensko.autogram.TestMethodSources#mismatchedDigestsFSXmlProvider"}) - void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(DSSDocument document) { + void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(ProtectedDSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, true, @@ -215,14 +217,14 @@ void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(DSSDoc @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidAsiceProvider") - void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(DSSDocument document) throws IOException { + void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(ProtectedDSSDocument document) throws IOException { Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> SigningParameters.buildForASiCWithXAdES(document, false, false, tspSource, true)); } @Test void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException { - var document = new InMemoryDocument( + var document = new ProtectedInMemoryDocument( this.getClass().getResourceAsStream("empty_xml.asice").readAllBytes(), "empty_xml.asice"); @@ -233,7 +235,7 @@ void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException { @Test void testInvalidTransformation() throws IOException { var generalAgendaXml = this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(); - var document = new InMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML); + var document = new ProtectedInMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML); var transformation = "invalid transformation"; Assertions.assertThrows(TransformationParsingErrorException.class, diff --git a/src/test/java/digital/slovensko/autogram/TestMethodSources.java b/src/test/java/digital/slovensko/autogram/TestMethodSources.java index 5dec48f3..ede59d16 100644 --- a/src/test/java/digital/slovensko/autogram/TestMethodSources.java +++ b/src/test/java/digital/slovensko/autogram/TestMethodSources.java @@ -1,6 +1,7 @@ package digital.slovensko.autogram; import digital.slovensko.autogram.core.AutogramMimeType; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; @@ -22,15 +23,15 @@ public static Stream generalAgendaProvider() throws IOException { var indentedAsice = cls.getResourceAsStream("general_agenda_indented.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(inlineXml, "generalAgendaInlineXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(inlineXmlHeader, "generalAgendaInlineXmlHeader.xml", MimeTypeEnum.XML), - new InMemoryDocument(indentedXml, "generalAgendaIndentedXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(indentedXmlHeader, "generalAgendaIndentedXmlHeader.xml", MimeTypeEnum.XML), - new InMemoryDocument(inlineXdc, "generalAgendaInlineXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(indentedXdc, "generalAgendaIndentedXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(inlineAsice, "generalAgendaInlineAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(indentedAsice, "generalAgendaIndentedAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(inlineXml, "generalAgendaInlineXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(inlineXmlHeader, "generalAgendaInlineXmlHeader.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(indentedXml, "generalAgendaIndentedXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(indentedXmlHeader, "generalAgendaIndentedXmlHeader.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(inlineXdc, "generalAgendaInlineXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(indentedXdc, "generalAgendaIndentedXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(inlineAsice, "generalAgendaInlineAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(indentedAsice, "generalAgendaIndentedAsice.asice", MimeTypeEnum.ASICE) ); } @@ -38,9 +39,9 @@ public static Stream unsetXdcfMimetypeProvider() throws IOException var inlineXdcf = cls.getResourceAsStream("general_agenda.xdcf").readAllBytes(); return Stream.of( - new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfBinary.xdcf", MimeTypeEnum.BINARY), - new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfXml.xdcf", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfBinary.xdcf", MimeTypeEnum.BINARY), + new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfXml.xdcf", MimeTypeEnum.XML) ); } @@ -56,16 +57,16 @@ public static Stream fsDPFOProvider() throws IOException { var timestampedAsice = cls.getResourceAsStream("fs_forms/signed_indented_ts.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(inlineXml, "dic2120515056_fs792_772.xml", MimeTypeEnum.XML), - new InMemoryDocument(inlineXmlHeader, "d_fs792_772_header.xml", MimeTypeEnum.XML), - new InMemoryDocument(indentedXml, "d_fs792_772_indented.xml", MimeTypeEnum.XML), - new InMemoryDocument(indentedXmlHeader, "d_fs792_772_header_indented.xml", MimeTypeEnum.XML), - new InMemoryDocument(inlineXdc, "d_fs792_772_xdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(indentedXdc, "d_fs792_772_xdc_indented.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(inlineAsice, "signed.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(inlineAsice, "d_fs792_772_signed.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(indentedAsice, "signed_indented.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(timestampedAsice, "signed_indented_ts.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(inlineXml, "dic2120515056_fs792_772.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(inlineXmlHeader, "d_fs792_772_header.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(indentedXml, "d_fs792_772_indented.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(indentedXmlHeader, "d_fs792_772_header_indented.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(inlineXdc, "d_fs792_772_xdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(indentedXdc, "d_fs792_772_xdc_indented.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(inlineAsice, "signed.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(inlineAsice, "d_fs792_772_signed.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(indentedAsice, "signed_indented.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(timestampedAsice, "signed_indented_ts.asice", MimeTypeEnum.ASICE) ); } @@ -89,12 +90,12 @@ public static Stream invalidXmlProvider() throws IOException { return Stream.of( - new InMemoryDocument(notAnXml, "notAnXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(invalidXml, "invalidXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(invalidXmlHeader, "invalidXmlHeader.xml", MimeTypeEnum.XML), - new InMemoryDocument(invalidXdc, "invalidXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(twoRootElements, "twoRootElements.xml", MimeTypeEnum.XML), - new InMemoryDocument(twoRootElementsHeader, "twoRootElementsHeader.xml", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(notAnXml, "notAnXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(invalidXml, "invalidXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(invalidXmlHeader, "invalidXmlHeader.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(invalidXdc, "invalidXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(twoRootElements, "twoRootElements.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(twoRootElementsHeader, "twoRootElementsHeader.xml", MimeTypeEnum.XML) ); } @@ -102,7 +103,7 @@ public static Stream nonEFormXmlProvider() throws IOException { var wrongXdcSchemaXml = cls.getResourceAsStream("wrong_schema_xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(wrongXdcSchemaXml, "wrongXdcSchemaXml.xml", AutogramMimeType.XML_DATACONTAINER) + new ProtectedInMemoryDocument(wrongXdcSchemaXml, "wrongXdcSchemaXml.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -111,8 +112,8 @@ public static Stream xsdSchemaFailedValidationXmlProvider() throws var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(wrongSchemaGAXml, "wrongSchemaGAXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) + new ProtectedInMemoryDocument(wrongSchemaGAXml, "wrongSchemaGAXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -123,10 +124,10 @@ public static Stream mismatchedDigestsXmlProvider() throws IOExcept var mismatchedXsltGAXdcAsice = cls.getResourceAsStream("mismatched_xslt_ga_xdc.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(mismatchedXsdGAXdcXml, "mismatchedXsdGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsltGAXdcXml, "mismatchedXsltGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsdGAXdcAsice, "mismatchedXsdGAXdcAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(mismatchedXsltGAXdcAsice, "mismatchedXsltGAXdcAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(mismatchedXsdGAXdcXml, "mismatchedXsdGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsltGAXdcXml, "mismatchedXsltGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsdGAXdcAsice, "mismatchedXsdGAXdcAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(mismatchedXsltGAXdcAsice, "mismatchedXsltGAXdcAsice.asice", MimeTypeEnum.ASICE) ); } @@ -137,10 +138,10 @@ public static Stream mismatchedDigestsFSXmlProvider() throws IOExce var mismatchedXsltFSXsltXdcAsice = cls.getResourceAsStream("fs_forms/signed_xdc_xslt_digest.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(mismatchedXsltFSXdcXml, "d_fs792_772_xdc_xsd_digest.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsltFSXsltXdcXml, "d_fs792_772_xdc_xslt_digest.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsltFSXdcAsice, "signed_xdc_xsd_digest.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(mismatchedXsltFSXsltXdcAsice, "signed_xdc_xslt_digest.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(mismatchedXsltFSXdcXml, "d_fs792_772_xdc_xsd_digest.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsltFSXsltXdcXml, "d_fs792_772_xdc_xslt_digest.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsltFSXdcAsice, "signed_xdc_xsd_digest.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(mismatchedXsltFSXsltXdcAsice, "signed_xdc_xslt_digest.asice", MimeTypeEnum.ASICE) ); } @@ -150,9 +151,9 @@ public static Stream unknownEfomXmlProvider() throws IOException { var unknownEfomAsice = cls.getResourceAsStream("unknown_eform.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(unknownEfomXml, "unknownEfomXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(unknownEfomAsice, "unknownEfomAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(unknownEfomXml, "unknownEfomXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(unknownEfomAsice, "unknownEfomAsice.asice", MimeTypeEnum.ASICE) ); } @@ -166,9 +167,9 @@ public static Stream invalidAsiceProvider() throws IOException { // var noMimetypeAsice = cls.getResourceAsStream("no_mimetype.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(noSignaturesAsice, "noSignaturesAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(invalidAsice, "invalidAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(noMetaInfAsice, "noMetaInfAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(noSignaturesAsice, "noSignaturesAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(invalidAsice, "invalidAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(noMetaInfAsice, "noMetaInfAsice.asice", MimeTypeEnum.ASICE) ); } @@ -180,11 +181,11 @@ public static Stream validOtherDocumentsProvider() throws IOEx var sampleDocx = cls.getResourceAsStream("sample.docx").readAllBytes(); return Stream.of( - new InMemoryDocument(sampleTxt, "sample.txt", MimeTypeEnum.TEXT), - new InMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), - new InMemoryDocument(samplePng, "sample.png", MimeTypeEnum.PNG), - new InMemoryDocument(sampleIco, "sample.ico", new AutogramMimeType("image/x-icon", "ico")), - new InMemoryDocument(sampleDocx, "sample.docx", new AutogramMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx")) + new ProtectedInMemoryDocument(sampleTxt, "sample.txt", MimeTypeEnum.TEXT), + new ProtectedInMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), + new ProtectedInMemoryDocument(samplePng, "sample.png", MimeTypeEnum.PNG), + new ProtectedInMemoryDocument(sampleIco, "sample.ico", new AutogramMimeType("image/x-icon", "ico")), + new ProtectedInMemoryDocument(sampleDocx, "sample.docx", new AutogramMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx")) ); } @@ -192,7 +193,7 @@ public static Stream nonEformXmlProvider() throws IOException var nonEformXml = cls.getResourceAsStream("non_eform.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML) ); } @@ -201,8 +202,8 @@ public static Stream pdfForPadesProvider() throws IOException var samplePdfSigned = cls.getResourceAsStream("sample_signed.pdf").readAllBytes(); return Stream.of( - new InMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), - new InMemoryDocument(samplePdfSigned, "sample_signed.pdf", MimeTypeEnum.PDF) + new ProtectedInMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), + new ProtectedInMemoryDocument(samplePdfSigned, "sample_signed.pdf", MimeTypeEnum.PDF) ); } @@ -215,12 +216,12 @@ public static Stream validXadesDocumentsProvider() throws IOEx var sampleDocxXadesAsice = cls.getResourceAsStream("sample_docx_xades.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(generalAgendaAsice, "generalAgendaAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(sampleTxtXadesAsice, "sampleTxtXadesAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(samplePdfXadesAsice, "samplePdfXadesAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(samplePngXadesAsice, "samplePngXadesAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(sampleIcoXadesAsice, "sampleIcoXadesAsice.asice", MimeTypeEnum.ASICE), - new InMemoryDocument(sampleDocxXadesAsice, "sampleDocxXadesAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(generalAgendaAsice, "generalAgendaAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(sampleTxtXadesAsice, "sampleTxtXadesAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(samplePdfXadesAsice, "samplePdfXadesAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(samplePngXadesAsice, "samplePngXadesAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(sampleIcoXadesAsice, "sampleIcoXadesAsice.asice", MimeTypeEnum.ASICE), + new ProtectedInMemoryDocument(sampleDocxXadesAsice, "sampleDocxXadesAsice.asice", MimeTypeEnum.ASICE) ); } @@ -233,12 +234,12 @@ public static Stream xdcDocumentsProvider() throws IOException var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) + new ProtectedInMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -251,12 +252,12 @@ public static Stream xdcDocumentsWithXmlMimetypeProvider() thr var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", MimeTypeEnum.XML), - new InMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", MimeTypeEnum.XML), - new InMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", MimeTypeEnum.XML), - new InMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", MimeTypeEnum.XML), - new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", MimeTypeEnum.XML), - new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", MimeTypeEnum.XML) ); } @@ -269,12 +270,12 @@ public static Stream nonXdcXmlDocumentsProvider() throws IOExc var wrongSchemaXdcXml = cls.getResourceAsStream("wrong_schema_xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(documentContentNoUsedXSDReference, "documentContentNoUsedXSDReference.xml", MimeTypeEnum.XML), - new InMemoryDocument(documentContentUsedXSDReferenceNoAttributes, "documentContentUsedXSDReferenceNoAttributes.xml", MimeTypeEnum.XML), - new InMemoryDocument(documentContentUsedXSDReferenceNoDigestValue, "documentContentUsedXSDReferenceNoDigestValue.xml", MimeTypeEnum.XML), - new InMemoryDocument(emptyXml, "emptyXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML), - new InMemoryDocument(wrongSchemaXdcXml, "wrongSchemaXdcXml.xml", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(documentContentNoUsedXSDReference, "documentContentNoUsedXSDReference.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(documentContentUsedXSDReferenceNoAttributes, "documentContentUsedXSDReferenceNoAttributes.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(documentContentUsedXSDReferenceNoDigestValue, "documentContentUsedXSDReferenceNoDigestValue.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(emptyXml, "emptyXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(wrongSchemaXdcXml, "wrongSchemaXdcXml.xml", MimeTypeEnum.XML) ); } @@ -282,7 +283,7 @@ public static Stream validCadesDocumentsProvider() throws IOEx var samplePdfCadesAsice = cls.getResourceAsStream("sample_pdf_cades.asice").readAllBytes(); return Stream.of( - new InMemoryDocument(samplePdfCadesAsice, "samplePdfCadesAsice.asice", MimeTypeEnum.ASICE) + new ProtectedInMemoryDocument(samplePdfCadesAsice, "samplePdfCadesAsice.asice", MimeTypeEnum.ASICE) ); } @@ -294,11 +295,11 @@ public static Stream orsrDocumentsProvider() throws IOExcepti var fupsXdcNoNamespaceXml = cls.getResourceAsStream("FUPS_wo_namespace.xdc.xml").readAllBytes(); return Stream.of( - new InMemoryDocument(fupaXml, "FUPA.xml", MimeTypeEnum.XML), - new InMemoryDocument(fupsXml, "FUPS.xml", MimeTypeEnum.XML), - new InMemoryDocument(fuzsNewXml, "fuzs_new.xml", MimeTypeEnum.XML), - new InMemoryDocument(fupsXdcXml, "FUPS.xdc.xml", MimeTypeEnum.XML), - new InMemoryDocument(fupsXdcNoNamespaceXml, "FUPS_wo_namespace.xdc.xml", MimeTypeEnum.XML) + new ProtectedInMemoryDocument(fupaXml, "FUPA.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(fupsXml, "FUPS.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(fuzsNewXml, "fuzs_new.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(fupsXdcXml, "FUPS.xdc.xml", MimeTypeEnum.XML), + new ProtectedInMemoryDocument(fupsXdcNoNamespaceXml, "FUPS_wo_namespace.xdc.xml", MimeTypeEnum.XML) ); } } diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index 40da9e10..bb4f9452 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -10,6 +10,7 @@ import digital.slovensko.autogram.core.*; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -42,7 +43,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce "crystal_test_data/PovolenieZdravotnictvo.html.xslt") .readAllBytes()); - var document = new InMemoryDocument( + var document = new ProtectedInMemoryDocument( this.getClass().getResourceAsStream( "crystal_test_data/rozhodnutie_X4564-2.xml"), "rozhodnutie_X4564-2.xml"); @@ -120,7 +121,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio "crystal_test_data/PovolenieZdravotnictvo.sb.xslt") .readAllBytes()); - var document = new InMemoryDocument( + var document = new ProtectedInMemoryDocument( this.getClass().getResourceAsStream( "crystal_test_data/rozhodnutie_X4564-2.xml"), "rozhodnutie_X4564-2.xml"); diff --git a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java index cdf16808..fa51ae91 100644 --- a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java +++ b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java @@ -4,6 +4,7 @@ import digital.slovensko.autogram.core.eforms.EFormUtils; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.eforms.xdc.XDCBuilder; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.ASiCContainerType; import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeTypeEnum; @@ -25,7 +26,7 @@ void testTransformsPlainHtmlWithoutAddingNamespaces() throws IOException { var transformation = new String(this.getClass().getResourceAsStream("general_agenda.xslt").readAllBytes(), StandardCharsets.UTF_8); var xsdSchema = new String(this.getClass().getResourceAsStream("general_agenda.xsd").readAllBytes(), StandardCharsets.UTF_8); - var document = new InMemoryDocument(this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(), "general_agenda.xml", MimeTypeEnum.XML); + var document = new ProtectedInMemoryDocument(this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(), "general_agenda.xml", MimeTypeEnum.XML); var params = SigningParameters.buildParameters( SignatureLevel.XAdES_BASELINE_B, diff --git a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java index eb96b2b7..e000cb8e 100644 --- a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java +++ b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java @@ -2,6 +2,7 @@ import digital.slovensko.autogram.core.errors.MultipleOriginalDocumentsFoundException; import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; +import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.util.AsicContainerUtils; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.model.InMemoryDocument; @@ -15,10 +16,10 @@ class AsicContainerTest { @Test void testGetOriginalFileXdc() { var asiceWithXdcOriginalFileContent = "UEsDBAoAAAgAALZj+laKIflFHwAAAB8AAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi92bmQuZXRzaS5hc2ljLWUremlwUEsDBBQACAgIALZj+lYAAAAAAAAAAAAAAAAMAAAAZG9jdW1lbnQueG1sxZTbctowEIZfRaPbDJIVSAoUk+GUtE1oKYEELhVrMQpGciVxSN+ml32OvFhlHCB0aGY6veildn+t/v127drFep6gJRgrtQoxIwFGoCItpIpDPBxcFsr4ol5bi6g66t60ueMtrRyXCgzyN5Wt+lSIp86lVUqFz5NYL4mdUQETGm211Guz5C5w4gOUEYYPaqOsOCg3eEohxDxNExlx551l99+jaMqNBRfmttBH4aVyIsEcN6AjChNt5rSRpuQK/Ks8acSgBPcvVzC623dd8T4OFHlzu7o2msKc223pt6q+ULFyd3m1WpFVkWgT09MgYNQ3e7upV5DKOq4i8K/bxcMjRK7+WS+ff6JUC64k1Og2XHOwdvWeFs8/lnyOnHYaqddSUqMbSY0eePLnV3xz2EMLIjdg+zAB4+cNYp8a3bZ3YdSWMVjXBTfVIsQLo6paiuopYeekXAqIn2DASJGUiA/hF/UdTxZ+fLTlVNCstN99uFbnw/5lvyx7w+vJ0xWU5s1xen1yeiYiJsf3i06I0cBwZTOujSTWRrrp/Bi/QT9H2O+0Ch50IWIlVcgiQZGd4frfTmuTImsrckq/d79n0jNg/bJtdjFHt0f05521icv2HP8Lxa+aPY5H7NP9k1h26ZcbapQ06XTGTJd9L7FJrz9qduKUfnvw3yu64Spe8NjfszOMuiAkb/taUm0cZRb9MTIydZvFH4wG/5l84vbo34Bc36uObC499nuq/wJQSwcImbqZaCoCAADbBAAAUEsDBBQACAgIALZj+lYAAAAAAAAAAAAAAAAaAAAATUVUQS1JTkYvc2lnbmF0dXJlczAwMS54b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new InMemoryDocument(Base64.getDecoder().decode(asiceWithXdcOriginalFileContent), null, MimeTypeEnum.ASICE); + var asiceWithXdcOriginalFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceWithXdcOriginalFileContent), null, MimeTypeEnum.ASICE); var actualOriginalXdcFileContent = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48eGRjOlhNTERhdGFDb250YWluZXIgeG1sbnM6eGRjPSJodHRwOi8vZGF0YS5nb3Yuc2svZGVmL2NvbnRhaW5lci94bWxkYXRhY29udGFpbmVyK3htbC8xLjEiPjx4ZGM6WE1MRGF0YSBDb250ZW50VHlwZT0iYXBwbGljYXRpb24veG1sOyBjaGFyc2V0PVVURi04IiBJZGVudGlmaWVyPSJodHRwOi8vZGF0YS5nb3Yuc2svZG9jL2Vmb3JtL0FwcC5HZW5lcmFsQWdlbmRhLzEuOSIgVmVyc2lvbj0iMS45Ij48R2VuZXJhbEFnZW5kYSB4bWxucz0iaHR0cDovL3NjaGVtYXMuZ292LnNrL2Zvcm0vQXBwLkdlbmVyYWxBZ2VuZGEvMS45IiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIj48c3ViamVjdD5Ob3bDqSBwb2RhbmllPC9zdWJqZWN0Pjx0ZXh0PlBvZMOhdmFtIHRvdG8gbm92w6kgcG9kYW5pZS48L3RleHQ+PC9HZW5lcmFsQWdlbmRhPjwveGRjOlhNTERhdGE+PHhkYzpVc2VkU2NoZW1hc1JlZmVyZW5jZWQ+PHhkYzpVc2VkWFNEUmVmZXJlbmNlIERpZ2VzdE1ldGhvZD0idXJuOm9pZDoyLjE2Ljg0MC4xLjEwMS4zLjQuMi4xIiBEaWdlc3RWYWx1ZT0iL0N0bjBCOUQ3SEtuNlVSRlI4aVBVS2Z5R2U0bUJZcEsrMjVkYzFpWVd1RT0iIFRyYW5zZm9ybUFsZ29yaXRobT0iaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMteG1sLWMxNG4tMjAwMTAzMTUiPmh0dHA6Ly9zY2hlbWFzLmdvdi5zay9mb3JtL0FwcC5HZW5lcmFsQWdlbmRhLzEuOS9mb3JtLnhzZDwveGRjOlVzZWRYU0RSZWZlcmVuY2U+PHhkYzpVc2VkUHJlc2VudGF0aW9uU2NoZW1hUmVmZXJlbmNlIENvbnRlbnRUeXBlPSJhcHBsaWNhdGlvbi94c2x0K3htbCIgRGlnZXN0TWV0aG9kPSJ1cm46b2lkOjIuMTYuODQwLjEuMTAxLjMuNC4yLjEiIERpZ2VzdFZhbHVlPSJRbzFqWVgxSld5ZHZNL09ML3JuaXJwaGsxck0xejQxZlBSWEJFZ3AvcWJnPSIgTGFuZ3VhZ2U9InNrIiBNZWRpYURlc3RpbmF0aW9uVHlwZURlc2NyaXB0aW9uPSJUWFQiIFRyYW5zZm9ybUFsZ29yaXRobT0iaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMteG1sLWMxNG4tMjAwMTAzMTUiPmh0dHA6Ly9zY2hlbWFzLmdvdi5zay9mb3JtL0FwcC5HZW5lcmFsQWdlbmRhLzEuOS9mb3JtLnhzbHQ8L3hkYzpVc2VkUHJlc2VudGF0aW9uU2NoZW1hUmVmZXJlbmNlPjwveGRjOlVzZWRTY2hlbWFzUmVmZXJlbmNlZD48L3hkYzpYTUxEYXRhQ29udGFpbmVyPg=="; - var actualOriginalXdcFile = new InMemoryDocument(Base64.getDecoder().decode(actualOriginalXdcFileContent), "document.xml", AutogramMimeType.XML_DATACONTAINER); + var actualOriginalXdcFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(actualOriginalXdcFileContent), "document.xml", AutogramMimeType.XML_DATACONTAINER); var xdcFileFromAsice = AsicContainerUtils.getOriginalDocument(asiceWithXdcOriginalFile); @@ -29,7 +30,7 @@ void testGetOriginalFileXdc() { @Test void testGetOriginalFileNoSigantures() { var asiceContent = "UEsDBBQAAAAIAFZ6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0dPL475eHb1BLAwQUAAAAAABWehBXiiH5RR8AAAAfAAAACAAAAG1pbWV0eXBlYXBwbGljYXRpb24vdm5kLmV0c2kuYXNpYy1lK3ppcFBLAQIUABQAAAAIAFZ6EFeZuploLAIAANsEAAAMAAAAAAAAAAEAIAAAAAAAAABkb2N1bWVudC54bWxQSwECFAAUAAAACABXehBXuT2EmMAAAACFAQAAFQAAAAAAAAABACAAAABWAgAATUVUQS1JTkYvbWFuaWZlc3QueG1sUEsBAhQAFAAAAAAAVnoQV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAASQMAAG1pbWV0eXBlUEsFBgAAAAADAAMAswAAAI4DAAAAAA=="; - var asiceWithoutSignatures = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutSignatures = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithoutSignatures)); } @@ -37,7 +38,7 @@ void testGetOriginalFileNoSigantures() { @Test void testGetOriginalFileNoOriginalFileInAsice() { var asiceContent = "UEsDBBQAAAAIALB7EFe5PYSYwAAAAIUBAAAVAAAATUVUQS1JTkYvbWFuaWZlc3QueG1sjZDBTgMxDER/ZeVrlSxwQlHT3vgC+AAr8RaLxIk23hXl60mRWhZx6c0jzcwbeX/8zGlYaW5cxMOjfYCBJJTIcvLw9vpinuF42GcUnqipux5Dj0m7SQ/LLK5g4+YEMzWnwZVKEktYMom6v373A7qpDf8JNrSJE5mens+/3mlJyVTUdw/jpiJTZDR6ruQBa00cUHvluEq0pI1t3xYM7b64wng/4rrf9v130k5lte3jEoioGIoostC8uzR08vjvl4dvUEsDBBQAAAAIALB7EFdq0ASBPQcAAHEOAAAaAAAATUVUQS1JTkYvc2lnbmF0dXJlczAwMS54bWy1V1l3gsgS/is5yaOTsLqQk2QOq4ICsinwxtICyiar8usvamLWuZM5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ll8WfniEDV0qs+Wh/YknfI/yIuHLsgaFBorIia9T4iL87Zz5oH2dVGd/Up24oHhBRuPxGEHGBPo+mj7uvwX3ORToY46hv76KD1t/WwHAP72GS+1/13jf43q+51Q3l8WVXvWl/Vvu/uZS7OvoxIFfnDyPTwH3f1SgJvUfgqx5KHcnUu/3p3pZWjlRCopBL3hDdLV9E3yN7wv2n6F9Uvlh46enf2kXby3iE1Pplz/9aXz5D1BLAwQUAAAAAACwexBXiiH5RR8AAAAfAAAACAAAAG1pbWV0eXBlYXBwbGljYXRpb24vdm5kLmV0c2kuYXNpYy1lK3ppcFBLAQIUABQAAAAIALB7EFe5PYSYwAAAAIUBAAAVAAAAAAAAAAEAIAAAAAAAAABNRVRBLUlORi9tYW5pZmVzdC54bWxQSwECFAAUAAAACACwexBXatAEgT0HAABxDgAAGgAAAAAAAAABACAAAADzAAAATUVUQS1JTkYvc2lnbmF0dXJlczAwMS54bWxQSwECFAAUAAAAAACwexBXiiH5RR8AAAAfAAAACAAAAAAAAAABACAAAABoCAAAbWltZXR5cGVQSwUGAAAAAAMAAwDBAAAArQgAAAAA"; - var asiceWithoutOriginalFile = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutOriginalFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithoutOriginalFile)); } @@ -45,7 +46,7 @@ void testGetOriginalFileNoOriginalFileInAsice() { @Test void testGetOriginalFileNoFileEntriesInManifest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHp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IFfnDyPTwH3f1SgJvUfgqx5KHcnUu/3p3pZWjlRCopBL3hDdLV9E3yN7wv2n6F9Uvlh46enf2kXby3iE1Pplz/9aXz5D1BLAwQUAAAAAAD0exBXiiH5RR8AAAAfAAAACAAAAG1pbWV0eXBlYXBwbGljYXRpb24vdm5kLmV0c2kuYXNpYy1lK3ppcFBLAQIUABQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAAAAAAAEAIAAAAAAAAABkb2N1bWVudC54bWxQSwECFAAUAAAACAAZfBBXUADISG4AAACoAAAAFQAAAAAAAAABACAAAABWAgAATUVUQS1JTkYvbWFuaWZlc3QueG1sUEsBAhQAFAAAAAgA9HsQV2rQBIE9BwAAcQ4AABoAAAAAAAAAAQAgAAAA9wIAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAAAAAA9HsQV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAAbAoAAG1pbWV0eXBlUEsFBgAAAAAEAAQA+wAAALEKAAAAAA=="; - var asiceWithManifestFileWithoutFileEntries = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithManifestFileWithoutFileEntries = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithManifestFileWithoutFileEntries); @@ -57,7 +58,7 @@ void testGetOriginalFileNoFileEntriesInManifest() { @Test void testGetOriginalFileInvalidManifest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIM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AUAAAACAD0exBXmbqZaCwCAADbBAAADAAAAAAAAAABACAAAAAAAAAAZG9jdW1lbnQueG1sUEsBAhQAFAAAAAAA8X0QVwAAAAAAAAAAAAAAABUAAAAAAAAAAAAgAAAAVgIAAE1FVEEtSU5GL21hbmlmZXN0LnhtbFBLAQIUABQAAAAIAPR7EFdq0ASBPQcAAHEOAAAaAAAAAAAAAAEAIAAAAIkCAABNRVRBLUlORi9zaWduYXR1cmVzMDAxLnhtbFBLAQIUABQAAAAAAPR7EFeKIflFHwAAAB8AAAAIAAAAAAAAAAEAIAAAAP4JAABtaW1ldHlwZVBLBQYAAAAABAAEAPsAAABDCgAAAAA="; - var asiceWithInvalidManifestFile = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithInvalidManifestFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithInvalidManifestFile); @@ -69,7 +70,7 @@ void testGetOriginalFileInvalidManifest() { @Test void testGetOriginalFileNoMainfest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu+qyXTz9RpgVXEpr0Jdx0sHZRX4unH0s+R047jdRrKWnSQtKkO578+RXfEvbIgigN2AFMwfh5g9imxt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File = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutManifestFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithoutManifestFile); @@ -81,7 +82,7 @@ void testGetOriginalFileNoMainfest() { @Test void testGetOriginalFileManifestFileEntriesNoAttributes() { var asiceContent = "UEsDBBQAAAAIAG1+EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu+qyXTz9RpgVXEpr0Jdx0sHZRX4unH0s+R047jdRrKWnSQtKkO578+RXfEvbIgigN2AFMwfh5g9imxtedTRh1ZALW9cDNtAjxwqiGlqJRJeyYnNQC4icYMHJIasSH8LP6hqcLPz565lTQrnfefeiq49HgYnAi+6Pu9PESavP2JOseVI9EzOTkdnEeYjQ0XNmcaytNtJFuNt/HbzgoEQ7OzyoedCVmNVXJI8EhO8LR306rSJG1FSWl37vfMukbsH7Zil0s0W0R/XlnberyPcf/QvGrZveTMft0+yiWPfrliholTTZ7YKbHvtfYtD8Yt8+TjH67898ruuIqWfDE37MPGPVASN7xtaQqHOUW/TE2MnPF4g/Hw/9MPnVb9G9AjraqPZv7esU3v6foF1BLAwQUAAAACACNfhBXqJLPmXoAAADUAAAAFQAAAE1FVEEtSU5GL21hbmlmZX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X3V2NaYkt2WGXCI1vtsWnSVcJCKFzEbY2ByoHE1VIdaF7fLJefDgRg3JLZivM1UGbaps1UNdTd08JA90J6Mm6RIzsPdFPHww3ofA8jxl7O8wX1vQomk8tpLvj7uq/DSQaAvvUU+t4aXp/OgfVTqnkZtjj05fB/Fr1TurPBfRviJCGIPaE/mdKcIQNUP718NlteTvxKA83z6J9P/o5trP33391Ghh6dHfS9EYRS7h8f36EhH4EeUeMRx+wn6rvfZ9FNyLzsn0cfvy2T+P/EE99gky5KIw0UF0ojfu0doAdlJdDS4Ll8WfniEDV0qs+Wh/YknfI/yIuHLsgaFBorIia9T4iL87Zz5oH2dVGd/Up24oHhBRuPxGEHGBPo+mj7uvwX3ORToY46hv76KD1t/WwHAP72GS+1/13jf43q+51Q3l8WVXvWl/Vvu/uZS7OvoxIFfnDyPTwH3f1SgJvUfgqx5KHcnUu/3p3pZWjlRCopBL3hDdLV9E3yN7wv2n6F9Uvlh46enf2kXby3iE1Pplz/9aXz5D1BLAwQUAAAAAABtfhBXiiH5RR8AAAAfAAAACAAAAG1pbWV0eXBlYXBwbGljYXRpb24vdm5kLmV0c2kuYXNpYy1lK3ppcFBLAQIUABQAAAAIAG1+EFeZuploLAIAANsEAAAMAAAAAAAAAAEAIAAAAAAAAABkb2N1bWVudC54bWxQSwECFAAUAAAACACNfhBXqJLPmXoAAADUAAAAFQAAAAAAAAABACAAAABWAgAATUVUQS1JTkYvbWFuaWZlc3QueG1sUEsBAhQAFAAAAAgAbX4QV2rQBIE9BwAAcQ4AABoAAAAAAAAAAQAgAAAAAwMAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAAAAAAbX4QV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAAeAoAAG1pbWV0eXBlUEsFBgAAAAAEAAQA+wAAAL0KAAAAAA=="; - var asiceWithManifestFileWithNoFileEntryAttributes = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithManifestFileWithNoFileEntryAttributes = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithManifestFileWithNoFileEntryAttributes); @@ -93,7 +94,7 @@ void testGetOriginalFileManifestFileEntriesNoAttributes() { @Test void testGetOriginalFileMultipleFilesInAsice() { var asiceContent = "UEsDBBQDAAAIAAdfElfy7qAyvAAAALcBAAAVAAAATUVUQS1JTkYvbWFuaWZlc3QueG1slZBNbgIxDEb3PcXI2yqTllUVEdj1BO0BrIwBS4kTTTxo4PSMkIBBsICdP/+8J3m5HlNs9tRXzuLhu/2ChiTkjmXr4f/v1/zAerVMKLyhqu5SNNOZ1Gv0MPTiMlauTjBRdRpcLiRdDkMiUXe/786ia5r5FzCzbTiSIdH+0Nx6Q4ymoO482BkiUcdo9FDIA5YSOaBOSLuXriWt3GLlYOjzyAXs6wqdcqujPjdN41FticjyLnTxMtU+PH/1cQJQSwMEFAAICAgAoFESVwAAAAAAAAAAAAAAABoAAABNRVRBLUlORi9zaWduYXR1cmVzMDAxLnhtbLVXWXeqyhL+K1nm0ZswI2YlOauZUQFBRPENmWWUQdBff1F3zLBz7s1e59637uqq6pq66uvnv7o0uTt4ZRXl2csAeYQHd17m5G6UBS+DpcE/UIO/Xp/tKnKe1sDlFosoyOy6Kb3qrpfMqqfz0csgrOviCYKaMnr06ip6zMsAgtExQkEH5BF9RO4Hr89u9XST/iXsVjfRtm0fW+wiiMIwDMFjqOdxqyi4H9xJ7ssgch9IeOuShEP5CIwgGEngKEZi+BgjiK3vopj/fonnSpmfX7aMneVZ5NhJdLLr3kvZq8PcvQNJkJdRHabfWWDoZyMQSOeYh96KBwfBs4czBcYQYgB99uUnCi/aYPzNpYc0L737srIfqtBGCfKXSt3zvbIPv3dxuHz4gcsPyOBuqUsvg9qr6se6q68xYKOg3/+hZf3N95/suWox7aTxXhU5LKjCGiMhkLQt4lE6jmmN3aYbAfc2lI0XKHu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taW1ldHlwZWFwcGxpY2F0aW9uL3ZuZC5ldHNpLmFzaWMtZSt6aXBQSwMEFAAICAgAoFESVwAAAAAAAAAAAAAAAAgAAAB0ZXN0LnR4dAvJL8lXyEpVKEktLuECAFBLBwjvDPUSDwAAAA0AAABQSwMECgMAAAAAIVESV+8M9RINAAAADQAAAAkAAAB0ZXN0Mi50eHRUb3RvIGplIHRlc3QKUEsBAj8DFAMAAAgAB18SV/LuoDK8AAAAtwEAABUAJAAAAAAAAAAggLSBAAAAAE1FVEEtSU5GL21hbmlmZXN0LnhtbAoAIAAAAAAAAQAYAADzUjm60dkBAPNSObrR2QEA81I5utHZAVBLAQIUABQACAgIAKBRElfm1p3nmwcAAE8PAAAaAAAAAAAAAAAAAAAAAO8AAABNRVRBLUlORi9zaWduYXR1cmVzMDAxLnhtbFBLAQIKAAoAAAgAAKBREleKIflFHwAAAB8AAAAIAAAAAAAAAAAAAAAAANIIAABtaW1ldHlwZVBLAQIUABQACAgIAKBRElfvDPUSDwAAAA0AAAAIAAAAAAAAAAAAAAAAABcJAAB0ZXN0LnR4dFBLAQI/AwoDAAAAACFRElfvDPUSDQAAAA0AAAAJACQAAAAAAAAAIIC0gVwJAAB0ZXN0Mi50eHQKACAAAAAAAAEAGAAAo40/q9HZAYCe812r0dkBgL39V6vR2QFQSwUGAAAAAAUABQB2AQAAkAkAAAAA"; - var asiceWithMultipleFiles = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithMultipleFiles = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(MultipleOriginalDocumentsFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithMultipleFiles)); } From aad94b74dd8094a30c4919ec94bf7586c726da18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Tue, 20 Aug 2024 17:59:43 +0200 Subject: [PATCH 05/50] fix: run callback, default pass --- src/main/java/digital/slovensko/autogram/core/Autogram.java | 4 +++- .../slovensko/autogram/model/ProtectedFileDocument.java | 2 +- .../slovensko/autogram/model/ProtectedInMemoryDocument.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 7ec25e63..e033843a 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -73,8 +73,10 @@ public void handleProtectedPdfDocument(ProtectedDSSDocument document) { } public void handleProtectedPdfDocument(ProtectedDSSDocument document, Runnable callback) { - if (!PDFUtils.isPdfAndPasswordProtected(document)) + if (!PDFUtils.isPdfAndPasswordProtected(document)) { + callback.run(); return; + } ui.onWorkThreadDo(() -> { var password = ui.getDocumentPassword(); diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java index 797a3e4d..345f4d28 100644 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java @@ -5,7 +5,7 @@ import java.io.File; public class ProtectedFileDocument extends FileDocument implements ProtectedDSSDocument { - private char[] password; + private char[] password = new char[0]; public ProtectedFileDocument(String path) { super(path); diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java index ff487880..df4179f8 100644 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java @@ -6,7 +6,7 @@ import java.io.InputStream; public class ProtectedInMemoryDocument extends InMemoryDocument implements ProtectedDSSDocument { - private char[] password; + private char[] password = new char[0]; public ProtectedInMemoryDocument(byte[] bytes) { super(bytes); 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 06/50] 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; } From acb36d4a4db85d33f05975501d4f377c2d5416e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 21 Aug 2024 13:49:45 +0200 Subject: [PATCH 07/50] refactor: change place where we're asking for password --- .../digital/slovensko/autogram/core/Autogram.java | 13 ++----------- .../digital/slovensko/autogram/core/SigningJob.java | 11 +++++------ .../slovensko/autogram/server/SignEndpoint.java | 2 +- .../autogram/ui/BatchGuiFileResponder.java | 5 +---- .../digital/slovensko/autogram/ui/cli/CliApp.java | 11 +++-------- .../autogram/ui/gui/MainMenuController.java | 5 ++--- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index e033843a..8c0d6e73 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -72,17 +72,8 @@ public void handleProtectedPdfDocument(ProtectedDSSDocument document) { document.setPassword(password); } - public void handleProtectedPdfDocument(ProtectedDSSDocument document, Runnable callback) { - if (!PDFUtils.isPdfAndPasswordProtected(document)) { - callback.run(); - return; - } - - ui.onWorkThreadDo(() -> { - var password = ui.getDocumentPassword(); - document.setPassword(password); - callback.run(); - }); + public void wrapInWorkThread(Runnable callback) { + ui.onWorkThreadDo(callback); } public void startVisualization(SigningJob job) { diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 5eb235ca..62d48302 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -183,17 +183,16 @@ private static SigningJob build(ProtectedDSSDocument document, SigningParameters return new SigningJob(document, params, responder); } - public static SigningJob buildFromRequest(ProtectedDSSDocument document, SigningParameters params, Responder responder) { + public static SigningJob buildFromRequest(ProtectedDSSDocument document, Autogram autogram, SigningParameters params, Responder responder) { + autogram.handleProtectedPdfDocument(document); + return build(document, params, responder); } - public static SigningJob buildFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + public static SigningJob buildFromFile(File file, Autogram autogram, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var document = createDSSFileDocumentFromFile(file); - var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); - return build(document, parameters, responder); - } + autogram.handleProtectedPdfDocument(document); - public static SigningJob buildFromFileDocument(ProtectedFileDocument document, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); return build(document, parameters, responder); } diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index 29b6ff59..2b6e0b38 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -29,7 +29,7 @@ public void handle(HttpExchange exchange) throws IOException { var responder = body.getBatchId() == null ? new ServerResponder(exchange) : new ResponderInBatch(new ServerResponder(exchange), autogram.getBatch(body.getBatchId())); - var job = SigningJob.buildFromRequest(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); + var job = SigningJob.buildFromRequest(body.getDocument(), autogram, body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); if (body.getBatchId() != null) autogram.batchSign(job, body.getBatchId()); diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index bf2bbe05..e8bf0be5 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -64,10 +64,7 @@ public void onBatchStartSuccess(Batch batch) { onAllFilesSigned(batch); }), batch); - var document = SigningJob.createDSSFileDocumentFromFile(file); - autogram.handleProtectedPdfDocument(document); - - var job = SigningJob.buildFromFileDocument(document, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); + var job = SigningJob.buildFromFile(file, autogram, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); } catch (AutogramException e) { autogram.onSigningFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index dd07edaf..322b368e 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -30,14 +30,9 @@ public static void start(CommandLine cmd) { var source = settings.getSource(); var sourceList = source.isDirectory() ? source.listFiles() : new File[] { source }; var jobs = Arrays.stream(sourceList).filter(f -> f.isFile()) - .map(f -> { - var document = SigningJob.createDSSFileDocumentFromFile(f); - autogram.handleProtectedPdfDocument(document); - - return SigningJob.buildFromFileDocument(document, new SaveFileResponder(f, autogram, targetPathBuilder), - settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), - settings.getTspSource(), settings.isPlainXmlEnabled()); - }) + .map(f -> SigningJob.buildFromFile(f, autogram, new SaveFileResponder(f, autogram, targetPathBuilder), + settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), + settings.getTspSource(), settings.isPlainXmlEnabled())) .toList(); if (settings.isPdfaCompliance()) { jobs.forEach(job -> { diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index d04ccc8c..21eae618 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -110,10 +110,9 @@ private void signFiles(List list) { var filesList = getFilesList(list); if (filesList.size() == 1) { var file = filesList.get(0); - var document = SigningJob.createDSSFileDocumentFromFile(file); - autogram.handleProtectedPdfDocument(document, () -> { - var job = SigningJob.buildFromFileDocument(document, + autogram.wrapInWorkThread(() -> { + var job = SigningJob.buildFromFile(file, autogram, new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); From 11ef8b9c84f77ea932ec0159d6550c6d63f94cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Thu, 22 Aug 2024 21:40:05 +0200 Subject: [PATCH 08/50] fix: tests --- .../digital/slovensko/autogram/AutogramTests.java | 14 +++++++------- .../slovensko/autogram/SigningJobTests.java | 6 +++++- .../slovensko/autogram/TransformationTests.java | 10 ++++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index c30f0e21..e03eadc9 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -52,7 +52,7 @@ void testSignAsiceXadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -68,7 +68,7 @@ void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -91,7 +91,7 @@ void testSignAsiceCadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); } @ParameterizedTest @@ -105,7 +105,7 @@ void testSignPadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -136,7 +136,7 @@ void testSignBuildFromFileHappyScenario(InMemoryDocument document) throws IOExce var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromFile(file, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); + key -> autogram.sign(SigningJob.buildFromFile(file, autogram, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); verify(responder).onDocumentSigned(any()); } @@ -192,7 +192,7 @@ public AbstractKeyStoreTokenConnection createToken(PasswordManager pm, Signature } } - private static class FakeUI implements UI { + public static class FakeUI implements UI { @Override public void startSigning(SigningJob signingJob, Autogram autogram) { @@ -317,7 +317,7 @@ public void updateBatch() { } } - private class TestSettings extends UserSettings { + public static class TestSettings extends UserSettings { @Override public DriverDetector getDriverDetector() { List drivers = List.of(new FakeTokenDriver("fake")); diff --git a/src/test/java/digital/slovensko/autogram/SigningJobTests.java b/src/test/java/digital/slovensko/autogram/SigningJobTests.java index d2b6f463..9fe0fce8 100644 --- a/src/test/java/digital/slovensko/autogram/SigningJobTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningJobTests.java @@ -1,5 +1,6 @@ package digital.slovensko.autogram; +import digital.slovensko.autogram.core.Autogram; import digital.slovensko.autogram.core.SigningJob; import digital.slovensko.autogram.core.UserSettings; import digital.slovensko.autogram.core.visualization.DocumentVisualizationBuilder; @@ -50,9 +51,12 @@ void testEnd2EndHtmlTransformationEncoding() throws IOException, RequestValidati null, null, null); + var newUI = new AutogramTests.FakeUI(); + var settings = new AutogramTests.TestSettings(); + var autogram = new Autogram(newUI, settings); var signRequestBody = new SignRequestBody(new Document(content), ssParams, "application/xml;base64"); - var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); + var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), autogram, signRequestBody.getParameters(null, true), null); Visualization visualization = null; try { visualization = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index bb4f9452..0e2423b6 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -72,8 +72,11 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce document, null, true); + var newUI = new AutogramTests.FakeUI(); + var settings = new AutogramTests.TestSettings(); + var autogram = new Autogram(newUI, settings); - SigningJob job = SigningJob.buildFromRequest(document, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(document, autogram, params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -150,8 +153,11 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio document, null, true); + var newUI = new AutogramTests.FakeUI(); + var settings = new AutogramTests.TestSettings(); + var autogram = new Autogram(newUI, settings); - SigningJob job = SigningJob.buildFromRequest(document, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(document, autogram, params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { From 553dd41c0e0762e79b962c0f6fbed1a18b395d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 2 Sep 2024 11:47:03 +0200 Subject: [PATCH 09/50] refactor: autogram document, split passwords --- .../slovensko/autogram/core/Autogram.java | 18 +++-- .../autogram/core/SignatureValidator.java | 4 +- .../slovensko/autogram/core/SigningJob.java | 69 ++++++++++--------- .../autogram/core/SigningParameters.java | 10 +-- .../autogram/core/eforms/xdc/XDCBuilder.java | 8 +-- .../DocumentVisualizationBuilder.java | 31 ++++----- .../core/visualization/PDFVisualization.java | 9 ++- .../autogram/model/AutogramDocument.java | 38 ++++++++++ .../autogram/model/ProtectedDSSDocument.java | 12 ---- .../autogram/model/ProtectedFileDocument.java | 27 -------- .../model/ProtectedInMemoryDocument.java | 44 ------------ .../server/dto/ServerSigningParameters.java | 9 +-- .../autogram/server/dto/SignRequestBody.java | 11 +-- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../slovensko/autogram/ui/cli/CliUI.java | 2 +- .../slovensko/autogram/ui/gui/GUI.java | 4 +- .../autogram/util/AsicContainerUtils.java | 54 +-------------- .../slovensko/autogram/util/DSSUtils.java | 26 +++---- .../slovensko/autogram/util/PDFUtils.java | 15 ++-- .../slovensko/autogram/AutogramTests.java | 1 - .../autogram/SigningParametersTests.java | 3 - .../slovensko/autogram/TestMethodSources.java | 1 - .../autogram/TransformationTests.java | 2 - .../slovensko/autogram/XDCBuilderTests.java | 2 - .../autogram/core/AsicContainerTest.java | 2 - 25 files changed, 154 insertions(+), 250 deletions(-) create mode 100644 src/main/java/digital/slovensko/autogram/model/AutogramDocument.java delete mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java delete mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java delete mode 100644 src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 8c0d6e73..0f14c444 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -4,7 +4,7 @@ import digital.slovensko.autogram.core.visualization.DocumentVisualizationBuilder; import digital.slovensko.autogram.core.visualization.UnsupportedVisualization; import digital.slovensko.autogram.drivers.TokenDriver; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; @@ -57,19 +57,25 @@ public void checkPDFACompliance(SigningJob job) { return; ui.onWorkThreadDo(() -> { - var result = new PDFAStructureValidator().validate(job.getDocument()); + var result = new PDFAStructureValidator().validate(job.getDocument().getDocument()); if (!result.isCompliant()) { ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); } }); } - public void handleProtectedPdfDocument(ProtectedDSSDocument document) { - if (!PDFUtils.isPdfAndPasswordProtected(document)) + public void handleProtectedPdfDocument(AutogramDocument document) { + var protection = PDFUtils.determinePDFProtection(document.getDocument()); + if (protection == PDFUtils.PDFProtection.NONE) return; + System.out.println("PDF is protected with: " + protection); + var password = ui.getDocumentPassword(); - document.setPassword(password); + switch (protection) { + case OPEN_DOCUMENT_PASSWORD -> document.setOpenDocumentPassword(password); + case MASTER_PASSWORD -> document.setMasterPassword(password); + } } public void wrapInWorkThread(Runnable callback) { @@ -165,7 +171,7 @@ public void batchSign(SigningJob job, String batchId) { ui.onWorkThreadDo(() -> { try { signCommonAndThen(job, batch.getSigningKey(), (jobNew) -> { - Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getName()); + Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getDocument().getName()); }); } catch (AutogramException e) { job.onDocumentSignFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java b/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java index de5f14c1..b6ce90a0 100644 --- a/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java +++ b/src/main/java/digital/slovensko/autogram/core/SignatureValidator.java @@ -15,7 +15,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import eu.europa.esig.dss.simplereport.SimpleReport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -166,7 +166,7 @@ public static ValidationReports getSignatureCheckReport(SigningJob job) { return new ValidationReports(validator.validateDocument(), job); } - public static SimpleReport getSignedDocumentSimpleReport(ProtectedDSSDocument document) { + public static SimpleReport getSignedDocumentSimpleReport(AutogramDocument document) { var validator = createDocumentValidator(document); if (validator == null) return null; diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 62d48302..9b002c35 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -6,14 +6,14 @@ import digital.slovensko.autogram.core.eforms.xdc.XDCBuilder; import digital.slovensko.autogram.core.eforms.xdc.XDCValidator; import digital.slovensko.autogram.core.errors.AutogramException; -import digital.slovensko.autogram.model.ProtectedDSSDocument; -import digital.slovensko.autogram.model.ProtectedFileDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.util.Logging; import eu.europa.esig.dss.asic.cades.signature.ASiCWithCAdESService; import eu.europa.esig.dss.asic.xades.signature.ASiCWithXAdESService; import eu.europa.esig.dss.cades.signature.CAdESService; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.model.DSSDocument; +import eu.europa.esig.dss.model.FileDocument; import eu.europa.esig.dss.pades.signature.PAdESService; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; import eu.europa.esig.dss.validation.CommonCertificateVerifier; @@ -24,16 +24,16 @@ public class SigningJob { private final Responder responder; - private final ProtectedDSSDocument document; + private final AutogramDocument document; private final SigningParameters parameters; - private SigningJob(ProtectedDSSDocument document, SigningParameters parameters, Responder responder) { + private SigningJob(AutogramDocument document, SigningParameters parameters, Responder responder) { this.document = document; this.parameters = parameters; this.responder = responder; } - public ProtectedDSSDocument getDocument() { + public AutogramDocument getDocument() { return this.document; } @@ -46,7 +46,7 @@ public int getVisualizationWidth() { } public void signWithKeyAndRespond(SigningKey key) throws InterruptedException, AutogramException { - Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getName()); + Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getDocument().getName()); boolean isContainer = getParameters().getContainer() != null; var doc = switch (getParameters().getSignatureType()) { case XAdES -> isContainer ? signDocumentAsAsiCWithXAdeS(key) : signDocumentAsXAdeS(key); @@ -72,10 +72,10 @@ private DSSDocument signDocumentAsCAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { @@ -90,10 +90,10 @@ private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.XAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, getParameters().getDigestAlgorithm()); - return service.signDocument(getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsXAdeS(SigningKey key) { @@ -106,10 +106,10 @@ private DSSDocument signDocumentAsXAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { @@ -125,10 +125,10 @@ private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.CAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsPAdeS(SigningKey key) { @@ -140,21 +140,21 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { signatureParameters.setSigningCertificate(key.getCertificate()); signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - signatureParameters.setPasswordProtection(document.getPassword()); + signatureParameters.setPasswordProtection(document.getSigningPassword()); if (signatureParameters.getSignatureLevel().equals(SignatureLevel.PAdES_BASELINE_T)) { service.setTspSource(getParameters().getTspSource()); signatureParameters.setContentSize(9472*2); } - var dataToSign = service.getDataToSign(getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); } - public static ProtectedFileDocument createDSSFileDocumentFromFile(File file) { - var fileDocument = new ProtectedFileDocument(file); + public static AutogramDocument createDSSFileDocumentFromFile(File file) { + var fileDocument = new FileDocument(file); if (fileDocument.getName().endsWith(".xdcf")) fileDocument.setMimeType(XML_DATACONTAINER_WITH_CHARSET); @@ -165,12 +165,13 @@ else if (isXDC(fileDocument.getMimeType()) || isXML(fileDocument.getMimeType()) else if (isTxt(fileDocument.getMimeType())) fileDocument.setMimeType(AutogramMimeType.TEXT_WITH_CHARSET); - return fileDocument; + return new AutogramDocument(fileDocument); } - private static SigningJob build(ProtectedDSSDocument document, SigningParameters params, Responder responder) { + private static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { + DSSDocument document = autogramDocument.getDocument(); if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) - document = XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document)); + autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); if (isTxt(document.getMimeType())) document.setMimeType(AutogramMimeType.TEXT_WITH_CHARSET); @@ -180,10 +181,10 @@ private static SigningJob build(ProtectedDSSDocument document, SigningParameters document.setName(getXdcfFilename(document.getName())); } - return new SigningJob(document, params, responder); + return new SigningJob(autogramDocument, params, responder); } - public static SigningJob buildFromRequest(ProtectedDSSDocument document, Autogram autogram, SigningParameters params, Responder responder) { + public static SigningJob buildFromRequest(AutogramDocument document, Autogram autogram, SigningParameters params, Responder responder) { autogram.handleProtectedPdfDocument(document); return build(document, params, responder); @@ -197,34 +198,34 @@ public static SigningJob buildFromFile(File file, Autogram autogram, Responder r return build(document, parameters, responder); } - private static SigningParameters getParametersForFile(ProtectedFileDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + private static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: - return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document.getDocument(), checkPDFACompliance, isEn319132, tspSource); case XAdES: - return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES: - return SigningParameters.buildForASiCWithCAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } - if (isPDF(document.getMimeType())) switch (signatureType) { + if (isPDF(document.getDocument().getMimeType())) switch (signatureType) { case PAdES_BASELINE_B: - return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document.getDocument(), checkPDFACompliance, isEn319132, tspSource); case XAdES_BASELINE_B: - return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES_BASELINE_B: - return SigningParameters.buildForASiCWithCAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } - return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); } public boolean shouldCheckPDFCompliance() { - return parameters.getCheckPDFACompliance() && isPDF(document.getMimeType()) && !document.isProtected(); + return parameters.getCheckPDFACompliance() && isPDF(document.getDocument().getMimeType()) && document.getOpenDocumentPassword().length == 0; } } diff --git a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java index 406f70f4..549668b8 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java @@ -6,7 +6,7 @@ import digital.slovensko.autogram.core.errors.AutogramException; import digital.slovensko.autogram.core.errors.SigningParametersException; import digital.slovensko.autogram.core.errors.UnknownEformException; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.util.AsicContainerUtils; import digital.slovensko.autogram.core.eforms.EFormUtils; import digital.slovensko.autogram.core.eforms.xdc.XDCValidator; @@ -61,7 +61,7 @@ public static SigningParameters buildParameters( SignatureLevel level, DigestAlgorithm digestAlgorithm, ASiCContainerType container, SignaturePackaging packaging, boolean en319132, String infoCanonicalization, String propertiesCanonicalization, String keyInfoCanonicalization, EFormAttributes eFormAttributes, boolean autoLoadEform, String fsFormId, boolean checkPDFACompliance, - int preferredPreviewWidth, ProtectedDSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + int preferredPreviewWidth, DSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { if (level == null) throw new SigningParametersException("Nebol zadaný typ podpisu", "Typ/level podpisu je povinný atribút"); @@ -108,21 +108,21 @@ public static SigningParameters buildParameters( keyInfoCanonicalization, eFormAttributes, checkPDFACompliance, preferredPreviewWidth, tspSource); } - public static SigningParameters buildForPDF(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource) throws AutogramException { + public static SigningParameters buildForPDF(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.PAdES_BASELINE_B : SignatureLevel.PAdES_BASELINE_T, DigestAlgorithm.SHA256, null, null, signAsEn319132, null, null, null, null, false, null, checkPDFACompliance, 640, document, tspSource, true); } - public static SigningParameters buildForASiCWithXAdES(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + public static SigningParameters buildForASiCWithXAdES(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.XAdES_BASELINE_B : SignatureLevel.XAdES_BASELINE_T, DigestAlgorithm.SHA256, ASiCContainerType.ASiC_E, SignaturePackaging.ENVELOPING, signAsEn319132, null, null, null, null, true, EFormUtils.getFsFormIdFromFilename(document.getName()), checkPDFACompliance, 640, document, tspSource, plainXmlEnabled); } - public static SigningParameters buildForASiCWithCAdES(ProtectedDSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { + public static SigningParameters buildForASiCWithCAdES(DSSDocument document, boolean checkPDFACompliance, boolean signAsEn319132, TSPSource tspSource, boolean plainXmlEnabled) throws AutogramException { return buildParameters( (tspSource == null) ? SignatureLevel.CAdES_BASELINE_B : SignatureLevel.CAdES_BASELINE_T, DigestAlgorithm.SHA256, ASiCContainerType.ASiC_E, SignaturePackaging.ENVELOPING, signAsEn319132, null, null, null, null, true, diff --git a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java index 00e49765..f596b111 100644 --- a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java @@ -4,8 +4,6 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.XsltParams; import digital.slovensko.autogram.core.errors.TransformationException; -import digital.slovensko.autogram.model.ProtectedDSSDocument; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.util.XMLUtils; import static digital.slovensko.autogram.core.eforms.EFormUtils.*; @@ -14,6 +12,8 @@ import eu.europa.esig.dss.enumerations.DigestAlgorithm; +import eu.europa.esig.dss.model.DSSDocument; +import eu.europa.esig.dss.model.InMemoryDocument; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; @@ -32,7 +32,7 @@ public abstract class XDCBuilder { private static final Charset ENCODING = StandardCharsets.UTF_8; - public static ProtectedDSSDocument transform(SigningParameters params, String filename, Document document) { + public static DSSDocument transform(SigningParameters params, String filename, Document document) { var identifier = params.getIdentifier(); var lastSlashIndex = identifier.lastIndexOf("/"); if (lastSlashIndex == -1) @@ -58,7 +58,7 @@ public static ProtectedDSSDocument transform(SigningParameters params, String fi var content = getDocumentContent(transformedDocument).getBytes(ENCODING); - return new ProtectedInMemoryDocument(content, getXdcfFilename(filename), AutogramMimeType.XML_DATACONTAINER_WITH_CHARSET); + return new InMemoryDocument(content, getXdcfFilename(filename), AutogramMimeType.XML_DATACONTAINER_WITH_CHARSET); } catch (Exception e) { throw new TransformationException("Nastala chyba počas transformácie dokumentu", diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index e9493820..7da9a866 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -6,12 +6,11 @@ import javax.xml.parsers.ParserConfigurationException; import digital.slovensko.autogram.core.UserSettings; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import eu.europa.esig.dss.model.DSSDocument; import org.xml.sax.SAXException; -import digital.slovensko.autogram.core.AutogramMimeType; import static digital.slovensko.autogram.core.AutogramMimeType.*; import digital.slovensko.autogram.core.SigningJob; import digital.slovensko.autogram.core.SigningParameters; @@ -23,10 +22,10 @@ public class DocumentVisualizationBuilder { - private final ProtectedDSSDocument document; + private final AutogramDocument document; private final SigningParameters parameters; - private DocumentVisualizationBuilder(ProtectedDSSDocument document, SigningParameters parameters) { + private DocumentVisualizationBuilder(AutogramDocument document, SigningParameters parameters) { this.document = document; this.parameters = parameters; } @@ -43,9 +42,9 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti throws IOException, ParserConfigurationException, SAXException { var documentToDisplay = document; - if (isAsice(documentToDisplay.getMimeType())) { + if (isAsice(documentToDisplay.getDocument().getMimeType())) { try { - documentToDisplay = AsicContainerUtils.getOriginalDocument(document); + documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document.getDocument())); } catch (AutogramException e) { return new UnsupportedVisualization(job); } @@ -53,29 +52,29 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti var transformation = parameters.getTransformation(); - if (isDocumentSupportingTransformation(documentToDisplay) && isTranformationAvailable(transformation)) { + if (isDocumentSupportingTransformation(documentToDisplay.getDocument()) && isTranformationAvailable(transformation)) { var transformationOutputMimeType = parameters.getXsltDestinationType(); if (transformationOutputMimeType.equals("HTML")) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); if (transformationOutputMimeType.equals("TXT")) - return new PlainTextVisualization(EFormUtils.transform(documentToDisplay, transformation), job); + return new PlainTextVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); return new UnsupportedVisualization(job); } - if (documentToDisplay.getMimeType().equals(MimeTypeEnum.HTML)) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); + if (documentToDisplay.getDocument().getMimeType().equals(MimeTypeEnum.HTML)) + return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); - if (isTxt(documentToDisplay.getMimeType())) - return new PlainTextVisualization(new String(documentToDisplay.openStream().readAllBytes(), StandardCharsets.UTF_8), job); + if (isTxt(documentToDisplay.getDocument().getMimeType())) + return new PlainTextVisualization(new String(documentToDisplay.getDocument().openStream().readAllBytes(), StandardCharsets.UTF_8), job); - if (isPDF(documentToDisplay.getMimeType())) + if (isPDF(documentToDisplay.getDocument().getMimeType())) return new PDFVisualization(documentToDisplay, job, userSettings); - if (isImage(documentToDisplay.getMimeType())) - return new ImageVisualization(documentToDisplay, job); + if (isImage(documentToDisplay.getDocument().getMimeType())) + return new ImageVisualization(documentToDisplay.getDocument(), job); return new UnsupportedVisualization(job); } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java index f0d1c86d..727fa028 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java @@ -6,9 +6,8 @@ import digital.slovensko.autogram.core.SigningJob; import digital.slovensko.autogram.core.UserSettings; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.ui.Visualizer; -import eu.europa.esig.dss.model.DSSDocument; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.ImageType; import org.apache.pdfbox.rendering.PDFRenderer; @@ -16,18 +15,18 @@ import javax.imageio.ImageIO; public class PDFVisualization extends Visualization { - private final ProtectedDSSDocument document; + private final AutogramDocument document; private final UserSettings settings; - public PDFVisualization(ProtectedDSSDocument document, SigningJob job, UserSettings settings) { + public PDFVisualization(AutogramDocument document, SigningJob job, UserSettings settings) { super(job); this.document = document; this.settings = settings; } private ArrayList getPdfImages() throws IOException { - var pdfDocument = PDDocument.load(this.document.openStream(), new String(this.document.getPassword())); + var pdfDocument = PDDocument.load(this.document.getDocument().openStream(), new String(this.document.getOpenDocumentPassword())); var pdfRenderer = new PDFRenderer(pdfDocument); var divs = new ArrayList(); for (int page = 0; page < pdfDocument.getNumberOfPages(); ++page) { diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java new file mode 100644 index 00000000..f30f544c --- /dev/null +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -0,0 +1,38 @@ +package digital.slovensko.autogram.model; + +import eu.europa.esig.dss.model.DSSDocument; + +public class AutogramDocument { + private final DSSDocument document; + + private char[] openDocumentPassword = new char[0]; + private char[] masterPassword = new char[0]; + + public AutogramDocument(DSSDocument document) { + this.document = document; + } + + public char[] getOpenDocumentPassword() { + return openDocumentPassword; + } + + public void setOpenDocumentPassword(char[] openDocumentPassword) { + this.openDocumentPassword = openDocumentPassword; + } + + public char[] getMasterPassword() { + return masterPassword; + } + + public void setMasterPassword(char[] masterPassword) { + this.masterPassword = masterPassword; + } + + public char[] getSigningPassword() { + return openDocumentPassword.length > 0 ? openDocumentPassword : masterPassword; + } + + public DSSDocument getDocument() { + return document; + } +} diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java deleted file mode 100644 index b8f9a4bf..00000000 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedDSSDocument.java +++ /dev/null @@ -1,12 +0,0 @@ -package digital.slovensko.autogram.model; - -import eu.europa.esig.dss.model.DSSDocument; - -public interface ProtectedDSSDocument extends DSSDocument { - char[] getPassword(); - void setPassword(char[] password); - - default boolean isProtected() { - return getPassword().length != 0; - } -} diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java deleted file mode 100644 index 345f4d28..00000000 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedFileDocument.java +++ /dev/null @@ -1,27 +0,0 @@ -package digital.slovensko.autogram.model; - -import eu.europa.esig.dss.model.FileDocument; - -import java.io.File; - -public class ProtectedFileDocument extends FileDocument implements ProtectedDSSDocument { - private char[] password = new char[0]; - - public ProtectedFileDocument(String path) { - super(path); - } - - public ProtectedFileDocument(File file) { - super(file); - } - - @Override - public char[] getPassword() { - return this.password; - } - - @Override - public void setPassword(char[] password) { - this.password = password; - } -} diff --git a/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java b/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java deleted file mode 100644 index df4179f8..00000000 --- a/src/main/java/digital/slovensko/autogram/model/ProtectedInMemoryDocument.java +++ /dev/null @@ -1,44 +0,0 @@ -package digital.slovensko.autogram.model; - -import eu.europa.esig.dss.enumerations.MimeType; -import eu.europa.esig.dss.model.InMemoryDocument; - -import java.io.InputStream; - -public class ProtectedInMemoryDocument extends InMemoryDocument implements ProtectedDSSDocument { - private char[] password = new char[0]; - - public ProtectedInMemoryDocument(byte[] bytes) { - super(bytes); - } - - public ProtectedInMemoryDocument(byte[] bytes, String name) { - super(bytes, name); - } - - public ProtectedInMemoryDocument(byte[] bytes, String name, MimeType mimeType) { - super(bytes, name, mimeType); - } - - public ProtectedInMemoryDocument(InputStream inputStream) { - super(inputStream); - } - - public ProtectedInMemoryDocument(InputStream inputStream, String name) { - super(inputStream, name); - } - - public ProtectedInMemoryDocument(InputStream inputStream, String name, MimeType mimeType) { - super(inputStream, name, mimeType); - } - - @Override - public char[] getPassword() { - return this.password; - } - - @Override - public void setPassword(char[] password) { - this.password = password; - } -} diff --git a/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java b/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java index 4f0fba40..29362571 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/ServerSigningParameters.java @@ -7,7 +7,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Base64; -import java.util.regex.Pattern; import javax.xml.crypto.dsig.CanonicalizationMethod; @@ -15,8 +14,7 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.eforms.dto.XsltParams; -import digital.slovensko.autogram.model.ProtectedDSSDocument; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.server.errors.MalformedBodyException; import digital.slovensko.autogram.server.errors.RequestValidationException; import digital.slovensko.autogram.server.errors.UnsupportedSignatureLevelException; @@ -28,7 +26,6 @@ import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; import eu.europa.esig.dss.model.DSSDocument; -import eu.europa.esig.dss.model.InMemoryDocument; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; public class ServerSigningParameters { @@ -135,7 +132,7 @@ public ServerSigningParameters() { this.fsFormId = null; } - public SigningParameters getSigningParameters(boolean isBase64, ProtectedDSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) { + public SigningParameters getSigningParameters(boolean isBase64, DSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) { var xsltParams = new XsltParams( transformationIdentifier, transformationLanguage, @@ -253,7 +250,7 @@ private ASiCContainerType getContainer() { return container; } - public void resolveSigningLevel(ProtectedInMemoryDocument document) throws RequestValidationException { + public void resolveSigningLevel(AutogramDocument document) throws RequestValidationException { if (level != null) return; diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index f64550fe..540f9700 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -5,10 +5,11 @@ import digital.slovensko.autogram.core.errors.TransformationParsingErrorException; import digital.slovensko.autogram.core.SigningParameters; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.server.errors.MalformedBodyException; import digital.slovensko.autogram.server.errors.RequestValidationException; import eu.europa.esig.dss.enumerations.MimeType; +import eu.europa.esig.dss.model.InMemoryDocument; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; import static digital.slovensko.autogram.core.AutogramMimeType.*; @@ -52,11 +53,11 @@ private void resolveSigningLevel() throws RequestValidationException { parameters.resolveSigningLevel(getDocument()); } - public ProtectedInMemoryDocument getDocument() { + public AutogramDocument getDocument() { var content = decodeDocumentContent(document.getContent(), isBase64()); var filename = document.getFilename(); - return new ProtectedInMemoryDocument(content, filename, getMimetype()); + return new AutogramDocument(new InMemoryDocument(content, filename, getMimetype())); } public void validateSigningParameters() throws RequestValidationException, MalformedBodyException, @@ -64,11 +65,11 @@ public void validateSigningParameters() throws RequestValidationException, Malfo if (parameters == null) throw new RequestValidationException("Parameters are required", ""); - parameters.validate(getDocument().getMimeType()); + parameters.validate(getDocument().getDocument().getMimeType()); } public SigningParameters getParameters(TSPSource tspSource, boolean plainXmlEnabled) { - return parameters.getSigningParameters(isBase64(), getDocument(), tspSource, plainXmlEnabled); + return parameters.getSigningParameters(isBase64(), getDocument().getDocument(), tspSource, plainXmlEnabled); } public String getBatchId() { diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 322b368e..ec01f71d 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -36,7 +36,7 @@ public static void start(CommandLine cmd) { .toList(); if (settings.isPdfaCompliance()) { jobs.forEach(job -> { - System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getName()); + System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getDocument().getName()); autogram.checkPDFACompliance(job); }); } diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 98ad6985..376cbcc1 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -46,7 +46,7 @@ public void startSigning(SigningJob job, Autogram autogram) { } private void sign(SigningJob job, Autogram autogram) { - System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getName(), nJobsSigned++, + System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getDocument().getName(), nJobsSigned++, nJobsTotal)); autogram.sign(job, activeKey); } diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index 24a75817..17b0c5cf 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -341,8 +341,8 @@ public void onSignatureCheckCompleted(ValidationReports reports) { public void showVisualization(Visualization visualization, Autogram autogram) { var title = "Dokument"; - if (visualization.getJob().getDocument().getName() != null) - title = "Dokument " + visualization.getJob().getDocument().getName(); + if (visualization.getJob().getDocument().getDocument().getName() != null) + title = "Dokument " + visualization.getJob().getDocument().getDocument().getName(); var controller = new SigningDialogController(visualization, autogram, this, title, userSettings.isSignaturesValidity()); jobControllers.put(visualization.getJob(), controller); diff --git a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java index 91ed7569..53af9457 100644 --- a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java @@ -3,7 +3,7 @@ import digital.slovensko.autogram.core.AutogramMimeType; import digital.slovensko.autogram.core.errors.MultipleOriginalDocumentsFoundException; import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import eu.europa.esig.dss.asic.xades.ASiCWithXAdESContainerExtractor; import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeType; @@ -21,7 +21,7 @@ import static digital.slovensko.autogram.core.AutogramMimeType.isXML; public class AsicContainerUtils { - public static ProtectedDSSDocument getOriginalDocument(ProtectedDSSDocument asice) throws OriginalDocumentNotFoundException, + public static DSSDocument getOriginalDocument(DSSDocument asice) throws OriginalDocumentNotFoundException, MultipleOriginalDocumentsFoundException { SignedDocumentValidator documentValidator; try { @@ -51,55 +51,7 @@ public static ProtectedDSSDocument getOriginalDocument(ProtectedDSSDocument asic if (isXML(originalDocument.getMimeType()) || MimeTypeEnum.BINARY.equals(originalDocument.getMimeType())) setMimeTypeFromManifest(asice, originalDocument); - return new ProtectedDSSDocument() { - @Override - public char[] getPassword() { - return new char[0]; - } - - @Override - public void setPassword(char[] password) {} - - @Override - public InputStream openStream() { - return originalDocument.openStream(); - } - - @Override - public void writeTo(OutputStream outputStream) throws IOException { - originalDocument.writeTo(outputStream); - } - - @Override - public String getName() { - return originalDocument.getName(); - } - - @Override - public void setName(String s) { - originalDocument.setName(s); - } - - @Override - public MimeType getMimeType() { - return originalDocument.getMimeType(); - } - - @Override - public void setMimeType(MimeType mimeType) { - originalDocument.setMimeType(mimeType); - } - - @Override - public void save(String s) throws IOException { - originalDocument.save(s); - } - - @Override - public String getDigest(DigestAlgorithm digestAlgorithm) { - return originalDocument.getDigest(digestAlgorithm); - } - }; + return originalDocument; } private static void setMimeTypeFromManifest(DSSDocument asiceContainer, DSSDocument documentToDisplay) { diff --git a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java index 87954841..2a33947d 100644 --- a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java @@ -1,6 +1,6 @@ package digital.slovensko.autogram.util; -import digital.slovensko.autogram.model.ProtectedDSSDocument; +import digital.slovensko.autogram.model.AutogramDocument; import eu.europa.esig.dss.asic.cades.validation.ASiCContainerWithCAdESValidatorFactory; import eu.europa.esig.dss.asic.xades.validation.ASiCContainerWithXAdESValidatorFactory; import eu.europa.esig.dss.cades.validation.CMSDocumentValidatorFactory; @@ -38,24 +38,24 @@ public static String buildTooltipLabel(DSSPrivateKeyEntry key) { return out; } - public static SignedDocumentValidator createDocumentValidator(ProtectedDSSDocument document) { - if (new PDFDocumentValidatorFactory().isSupported(document)) { - var validator = new PDFDocumentValidator(document); - validator.setPasswordProtection(document.getPassword()); + public static SignedDocumentValidator createDocumentValidator(AutogramDocument document) { + if (new PDFDocumentValidatorFactory().isSupported(document.getDocument())) { + var validator = new PDFDocumentValidator(document.getDocument()); + validator.setPasswordProtection(document.getOpenDocumentPassword()); return validator; } - if (new XMLDocumentValidatorFactory().isSupported(document)) - return new XMLDocumentValidatorFactory().create(document); + if (new XMLDocumentValidatorFactory().isSupported(document.getDocument())) + return new XMLDocumentValidatorFactory().create(document.getDocument()); - if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document)) - return new ASiCContainerWithXAdESValidatorFactory().create(document); + if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document.getDocument())) + return new ASiCContainerWithXAdESValidatorFactory().create(document.getDocument()); - if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document)) - return new ASiCContainerWithCAdESValidatorFactory().create(document); + if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document.getDocument())) + return new ASiCContainerWithCAdESValidatorFactory().create(document.getDocument()); - if (new CMSDocumentValidatorFactory().isSupported(document)) - return new CMSDocumentValidatorFactory().create(document); + if (new CMSDocumentValidatorFactory().isSupported(document.getDocument())) + return new CMSDocumentValidatorFactory().create(document.getDocument()); return null; } diff --git a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java index 73ac97c3..53766b81 100644 --- a/src/main/java/digital/slovensko/autogram/util/PDFUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/PDFUtils.java @@ -8,9 +8,9 @@ import eu.europa.esig.dss.pdf.pdfbox.PdfBoxDocumentReader; public class PDFUtils { - public static boolean isPdfAndPasswordProtected(DSSDocument document) { + public static PDFProtection determinePDFProtection(DSSDocument document) { if (!document.getMimeType().equals(MimeTypeEnum.PDF)) - return false; + return PDFProtection.NONE; try { PdfBoxDocumentReader reader = new PdfBoxDocumentReader(document); @@ -18,15 +18,20 @@ public static boolean isPdfAndPasswordProtected(DSSDocument document) { // document is protected against modification without password if (!reader.canCreateSignatureField()) { reader.close(); - return true; + return PDFProtection.MASTER_PASSWORD; } reader.close(); } catch (InvalidPasswordException e) { - return true; + return PDFProtection.OPEN_DOCUMENT_PASSWORD; } catch (IOException e) {} - return false; + return PDFProtection.NONE; } + public enum PDFProtection { + NONE, + OPEN_DOCUMENT_PASSWORD, + MASTER_PASSWORD, + } } diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index e03eadc9..bdc34319 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -5,7 +5,6 @@ import digital.slovensko.autogram.core.errors.UnknownEformException; import digital.slovensko.autogram.core.visualization.Visualization; import digital.slovensko.autogram.drivers.TokenDriver; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.ui.gui.IgnorableException; diff --git a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java index 5794d2c2..43fbc237 100644 --- a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java @@ -3,13 +3,10 @@ import digital.slovensko.autogram.core.SigningParameters; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.errors.*; -import digital.slovensko.autogram.model.ProtectedDSSDocument; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.ASiCContainerType; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; -import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; import java.io.IOException; diff --git a/src/test/java/digital/slovensko/autogram/TestMethodSources.java b/src/test/java/digital/slovensko/autogram/TestMethodSources.java index ede59d16..95e0f63b 100644 --- a/src/test/java/digital/slovensko/autogram/TestMethodSources.java +++ b/src/test/java/digital/slovensko/autogram/TestMethodSources.java @@ -1,7 +1,6 @@ package digital.slovensko.autogram; import digital.slovensko.autogram.core.AutogramMimeType; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index 0e2423b6..293cc79f 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -10,7 +10,6 @@ import digital.slovensko.autogram.core.*; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -21,7 +20,6 @@ import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; -import eu.europa.esig.dss.model.InMemoryDocument; public class TransformationTests { diff --git a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java index fa51ae91..5266c90d 100644 --- a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java +++ b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java @@ -4,13 +4,11 @@ import digital.slovensko.autogram.core.eforms.EFormUtils; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; import digital.slovensko.autogram.core.eforms.xdc.XDCBuilder; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import eu.europa.esig.dss.enumerations.ASiCContainerType; import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; -import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Test; diff --git a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java index e000cb8e..cdf40d48 100644 --- a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java +++ b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java @@ -2,10 +2,8 @@ import digital.slovensko.autogram.core.errors.MultipleOriginalDocumentsFoundException; import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; -import digital.slovensko.autogram.model.ProtectedInMemoryDocument; import digital.slovensko.autogram.util.AsicContainerUtils; import eu.europa.esig.dss.enumerations.MimeTypeEnum; -import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; From 9d07e157ad131739b82d0287f2c11741bbe4ff19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 2 Sep 2024 11:50:14 +0200 Subject: [PATCH 10/50] add comment explaining PDF/A encryption --- src/main/java/digital/slovensko/autogram/core/SigningJob.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 9b002c35..cb2c1ee4 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -226,6 +226,7 @@ private static SigningParameters getParametersForFile(AutogramDocument document, } public boolean shouldCheckPDFCompliance() { + // PDF/A doesn't support encryption return parameters.getCheckPDFACompliance() && isPDF(document.getDocument().getMimeType()) && document.getOpenDocumentPassword().length == 0; } } From 83bd4df8ca6e784c9cb68253b847c696ed4ccbe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 2 Sep 2024 11:59:33 +0200 Subject: [PATCH 11/50] feat: show document name while unlocking --- .../java/digital/slovensko/autogram/core/Autogram.java | 4 +--- src/main/java/digital/slovensko/autogram/ui/UI.java | 3 ++- .../java/digital/slovensko/autogram/ui/cli/CliUI.java | 5 +++-- src/main/java/digital/slovensko/autogram/ui/gui/GUI.java | 5 +++-- .../slovensko/autogram/ui/gui/PasswordController.java | 9 +++++++++ .../slovensko/autogram/ui/gui/password-dialog.fxml | 1 + .../java/digital/slovensko/autogram/AutogramTests.java | 3 ++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 0f14c444..c53b6dc7 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -69,9 +69,7 @@ public void handleProtectedPdfDocument(AutogramDocument document) { if (protection == PDFUtils.PDFProtection.NONE) return; - System.out.println("PDF is protected with: " + protection); - - var password = ui.getDocumentPassword(); + var password = ui.getDocumentPassword(document.getDocument()); switch (protection) { case OPEN_DOCUMENT_PASSWORD -> document.setOpenDocumentPassword(password); case MASTER_PASSWORD -> document.setMasterPassword(password); diff --git a/src/main/java/digital/slovensko/autogram/ui/UI.java b/src/main/java/digital/slovensko/autogram/ui/UI.java index 5e6c8654..76124adc 100644 --- a/src/main/java/digital/slovensko/autogram/ui/UI.java +++ b/src/main/java/digital/slovensko/autogram/ui/UI.java @@ -5,6 +5,7 @@ import digital.slovensko.autogram.core.visualization.Visualization; import digital.slovensko.autogram.drivers.TokenDriver; import digital.slovensko.autogram.ui.gui.IgnorableException; +import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import java.io.File; @@ -55,7 +56,7 @@ public interface UI { void showError(AutogramException exception); - char[] getDocumentPassword(); + char[] getDocumentPassword(DSSDocument document); char[] getKeystorePassword(); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 376cbcc1..6eeb6fec 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -20,6 +20,7 @@ import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.ui.gui.IgnorableException; +import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; public class CliUI implements UI { @@ -268,8 +269,8 @@ public void showError(AutogramException e) { } @Override - public char[] getDocumentPassword() { - return System.console().readPassword("Enter document password (hidden): "); + public char[] getDocumentPassword(DSSDocument document) { + return System.console().readPassword("Enter document (" + document.getName() + ") password (hidden): "); } @Override diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index 17b0c5cf..2f61e18c 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -8,6 +8,7 @@ import digital.slovensko.autogram.core.*; import digital.slovensko.autogram.core.errors.*; +import eu.europa.esig.dss.model.DSSDocument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -199,9 +200,9 @@ public void showPkcsEidWindowsDllError(AutogramException e) { stage.show(); } - public char[] getDocumentPassword() { + public char[] getDocumentPassword(DSSDocument document) { var futurePassword = new FutureTask<>(() -> { - var controller = new PasswordController("Aké je heslo k dokumentu?", "Zadajte kód k dokumentu.", false, false); + var controller = new PasswordController("Aké je heslo k dokumentu?", "Odomikáte " + document.getName(), "Zadajte heslo k dokumentu.", false, false); var root = GUIUtils.loadFXML(controller, "password-dialog.fxml"); var stage = new Stage(); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java index e941c420..9db8050e 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java @@ -10,6 +10,7 @@ public class PasswordController { private final String questionText; + private final String descriptionText; private final String errorText; private final boolean isSigningStep; private final boolean allowEmpty; @@ -21,6 +22,8 @@ public class PasswordController { @FXML Text question; @FXML + Text description; + @FXML Text error; @FXML VBox formGroup; @@ -32,7 +35,12 @@ public class PasswordController { VBox mainBox; public PasswordController(String questionText, String blankPasswordErrorText, boolean isSigningStep, boolean allowEmpty) { + this(questionText, null, blankPasswordErrorText, false, false); + } + + public PasswordController(String questionText, String description, String blankPasswordErrorText, boolean isSigningStep, boolean allowEmpty) { this.questionText = questionText; + this.descriptionText = description; this.errorText = blankPasswordErrorText; this.isSigningStep = isSigningStep; this.allowEmpty = allowEmpty; @@ -40,6 +48,7 @@ public PasswordController(String questionText, String blankPasswordErrorText, bo public void initialize() { question.setText(questionText); + description.setText(descriptionText); error.setText(errorText); if(isSigningStep) { mainButton.setText("Podpísať"); diff --git a/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml b/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml index ff81e576..8af75559 100644 --- a/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml +++ b/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml @@ -13,6 +13,7 @@ + diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index bdc34319..d041428f 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -9,6 +9,7 @@ import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.ui.gui.IgnorableException; import eu.europa.esig.dss.enumerations.SignatureLevel; +import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; import eu.europa.esig.dss.token.AbstractKeyStoreTokenConnection; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; @@ -256,7 +257,7 @@ public void showError(AutogramException exception) { } @Override - public char[] getDocumentPassword() { + public char[] getDocumentPassword(DSSDocument document) { return null; } From e74a2832db8ac27cd2c221897a11d60142d28d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Tue, 3 Sep 2024 18:38:33 +0200 Subject: [PATCH 12/50] fix: tests --- .../slovensko/autogram/AutogramTests.java | 19 +- .../autogram/SigningParametersTests.java | 37 ++-- .../slovensko/autogram/TestMethodSources.java | 166 +++++++++--------- .../autogram/TransformationTests.java | 10 +- .../slovensko/autogram/XDCBuilderTests.java | 3 +- .../autogram/core/AsicContainerTest.java | 19 +- 6 files changed, 130 insertions(+), 124 deletions(-) diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index d041428f..564ed87e 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -5,6 +5,7 @@ import digital.slovensko.autogram.core.errors.UnknownEformException; import digital.slovensko.autogram.core.visualization.Visualization; import digital.slovensko.autogram.drivers.TokenDriver; +import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.ui.gui.IgnorableException; @@ -43,7 +44,7 @@ class AutogramTests { "digital.slovensko.autogram.TestMethodSources#validOtherDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#validXadesDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#fsDPFOProvider" }) - void testSignAsiceXadesHappyScenario(ProtectedInMemoryDocument document) { + void testSignAsiceXadesHappyScenario(DSSDocument document) { var settings = new TestSettings(); var newUI = new FakeUI(); var autogram = new Autogram(newUI, settings); @@ -52,14 +53,14 @@ void testSignAsiceXadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#nonEformXmlProvider"}) - void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) { + void testSignNonEformHappyScenario(DSSDocument document) { var settings = new TestSettings(); var newUI = new FakeUI(); var autogram = new Autogram(newUI, settings); @@ -68,21 +69,21 @@ void testSignNonEformHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#nonEformXmlProvider"}) - void testSignNonEformNegativeScenario(ProtectedInMemoryDocument document) { + void testSignNonEformNegativeScenario(DSSDocument document) { Assertions.assertThrows(UnknownEformException.class, () -> SigningParameters.buildForASiCWithXAdES(document, false, false, null, false)); } @ParameterizedTest @MethodSource({"digital.slovensko.autogram.TestMethodSources#validOtherDocumentsProvider", "digital.slovensko.autogram.TestMethodSources#validCadesDocumentsProvider"}) - void testSignAsiceCadesHappyScenario(ProtectedInMemoryDocument document) { + void testSignAsiceCadesHappyScenario(DSSDocument document) { var newUI = new FakeUI(); var settings = new TestSettings(); var autogram = new Autogram(newUI, settings); @@ -91,12 +92,12 @@ void testSignAsiceCadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); } @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#pdfForPadesProvider" }) - void testSignPadesHappyScenario(ProtectedInMemoryDocument document) { + void testSignPadesHappyScenario(DSSDocument document) { var newUI = new FakeUI(); var settings = new TestSettings(); var autogram = new Autogram(newUI, settings); @@ -105,7 +106,7 @@ void testSignPadesHappyScenario(ProtectedInMemoryDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(document, autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); verify(responder).onDocumentSigned(any()); } diff --git a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java index 43fbc237..39c1b2e4 100644 --- a/src/test/java/digital/slovensko/autogram/SigningParametersTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningParametersTests.java @@ -7,6 +7,7 @@ import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; +import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; import java.io.IOException; @@ -55,7 +56,7 @@ void setDefaultValues() throws IOException { @Test void testThrowsAutogramExceptionWhenNoMimeType() throws IOException { - var document = new ProtectedInMemoryDocument(generalAgendaXml); + var document = new InMemoryDocument(generalAgendaXml); Assertions.assertThrows(SigningParametersException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping, @@ -71,7 +72,7 @@ void testThrowsAutogramExceptionWhenNoDocument() { @Test void testThrowsXMLValidationFailedWhenNoXML() { - var document = new ProtectedInMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML); + var document = new InMemoryDocument("not xml".getBytes(), "doc.xml", MimeTypeEnum.XML); Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, enveloping, @@ -90,7 +91,7 @@ void testThrowsAutogramExceptionWhenNoSignatureLevel() { @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(ProtectedDSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(DSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, @@ -99,7 +100,7 @@ void testDoesNotThrowWithMinimalParametersForXadesNoConatiner(ProtectedDSSDocume @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesInAsice(ProtectedDSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesInAsice(DSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, null, null, null, null, @@ -108,7 +109,7 @@ void testDoesNotThrowWithMinimalParametersForXadesInAsice(ProtectedDSSDocument d @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(ProtectedDSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceWith(DSSDocument document) { Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -117,7 +118,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(ProtectedDSSDocument document) { + void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(DSSDocument document) { // TODO: mock eform S3 resource Assertions.assertDoesNotThrow( () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -127,7 +128,7 @@ void testDoesNotThrowWithMinimalParametersForXadesXdcInAsiceAutoLoadEform(Protec @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider") - void testThrowsAutogramExceptionWithInvalidXml(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXml(DSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -136,7 +137,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(DSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -146,7 +147,7 @@ void testThrowsAutogramExceptionWithInvalidXmlWithAutoLoadEform(ProtectedDSSDocu @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#nonEFormXmlProvider") - void testThrowsUnknownEformExceptionWithInvalidXmlEform(ProtectedDSSDocument document) { + void testThrowsUnknownEformExceptionWithInvalidXmlEform(DSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(UnknownEformException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -157,7 +158,7 @@ void testThrowsUnknownEformExceptionWithInvalidXmlEform(ProtectedDSSDocument doc @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlSchema(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlSchema(DSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -166,7 +167,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#xsdSchemaFailedValidationXmlProvider") - void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(DSSDocument document) { // TODO: mock eform S3 resource Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, @@ -176,7 +177,7 @@ void testThrowsAutogramExceptionWithInvalidXmlSchemaWithAutoLoadEform(ProtectedD @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#generalAgendaProvider") - void testThrowsAutogramExceptionWithUnknownEformXml(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithUnknownEformXml(DSSDocument document) { Assertions.assertThrows(EFormException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, null, null, null, new EFormAttributes(null, null, null, @@ -186,7 +187,7 @@ false, null, null, null, new EFormAttributes(null, null, null, @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#unknownEfomXmlProvider") - void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(DSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, true, @@ -195,7 +196,7 @@ void testThrowsAutogramExceptionWithUnknownEformXmlWithAutoLoadEform(ProtectedDS @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider") - void testThrowsAutogramExceptionWithMismatchedDigestsXml(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithMismatchedDigestsXml(DSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, asice, null, false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTransformation, xsdSchema, @@ -205,7 +206,7 @@ false, inclusive, inclusive, inclusive, new EFormAttributes(identifier, xsltTran @ParameterizedTest @MethodSource({ "digital.slovensko.autogram.TestMethodSources#mismatchedDigestsXmlProvider", "digital.slovensko.autogram.TestMethodSources#mismatchedDigestsFSXmlProvider"}) - void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(ProtectedDSSDocument document) { + void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(DSSDocument document) { Assertions.assertThrows(XMLValidationException.class, () -> SigningParameters.buildParameters(SignatureLevel.XAdES_BASELINE_B, null, null, null, false, null, null, null, null, true, @@ -214,14 +215,14 @@ void testThrowsAutogramExceptionWithMismatchedDigestsXmlWithAutoLoadEform(Protec @ParameterizedTest @MethodSource("digital.slovensko.autogram.TestMethodSources#invalidAsiceProvider") - void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(ProtectedDSSDocument document) throws IOException { + void testThrowsOriginalDocumentNotFoundWithAsiceWithoutSignature(DSSDocument document) throws IOException { Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> SigningParameters.buildForASiCWithXAdES(document, false, false, tspSource, true)); } @Test void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException { - var document = new ProtectedInMemoryDocument( + var document = new InMemoryDocument( this.getClass().getResourceAsStream("empty_xml.asice").readAllBytes(), "empty_xml.asice"); @@ -232,7 +233,7 @@ void testThrowsExceptionWithAsiceWithEmptyXml() throws IOException { @Test void testInvalidTransformation() throws IOException { var generalAgendaXml = this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(); - var document = new ProtectedInMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML); + var document = new InMemoryDocument(generalAgendaXml, "doc.xml", MimeTypeEnum.XML); var transformation = "invalid transformation"; Assertions.assertThrows(TransformationParsingErrorException.class, diff --git a/src/test/java/digital/slovensko/autogram/TestMethodSources.java b/src/test/java/digital/slovensko/autogram/TestMethodSources.java index 95e0f63b..5dec48f3 100644 --- a/src/test/java/digital/slovensko/autogram/TestMethodSources.java +++ b/src/test/java/digital/slovensko/autogram/TestMethodSources.java @@ -22,15 +22,15 @@ public static Stream generalAgendaProvider() throws IOException { var indentedAsice = cls.getResourceAsStream("general_agenda_indented.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(inlineXml, "generalAgendaInlineXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(inlineXmlHeader, "generalAgendaInlineXmlHeader.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(indentedXml, "generalAgendaIndentedXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(indentedXmlHeader, "generalAgendaIndentedXmlHeader.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(inlineXdc, "generalAgendaInlineXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(indentedXdc, "generalAgendaIndentedXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(inlineAsice, "generalAgendaInlineAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(indentedAsice, "generalAgendaIndentedAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(inlineXml, "generalAgendaInlineXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(inlineXmlHeader, "generalAgendaInlineXmlHeader.xml", MimeTypeEnum.XML), + new InMemoryDocument(indentedXml, "generalAgendaIndentedXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(indentedXmlHeader, "generalAgendaIndentedXmlHeader.xml", MimeTypeEnum.XML), + new InMemoryDocument(inlineXdc, "generalAgendaInlineXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(indentedXdc, "generalAgendaIndentedXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(inlineAsice, "generalAgendaInlineAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(indentedAsice, "generalAgendaIndentedAsice.asice", MimeTypeEnum.ASICE) ); } @@ -38,9 +38,9 @@ public static Stream unsetXdcfMimetypeProvider() throws IOException var inlineXdcf = cls.getResourceAsStream("general_agenda.xdcf").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfBinary.xdcf", MimeTypeEnum.BINARY), - new ProtectedInMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfXml.xdcf", MimeTypeEnum.XML) + new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcf.xdcf", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfBinary.xdcf", MimeTypeEnum.BINARY), + new InMemoryDocument(inlineXdcf, "generalAgendaInlineXdcfXml.xdcf", MimeTypeEnum.XML) ); } @@ -56,16 +56,16 @@ public static Stream fsDPFOProvider() throws IOException { var timestampedAsice = cls.getResourceAsStream("fs_forms/signed_indented_ts.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(inlineXml, "dic2120515056_fs792_772.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(inlineXmlHeader, "d_fs792_772_header.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(indentedXml, "d_fs792_772_indented.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(indentedXmlHeader, "d_fs792_772_header_indented.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(inlineXdc, "d_fs792_772_xdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(indentedXdc, "d_fs792_772_xdc_indented.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(inlineAsice, "signed.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(inlineAsice, "d_fs792_772_signed.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(indentedAsice, "signed_indented.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(timestampedAsice, "signed_indented_ts.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(inlineXml, "dic2120515056_fs792_772.xml", MimeTypeEnum.XML), + new InMemoryDocument(inlineXmlHeader, "d_fs792_772_header.xml", MimeTypeEnum.XML), + new InMemoryDocument(indentedXml, "d_fs792_772_indented.xml", MimeTypeEnum.XML), + new InMemoryDocument(indentedXmlHeader, "d_fs792_772_header_indented.xml", MimeTypeEnum.XML), + new InMemoryDocument(inlineXdc, "d_fs792_772_xdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(indentedXdc, "d_fs792_772_xdc_indented.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(inlineAsice, "signed.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(inlineAsice, "d_fs792_772_signed.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(indentedAsice, "signed_indented.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(timestampedAsice, "signed_indented_ts.asice", MimeTypeEnum.ASICE) ); } @@ -89,12 +89,12 @@ public static Stream invalidXmlProvider() throws IOException { return Stream.of( - new ProtectedInMemoryDocument(notAnXml, "notAnXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(invalidXml, "invalidXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(invalidXmlHeader, "invalidXmlHeader.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(invalidXdc, "invalidXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(twoRootElements, "twoRootElements.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(twoRootElementsHeader, "twoRootElementsHeader.xml", MimeTypeEnum.XML) + new InMemoryDocument(notAnXml, "notAnXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(invalidXml, "invalidXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(invalidXmlHeader, "invalidXmlHeader.xml", MimeTypeEnum.XML), + new InMemoryDocument(invalidXdc, "invalidXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(twoRootElements, "twoRootElements.xml", MimeTypeEnum.XML), + new InMemoryDocument(twoRootElementsHeader, "twoRootElementsHeader.xml", MimeTypeEnum.XML) ); } @@ -102,7 +102,7 @@ public static Stream nonEFormXmlProvider() throws IOException { var wrongXdcSchemaXml = cls.getResourceAsStream("wrong_schema_xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(wrongXdcSchemaXml, "wrongXdcSchemaXml.xml", AutogramMimeType.XML_DATACONTAINER) + new InMemoryDocument(wrongXdcSchemaXml, "wrongXdcSchemaXml.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -111,8 +111,8 @@ public static Stream xsdSchemaFailedValidationXmlProvider() throws var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(wrongSchemaGAXml, "wrongSchemaGAXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) + new InMemoryDocument(wrongSchemaGAXml, "wrongSchemaGAXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -123,10 +123,10 @@ public static Stream mismatchedDigestsXmlProvider() throws IOExcept var mismatchedXsltGAXdcAsice = cls.getResourceAsStream("mismatched_xslt_ga_xdc.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(mismatchedXsdGAXdcXml, "mismatchedXsdGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsltGAXdcXml, "mismatchedXsltGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsdGAXdcAsice, "mismatchedXsdGAXdcAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(mismatchedXsltGAXdcAsice, "mismatchedXsltGAXdcAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(mismatchedXsdGAXdcXml, "mismatchedXsdGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsltGAXdcXml, "mismatchedXsltGAXdcXml.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsdGAXdcAsice, "mismatchedXsdGAXdcAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(mismatchedXsltGAXdcAsice, "mismatchedXsltGAXdcAsice.asice", MimeTypeEnum.ASICE) ); } @@ -137,10 +137,10 @@ public static Stream mismatchedDigestsFSXmlProvider() throws IOExce var mismatchedXsltFSXsltXdcAsice = cls.getResourceAsStream("fs_forms/signed_xdc_xslt_digest.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(mismatchedXsltFSXdcXml, "d_fs792_772_xdc_xsd_digest.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsltFSXsltXdcXml, "d_fs792_772_xdc_xslt_digest.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsltFSXdcAsice, "signed_xdc_xsd_digest.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(mismatchedXsltFSXsltXdcAsice, "signed_xdc_xslt_digest.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(mismatchedXsltFSXdcXml, "d_fs792_772_xdc_xsd_digest.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsltFSXsltXdcXml, "d_fs792_772_xdc_xslt_digest.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsltFSXdcAsice, "signed_xdc_xsd_digest.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(mismatchedXsltFSXsltXdcAsice, "signed_xdc_xslt_digest.asice", MimeTypeEnum.ASICE) ); } @@ -150,9 +150,9 @@ public static Stream unknownEfomXmlProvider() throws IOException { var unknownEfomAsice = cls.getResourceAsStream("unknown_eform.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(unknownEfomXml, "unknownEfomXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(unknownEfomAsice, "unknownEfomAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(unknownEfomXml, "unknownEfomXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(unknownEfomAsice, "unknownEfomAsice.asice", MimeTypeEnum.ASICE) ); } @@ -166,9 +166,9 @@ public static Stream invalidAsiceProvider() throws IOException { // var noMimetypeAsice = cls.getResourceAsStream("no_mimetype.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(noSignaturesAsice, "noSignaturesAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(invalidAsice, "invalidAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(noMetaInfAsice, "noMetaInfAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(noSignaturesAsice, "noSignaturesAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(invalidAsice, "invalidAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(noMetaInfAsice, "noMetaInfAsice.asice", MimeTypeEnum.ASICE) ); } @@ -180,11 +180,11 @@ public static Stream validOtherDocumentsProvider() throws IOEx var sampleDocx = cls.getResourceAsStream("sample.docx").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(sampleTxt, "sample.txt", MimeTypeEnum.TEXT), - new ProtectedInMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), - new ProtectedInMemoryDocument(samplePng, "sample.png", MimeTypeEnum.PNG), - new ProtectedInMemoryDocument(sampleIco, "sample.ico", new AutogramMimeType("image/x-icon", "ico")), - new ProtectedInMemoryDocument(sampleDocx, "sample.docx", new AutogramMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx")) + new InMemoryDocument(sampleTxt, "sample.txt", MimeTypeEnum.TEXT), + new InMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), + new InMemoryDocument(samplePng, "sample.png", MimeTypeEnum.PNG), + new InMemoryDocument(sampleIco, "sample.ico", new AutogramMimeType("image/x-icon", "ico")), + new InMemoryDocument(sampleDocx, "sample.docx", new AutogramMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx")) ); } @@ -192,7 +192,7 @@ public static Stream nonEformXmlProvider() throws IOException var nonEformXml = cls.getResourceAsStream("non_eform.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML) + new InMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML) ); } @@ -201,8 +201,8 @@ public static Stream pdfForPadesProvider() throws IOException var samplePdfSigned = cls.getResourceAsStream("sample_signed.pdf").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), - new ProtectedInMemoryDocument(samplePdfSigned, "sample_signed.pdf", MimeTypeEnum.PDF) + new InMemoryDocument(samplePdf, "sample.pdf", MimeTypeEnum.PDF), + new InMemoryDocument(samplePdfSigned, "sample_signed.pdf", MimeTypeEnum.PDF) ); } @@ -215,12 +215,12 @@ public static Stream validXadesDocumentsProvider() throws IOEx var sampleDocxXadesAsice = cls.getResourceAsStream("sample_docx_xades.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(generalAgendaAsice, "generalAgendaAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(sampleTxtXadesAsice, "sampleTxtXadesAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(samplePdfXadesAsice, "samplePdfXadesAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(samplePngXadesAsice, "samplePngXadesAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(sampleIcoXadesAsice, "sampleIcoXadesAsice.asice", MimeTypeEnum.ASICE), - new ProtectedInMemoryDocument(sampleDocxXadesAsice, "sampleDocxXadesAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(generalAgendaAsice, "generalAgendaAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(sampleTxtXadesAsice, "sampleTxtXadesAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(samplePdfXadesAsice, "samplePdfXadesAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(samplePngXadesAsice, "samplePngXadesAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(sampleIcoXadesAsice, "sampleIcoXadesAsice.asice", MimeTypeEnum.ASICE), + new InMemoryDocument(sampleDocxXadesAsice, "sampleDocxXadesAsice.asice", MimeTypeEnum.ASICE) ); } @@ -233,12 +233,12 @@ public static Stream xdcDocumentsProvider() throws IOException var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), - new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) + new InMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", AutogramMimeType.XML_DATACONTAINER), + new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", AutogramMimeType.XML_DATACONTAINER) ); } @@ -251,12 +251,12 @@ public static Stream xdcDocumentsWithXmlMimetypeProvider() thr var wrongSchemaGAXdc = cls.getResourceAsStream("wrong_schema_ga_xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", MimeTypeEnum.XML) + new InMemoryDocument(generalAgendaXdcIndented, "generalAgendaXdcIndented.xml", MimeTypeEnum.XML), + new InMemoryDocument(generalAgendaXdc, "generalAgendaXdc.xml", MimeTypeEnum.XML), + new InMemoryDocument(mismatchedXsdGAXdc, "mismatchedXsdGAXdc.xml", MimeTypeEnum.XML), + new InMemoryDocument(mismatchedXsltGAXdc, "mismatchedXsltGAXdc.xml", MimeTypeEnum.XML), + new InMemoryDocument(unknownEfomXdc, "unknownEfomXdc.xml", MimeTypeEnum.XML), + new InMemoryDocument(wrongSchemaGAXdc, "wrongSchemaGAXdc.xml", MimeTypeEnum.XML) ); } @@ -269,12 +269,12 @@ public static Stream nonXdcXmlDocumentsProvider() throws IOExc var wrongSchemaXdcXml = cls.getResourceAsStream("wrong_schema_xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(documentContentNoUsedXSDReference, "documentContentNoUsedXSDReference.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(documentContentUsedXSDReferenceNoAttributes, "documentContentUsedXSDReferenceNoAttributes.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(documentContentUsedXSDReferenceNoDigestValue, "documentContentUsedXSDReferenceNoDigestValue.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(emptyXml, "emptyXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(wrongSchemaXdcXml, "wrongSchemaXdcXml.xml", MimeTypeEnum.XML) + new InMemoryDocument(documentContentNoUsedXSDReference, "documentContentNoUsedXSDReference.xml", MimeTypeEnum.XML), + new InMemoryDocument(documentContentUsedXSDReferenceNoAttributes, "documentContentUsedXSDReferenceNoAttributes.xml", MimeTypeEnum.XML), + new InMemoryDocument(documentContentUsedXSDReferenceNoDigestValue, "documentContentUsedXSDReferenceNoDigestValue.xml", MimeTypeEnum.XML), + new InMemoryDocument(emptyXml, "emptyXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(nonEformXml, "nonEformXml.xml", MimeTypeEnum.XML), + new InMemoryDocument(wrongSchemaXdcXml, "wrongSchemaXdcXml.xml", MimeTypeEnum.XML) ); } @@ -282,7 +282,7 @@ public static Stream validCadesDocumentsProvider() throws IOEx var samplePdfCadesAsice = cls.getResourceAsStream("sample_pdf_cades.asice").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(samplePdfCadesAsice, "samplePdfCadesAsice.asice", MimeTypeEnum.ASICE) + new InMemoryDocument(samplePdfCadesAsice, "samplePdfCadesAsice.asice", MimeTypeEnum.ASICE) ); } @@ -294,11 +294,11 @@ public static Stream orsrDocumentsProvider() throws IOExcepti var fupsXdcNoNamespaceXml = cls.getResourceAsStream("FUPS_wo_namespace.xdc.xml").readAllBytes(); return Stream.of( - new ProtectedInMemoryDocument(fupaXml, "FUPA.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(fupsXml, "FUPS.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(fuzsNewXml, "fuzs_new.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(fupsXdcXml, "FUPS.xdc.xml", MimeTypeEnum.XML), - new ProtectedInMemoryDocument(fupsXdcNoNamespaceXml, "FUPS_wo_namespace.xdc.xml", MimeTypeEnum.XML) + new InMemoryDocument(fupaXml, "FUPA.xml", MimeTypeEnum.XML), + new InMemoryDocument(fupsXml, "FUPS.xml", MimeTypeEnum.XML), + new InMemoryDocument(fuzsNewXml, "fuzs_new.xml", MimeTypeEnum.XML), + new InMemoryDocument(fupsXdcXml, "FUPS.xdc.xml", MimeTypeEnum.XML), + new InMemoryDocument(fupsXdcNoNamespaceXml, "FUPS_wo_namespace.xdc.xml", MimeTypeEnum.XML) ); } } diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index 293cc79f..f067ccf2 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -10,6 +10,8 @@ import digital.slovensko.autogram.core.*; import digital.slovensko.autogram.core.eforms.dto.EFormAttributes; +import digital.slovensko.autogram.model.AutogramDocument; +import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -41,7 +43,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce "crystal_test_data/PovolenieZdravotnictvo.html.xslt") .readAllBytes()); - var document = new ProtectedInMemoryDocument( + var document = new InMemoryDocument( this.getClass().getResourceAsStream( "crystal_test_data/rozhodnutie_X4564-2.xml"), "rozhodnutie_X4564-2.xml"); @@ -74,7 +76,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce var settings = new AutogramTests.TestSettings(); var autogram = new Autogram(newUI, settings); - SigningJob job = SigningJob.buildFromRequest(document, autogram, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), autogram, params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -122,7 +124,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio "crystal_test_data/PovolenieZdravotnictvo.sb.xslt") .readAllBytes()); - var document = new ProtectedInMemoryDocument( + var document = new InMemoryDocument( this.getClass().getResourceAsStream( "crystal_test_data/rozhodnutie_X4564-2.xml"), "rozhodnutie_X4564-2.xml"); @@ -155,7 +157,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio var settings = new AutogramTests.TestSettings(); var autogram = new Autogram(newUI, settings); - SigningJob job = SigningJob.buildFromRequest(document, autogram, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), autogram, params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { diff --git a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java index 5266c90d..0f1f9c63 100644 --- a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java +++ b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java @@ -10,6 +10,7 @@ import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; +import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Test; import javax.xml.crypto.dsig.CanonicalizationMethod; @@ -24,7 +25,7 @@ void testTransformsPlainHtmlWithoutAddingNamespaces() throws IOException { var transformation = new String(this.getClass().getResourceAsStream("general_agenda.xslt").readAllBytes(), StandardCharsets.UTF_8); var xsdSchema = new String(this.getClass().getResourceAsStream("general_agenda.xsd").readAllBytes(), StandardCharsets.UTF_8); - var document = new ProtectedInMemoryDocument(this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(), "general_agenda.xml", MimeTypeEnum.XML); + var document = new InMemoryDocument(this.getClass().getResourceAsStream("general_agenda.xml").readAllBytes(), "general_agenda.xml", MimeTypeEnum.XML); var params = SigningParameters.buildParameters( SignatureLevel.XAdES_BASELINE_B, diff --git a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java index cdf40d48..eb96b2b7 100644 --- a/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java +++ b/src/test/java/digital/slovensko/autogram/core/AsicContainerTest.java @@ -4,6 +4,7 @@ import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; import digital.slovensko.autogram.util.AsicContainerUtils; import eu.europa.esig.dss.enumerations.MimeTypeEnum; +import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -14,10 +15,10 @@ class AsicContainerTest { @Test void testGetOriginalFileXdc() { var asiceWithXdcOriginalFileContent = "UEsDBAoAAAgAALZj+laKIflFHwAAAB8AAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi92bmQuZXRzaS5hc2ljLWUremlwUEsDBBQACAgIALZj+lYAAAAAAAAAAAAAAAAMAAAAZG9jdW1lbnQueG1sxZTbctowEIZfRaPbDJIVSAoUk+GUtE1oKYEELhVrMQpGciVxSN+ml32OvFhlHCB0aGY6veildn+t/v127drFep6gJRgrtQoxIwFGoCItpIpDPBxcFsr4ol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AAE1FVEEtSU5GL21hbmlmZXN0LnhtbI2QwU4DMQxEf2Xla5UscEJR0974AvgAK/EWi8SJNt4V5etJkVoWcenNI83MG3l//MxpWGluXMTDo32AgSSUyHLy8Pb6Yp7heNhnFJ6oqbseQ49Ju0kPyyyuYOPmBDM1p8GVShJLWDKJur9+9wO6qQ3/CTa0iROZnp7Pv95pSclU1HcP46YiU2Q0eq7kAWtNHFB75bhKtKSNbd8WDO2+uMJ4P+K63/b9d9JOZbXt4xKIqBiKKLLQvLs0dPL475eHb1BLBwi5PYSYwAAAAIUBAABQSwECCgAKAAAIAAC2Y/pWiiH5RR8AAAAfAAAACAAAAAAAAAAAAAAAAAAAAAAAbWltZXR5cGVQSwECFAAUAAgICAC2Y/pWmbqZaCoCAADbBAAADAAAAAAAAAAAAAAAAABFAAAAZG9jdW1lbnQueG1sUEsBAhQAFAAICAgAtmP6VmrQBIE/BwAAcQ4AABoAAAAAAAAAAAAAAAAAqQIAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAICAgAtmP6Vrk9hJjAAAAAhQEAABUAAAAAAAAAAAAAAAAAMAoAAE1FVEEtSU5GL21hbmlmZXN0LnhtbFBLBQYAAAAABAAEAPsAAAAzCwAAAAA="; - var asiceWithXdcOriginalFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceWithXdcOriginalFileContent), null, MimeTypeEnum.ASICE); + var asiceWithXdcOriginalFile = new InMemoryDocument(Base64.getDecoder().decode(asiceWithXdcOriginalFileContent), null, MimeTypeEnum.ASICE); var actualOriginalXdcFileContent = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48eGRjOlhNTERhdGFDb250YWluZXIgeG1sbnM6eGRjPSJodHRwOi8vZGF0YS5nb3Yuc2svZGVmL2NvbnRhaW5lci94bWxkYXRhY29udGFpbmVyK3htbC8xLjEiPjx4ZGM6WE1MRGF0YSBDb250ZW50VHlwZT0iYXBwbGljYXRpb24ve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xck0xejQxZlBSWEJFZ3AvcWJnPSIgTGFuZ3VhZ2U9InNrIiBNZWRpYURlc3RpbmF0aW9uVHlwZURlc2NyaXB0aW9uPSJUWFQiIFRyYW5zZm9ybUFsZ29yaXRobT0iaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMteG1sLWMxNG4tMjAwMTAzMTUiPmh0dHA6Ly9zY2hlbWFzLmdvdi5zay9mb3JtL0FwcC5HZW5lcmFsQWdlbmRhLzEuOS9mb3JtLnhzbHQ8L3hkYzpVc2VkUHJlc2VudGF0aW9uU2NoZW1hUmVmZXJlbmNlPjwveGRjOlVzZWRTY2hlbWFzUmVmZXJlbmNlZD48L3hkYzpYTUxEYXRhQ29udGFpbmVyPg=="; - var actualOriginalXdcFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(actualOriginalXdcFileContent), "document.xml", AutogramMimeType.XML_DATACONTAINER); + var actualOriginalXdcFile = new InMemoryDocument(Base64.getDecoder().decode(actualOriginalXdcFileContent), "document.xml", AutogramMimeType.XML_DATACONTAINER); var xdcFileFromAsice = AsicContainerUtils.getOriginalDocument(asiceWithXdcOriginalFile); @@ -28,7 +29,7 @@ void testGetOriginalFileXdc() { @Test void testGetOriginalFileNoSigantures() { var asiceContent = "UEsDBBQAAAAIAFZ6EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu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ures = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutSignatures = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithoutSignatures)); } @@ -36,7 +37,7 @@ void testGetOriginalFileNoSigantures() { @Test void testGetOriginalFileNoOriginalFileInAsice() { var asiceContent = "UEsDBBQAAAAIALB7EFe5PYSYwAAAAIUBAAAVAAAATUVUQS1JTkYvbWFuaWZlc3QueG1sjZDBTgMxDER/ZeVrlSxwQlHT3vgC+AAr8RaLxIk23hXl60mRWhZx6c0jzcwbeX/8zGlYaW5cxMOjfYCBJJTIcvLw9vpinuF42GcUnqipux5Dj0m7SQ/LLK5g4+YEMzWnwZVKEktYMom6v373A7qpDf8JNrSJE5mens+/3mlJyVTUdw/jpiJTZDR6ruQBa00cUHvluEq0pI1t3xYM7b64wng/4rrf9v130k5lte3jEoioGIoostC8uzR08vjvl4dvUEsDBBQAAAAIALB7EFdq0ASBPQcAAHEOAAAaAAAATUVUQS1JTkYvc2lnbmF0dXJlczAwMS54bWy1V1l3gsgS/is5yaOTsLqQk2QOq4ICsinwxtICyiar8usvamLWuZM5c++TdHVVdX3V1VWfT38ekvimAUUZZenzLfIA396A1Mv8KA2ebw2du5/c/vny5JSR92iSPqtpUZA6VV2A8qa3TMvH09bzbVhV+SME1UX0AKoyesiKAIJRAplADfKAPiB3ty9Pfvl4tX419suradu2Dy12NkRhGIZgAup1/DIK7m5veP/5NvLvxyN4MhxhE9R1XRwfjfAh7sIYhg7RCeyC8eb9EODz6SY7L2knzdLIc+Koc6oepQiqMPNvyDjIiqgKk58i0NVTEAiksvR9H8W9h+Dp/UkCY8jwFvqM5TcOz95g/A3SfZIV4K4onfsydNDh6NWlCjag6NMPzoCL+19AvkdubwyVf771M69OQFo99Edc8sBEASirfxhdf/rdp5guXlZOXIOX2sJl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AIAAAAAAAAABNRVRBLUlORi9tYW5pZmVzdC54bWxQSwECFAAUAAAACACwexBXatAEgT0HAABxDgAAGgAAAAAAAAABACAAAADzAAAATUVUQS1JTkYvc2lnbmF0dXJlczAwMS54bWxQSwECFAAUAAAAAACwexBXiiH5RR8AAAAfAAAACAAAAAAAAAABACAAAABoCAAAbWltZXR5cGVQSwUGAAAAAAMAAwDBAAAArQgAAAAA"; - var asiceWithoutOriginalFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutOriginalFile = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(OriginalDocumentNotFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithoutOriginalFile)); } @@ -44,7 +45,7 @@ void testGetOriginalFileNoOriginalFileInAsice() { @Test void testGetOriginalFileNoFileEntriesInManifest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu+qyXTz9RpgVXEpr0Jdx0sHZRX4unH0s+R047jdRrKWnSQtKkO578+RXfEvbIgigN2AFMwfh5g9imxtedTRh1ZALW9cDNtAjxwqiGlqJRJeyYnNQC4icYMHJIasSH8LP6hqcLPz565lTQrnfefeiq49HgYnAi+6Pu9PESavP2JOseVI9EzO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Q4AABoAAAAAAAAAAQAgAAAA9wIAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAAAAAA9HsQV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAAbAoAAG1pbWV0eXBlUEsFBgAAAAAEAAQA+wAAALEKAAAAAA=="; - var asiceWithManifestFileWithoutFileEntries = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithManifestFileWithoutFileEntries = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithManifestFileWithoutFileEntries); @@ -56,7 +57,7 @@ void testGetOriginalFileNoFileEntriesInManifest() { @Test void testGetOriginalFileInvalidManifest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu+qyXTz9RpgVXEpr0Jdx0sHZRX4unH0s+R047jdRrKWnSQtKkO578+RXfEvbIgigN2AFMwfh5g9imxtedTRh1ZALW9cDNtAjxwqiGlqJRJeyYnNQC4icYMHJIasSH8LP6hqcLPz565lTQrnfefeiq49HgYnAi+6Pu9PESavP2JOseVI9EzOTkdnEeYjQ0XNmcaytNtJFuNt/HbzgoEQ7OzyoedCVmNVXJI8EhO8LR306rSJG1FSW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ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithInvalidManifestFile = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithInvalidManifestFile); @@ -68,7 +69,7 @@ void testGetOriginalFileInvalidManifest() { @Test void testGetOriginalFileNoMainfest() { var asiceContent = "UEsDBBQAAAAIAPR7EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtARjpVYhZiTACFSshVRJiEfDi8oJPo2aaxE3xr2rDnf8TCvHpQKD/E1lGz4V4plzWYNS4fMk0UtiH6iAKY1ftNRr8+QmcOADlBGGd2qjvDgoN3zMIMQ8y1IZc+ed5fffo3jGjQUXlrbQR+GlcirB7DegYwpTbea0lWXkEvyrPG0loAT3L9cxutl2Xfc+dhRlc5u6Np7BnNuX0m9VfaZi5ebyarUiq0OiTUKrQcCob/a6qFeRyjquYvCv28XdPcQu+qyXTz9RpgVXEpr0Jdx0sHZRX4unH0s+R047jdRrKWnSQtKkO578+RXfEvbIgigN2AFMwfh5g9imxtedTRh1ZALW9cDNtAjxwqiGlqJRJeyYnNQC4icYMHJIasSH8LP6hqcLPz565lTQrnfefeiq49HgYnAi+6Pu9PESavP2JOseVI9EzOTkdnEeYjQ0XNmcaytNtJFuNt/HbzgoEQ7OzyoedCVmNVXJI8EhO8LR306rSJG1FSWl37vfMukbsH7Zil0s0W0R/XlnberyPcf/QvGrZveTMft0+yiWPfrliholTTZ7YKbHvtfYtD8Yt8+TjH67898ruuIqWfDE37MPGPVASN7xtaQqHOUW/TE2MnPF4g/Hw/9MPnVb9G9AjraqPZv7esU3v6foF1BLAwQUAAAACAD0exBXatAEgT0HAABxDgAAGgAAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDE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fH9+hIR+BHlHjEcfsJ+q732fRTci87J9HH78tk/j/xBPfYJMuSiMNFBdKI37tHaAHZSXQ0uC5fFn54hA1dKrPlof2JJ3yP8iLhy7IGhQaKyImvU+Ii/O2c+aB9nVRnf1KduKB4QUbj8RhBxgT6Ppo+7r8F9zkU6GOOob++ig9bf1sBwD+9hkvtf9d43+N6vudUN5fFlV71pf1b7v7mUuzr6MSBX5w8j08B939UoCb1H4KseSh3J1Lv96d6WVo5UQqKQS94Q3S1fRN8je8L9p+hfVL5YeOnp39pF28t4hNT6Zc//Wl8+Q9QSwMEFAAAAAAA9HsQV4oh+UUfAAAAHwAAAAgAAABtaW1ldHlwZWFwcGxpY2F0aW9uL3ZuZC5ldHNpLmFzaWMtZSt6aXBQSwECFAAUAAAACAD0exBXmbqZaCwCAADbBAAADAAAAAAAAAABACAAAAAAAAAAZG9jdW1lbnQueG1sUEsBAhQAFAAAAAgA9HsQV2rQBIE9BwAAcQ4AABoAAAAAAAAAAQAgAAAAVgIAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAAAAAA9HsQV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAAywkAAG1pbWV0eXBlUEsFBgAAAAADAAMAuAAAABAKAAAAAA=="; - var asiceWithoutManifestFile = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithoutManifestFile = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithoutManifestFile); @@ -80,7 +81,7 @@ void testGetOriginalFileNoMainfest() { @Test void testGetOriginalFileManifestFileEntriesNoAttributes() { var asiceContent = "UEsDBBQAAAAIAG1+EFeZuploLAIAANsEAAAMAAAAZG9jdW1lbnQueG1sxZTPctowEMZfRaNrBskiJA0UOwMhSVtCSwkkcFSsxSgxkiuJP+nb9NjnyItVthMIHZqZTg89avfT6tvfrt08Xc9TtAR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7uvwX3ORToY46hv76KD1t/WwHAP72GS+1/13jf43q+51Q3l8WVXvWl/Vvu/uZS7OvoxIFfnDyPTwH3f1SgJvUfgqx5KHcnUu/3p3pZWjlRCopBL3hDdLV9E3yN7wv2n6F9Uvlh46enf2kXby3iE1Pplz/9aXz5D1BLAwQUAAAAAABtfhBXiiH5RR8AAAAfAAAACAAAAG1pbWV0eXBlYXBwbGljYXRpb24vdm5kLmV0c2kuYXNpYy1lK3ppcFBLAQIUABQAAAAIAG1+EFeZuploLAIAANsEAAAMAAAAAAAAAAEAIAAAAAAAAABkb2N1bWVudC54bWxQSwECFAAUAAAACACNfhBXqJLPmXoAAADUAAAAFQAAAAAAAAABACAAAABWAgAATUVUQS1JTkYvbWFuaWZlc3QueG1sUEsBAhQAFAAAAAgAbX4QV2rQBIE9BwAAcQ4AABoAAAAAAAAAAQAgAAAAAwMAAE1FVEEtSU5GL3NpZ25hdHVyZXMwMDEueG1sUEsBAhQAFAAAAAAAbX4QV4oh+UUfAAAAHwAAAAgAAAAAAAAAAQAgAAAAeAoAAG1pbWV0eXBlUEsFBgAAAAAEAAQA+wAAAL0KAAAAAA=="; - var asiceWithManifestFileWithNoFileEntryAttributes = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithManifestFileWithNoFileEntryAttributes = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); var originalFile = AsicContainerUtils.getOriginalDocument(asiceWithManifestFileWithNoFileEntryAttributes); @@ -92,7 +93,7 @@ void testGetOriginalFileManifestFileEntriesNoAttributes() { @Test void testGetOriginalFileMultipleFilesInAsice() { var asiceContent = "UEsDBBQDAAAIAAdfElfy7qAyvAAAALcBAAAVAAAATUVUQS1JTkYvbWFuaWZlc3QueG1slZBNbgIxDEb3PcXI2yqTllUVEdj1BO0BrIwBS4kTTTxo4PSMkIBBsICdP/+8J3m5HlNs9tRXzuLhu/2ChiTkjmXr4f/v1/zAerV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cAAE8PAAAaAAAAAAAAAAAAAAAAAO8AAABNRVRBLUlORi9zaWduYXR1cmVzMDAxLnhtbFBLAQIKAAoAAAgAAKBREleKIflFHwAAAB8AAAAIAAAAAAAAAAAAAAAAANIIAABtaW1ldHlwZVBLAQIUABQACAgIAKBRElfvDPUSDwAAAA0AAAAIAAAAAAAAAAAAAAAAABcJAAB0ZXN0LnR4dFBLAQI/AwoDAAAAACFRElfvDPUSDQAAAA0AAAAJACQAAAAAAAAAIIC0gVwJAAB0ZXN0Mi50eHQKACAAAAAAAAEAGAAAo40/q9HZAYCe812r0dkBgL39V6vR2QFQSwUGAAAAAAUABQB2AQAAkAkAAAAA"; - var asiceWithMultipleFiles = new ProtectedInMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); + var asiceWithMultipleFiles = new InMemoryDocument(Base64.getDecoder().decode(asiceContent), null, MimeTypeEnum.ASICE); Assertions.assertThrows(MultipleOriginalDocumentsFoundException.class, () -> AsicContainerUtils.getOriginalDocument(asiceWithMultipleFiles)); } From 065f674571df7df5da97c5f8aa79ca216577ed5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 25 Sep 2024 20:01:30 +0200 Subject: [PATCH 13/50] fix: pasword controller constructor --- .../digital/slovensko/autogram/ui/gui/PasswordController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java index 9db8050e..ad3ff57a 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java @@ -35,7 +35,7 @@ public class PasswordController { VBox mainBox; public PasswordController(String questionText, String blankPasswordErrorText, boolean isSigningStep, boolean allowEmpty) { - this(questionText, null, blankPasswordErrorText, false, false); + this(questionText, null, blankPasswordErrorText, isSigningStep, allowEmpty); } public PasswordController(String questionText, String description, String blankPasswordErrorText, boolean isSigningStep, boolean allowEmpty) { From 56cc58a9b1608083a222e3a8c79e58e2eca84f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 25 Sep 2024 20:08:58 +0200 Subject: [PATCH 14/50] fix: document name can be empty --- src/main/java/digital/slovensko/autogram/ui/gui/GUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index 2f61e18c..e8396fa1 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -202,7 +202,7 @@ public void showPkcsEidWindowsDllError(AutogramException e) { public char[] getDocumentPassword(DSSDocument document) { var futurePassword = new FutureTask<>(() -> { - var controller = new PasswordController("Aké je heslo k dokumentu?", "Odomikáte " + document.getName(), "Zadajte heslo k dokumentu.", false, false); + var controller = new PasswordController("Aké je heslo k dokumentu?", document.getName() != null ? "Odomikáte " + document.getName() : null, "Zadajte heslo k dokumentu.", false, false); var root = GUIUtils.loadFXML(controller, "password-dialog.fxml"); var stage = new Stage(); From 2778cb29107927e14971a98e0d620d2d8b172a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 25 Sep 2024 20:16:10 +0200 Subject: [PATCH 15/50] fix: handle protected pdf in sign endpoint before validation --- .../java/digital/slovensko/autogram/core/SigningJob.java | 2 -- .../digital/slovensko/autogram/server/SignEndpoint.java | 2 ++ .../slovensko/autogram/server/dto/SignRequestBody.java | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index cb2c1ee4..bfc252b4 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -185,8 +185,6 @@ private static SigningJob build(AutogramDocument autogramDocument, SigningParame } public static SigningJob buildFromRequest(AutogramDocument document, Autogram autogram, SigningParameters params, Responder responder) { - autogram.handleProtectedPdfDocument(document); - return build(document, params, responder); } diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index 2b6e0b38..66971fa1 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -24,6 +24,8 @@ public SignEndpoint(Autogram autogram) { public void handle(HttpExchange exchange) throws IOException { try { var body = EndpointUtils.loadFromJsonExchange(exchange, SignRequestBody.class); + autogram.handleProtectedPdfDocument(body.getDocument()); + body.validateDocument(); body.validateSigningParameters(); diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index 540f9700..6c8189bb 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -16,6 +16,7 @@ public class SignRequestBody { private final Document document; + private AutogramDocument autogramDocument; private ServerSigningParameters parameters; private final String payloadMimeType; private final String batchId; @@ -54,10 +55,14 @@ private void resolveSigningLevel() throws RequestValidationException { } public AutogramDocument getDocument() { + if (autogramDocument != null) + return autogramDocument; + var content = decodeDocumentContent(document.getContent(), isBase64()); var filename = document.getFilename(); - return new AutogramDocument(new InMemoryDocument(content, filename, getMimetype())); + this.autogramDocument = new AutogramDocument(new InMemoryDocument(content, filename, getMimetype())); + return autogramDocument; } public void validateSigningParameters() throws RequestValidationException, MalformedBodyException, From f8a4f7744e5296a97285d8736c4b98d22fab85ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 19:34:18 +0200 Subject: [PATCH 16/50] fix: password dialog --- .../slovensko/autogram/ui/gui/PasswordController.java | 9 ++++++++- .../slovensko/autogram/ui/gui/password-dialog.fxml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java index ad3ff57a..49c6a83a 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/PasswordController.java @@ -48,8 +48,15 @@ public PasswordController(String questionText, String description, String blankP public void initialize() { question.setText(questionText); - description.setText(descriptionText); + + if (descriptionText != null) { + description.setText(descriptionText); + description.setManaged(true); + description.setVisible(true); + } + error.setText(errorText); + if(isSigningStep) { mainButton.setText("Podpísať"); cancelButton.setManaged(true); diff --git a/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml b/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml index 8af75559..ee3fdc24 100644 --- a/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml +++ b/src/main/resources/digital/slovensko/autogram/ui/gui/password-dialog.fxml @@ -13,7 +13,7 @@ - + From a8770c1dfc2955c4fce192ee8e3f4b32dde6c244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 19:35:13 +0200 Subject: [PATCH 17/50] refactor: AutogramDocument#getDSSDocument --- .../slovensko/autogram/core/Autogram.java | 8 ++-- .../slovensko/autogram/core/SigningJob.java | 42 +++++++++---------- .../DocumentVisualizationBuilder.java | 24 +++++------ .../core/visualization/PDFVisualization.java | 2 +- .../autogram/model/AutogramDocument.java | 2 +- .../autogram/server/dto/SignRequestBody.java | 4 +- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../slovensko/autogram/ui/cli/CliUI.java | 2 +- .../slovensko/autogram/ui/gui/GUI.java | 5 +-- .../slovensko/autogram/util/DSSUtils.java | 20 ++++----- 10 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index c53b6dc7..ceda7a8d 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -57,7 +57,7 @@ public void checkPDFACompliance(SigningJob job) { return; ui.onWorkThreadDo(() -> { - var result = new PDFAStructureValidator().validate(job.getDocument().getDocument()); + var result = new PDFAStructureValidator().validate(job.getDocument().getDSSDocument()); if (!result.isCompliant()) { ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); } @@ -65,11 +65,11 @@ public void checkPDFACompliance(SigningJob job) { } public void handleProtectedPdfDocument(AutogramDocument document) { - var protection = PDFUtils.determinePDFProtection(document.getDocument()); + var protection = PDFUtils.determinePDFProtection(document.getDSSDocument()); if (protection == PDFUtils.PDFProtection.NONE) return; - var password = ui.getDocumentPassword(document.getDocument()); + var password = ui.getDocumentPassword(document.getDSSDocument()); switch (protection) { case OPEN_DOCUMENT_PASSWORD -> document.setOpenDocumentPassword(password); case MASTER_PASSWORD -> document.setMasterPassword(password); @@ -169,7 +169,7 @@ public void batchSign(SigningJob job, String batchId) { ui.onWorkThreadDo(() -> { try { signCommonAndThen(job, batch.getSigningKey(), (jobNew) -> { - Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getDocument().getName()); + Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getDSSDocument().getName()); }); } catch (AutogramException e) { job.onDocumentSignFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index bfc252b4..4cc70485 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -46,7 +46,7 @@ public int getVisualizationWidth() { } public void signWithKeyAndRespond(SigningKey key) throws InterruptedException, AutogramException { - Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getDocument().getName()); + Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getDSSDocument().getName()); boolean isContainer = getParameters().getContainer() != null; var doc = switch (getParameters().getSignatureType()) { case XAdES -> isContainer ? signDocumentAsAsiCWithXAdeS(key) : signDocumentAsXAdeS(key); @@ -72,10 +72,10 @@ private DSSDocument signDocumentAsCAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { @@ -90,10 +90,10 @@ private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.XAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, getParameters().getDigestAlgorithm()); - return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsXAdeS(SigningKey key) { @@ -106,10 +106,10 @@ private DSSDocument signDocumentAsXAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { @@ -125,10 +125,10 @@ private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.CAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsPAdeS(SigningKey key) { @@ -147,10 +147,10 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { signatureParameters.setContentSize(9472*2); } - var dataToSign = service.getDataToSign(getDocument().getDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); } public static AutogramDocument createDSSFileDocumentFromFile(File file) { @@ -169,7 +169,7 @@ else if (isTxt(fileDocument.getMimeType())) } private static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { - DSSDocument document = autogramDocument.getDocument(); + DSSDocument document = autogramDocument.getDSSDocument(); if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); @@ -200,31 +200,31 @@ private static SigningParameters getParametersForFile(AutogramDocument document, var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: - return SigningParameters.buildForPDF(document.getDocument(), checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource); case XAdES: - return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES: - return SigningParameters.buildForASiCWithCAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } - if (isPDF(document.getDocument().getMimeType())) switch (signatureType) { + if (isPDF(document.getDSSDocument().getMimeType())) switch (signatureType) { case PAdES_BASELINE_B: - return SigningParameters.buildForPDF(document.getDocument(), checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource); case XAdES_BASELINE_B: - return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES_BASELINE_B: - return SigningParameters.buildForASiCWithCAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } - return SigningParameters.buildForASiCWithXAdES(document.getDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); } public boolean shouldCheckPDFCompliance() { // PDF/A doesn't support encryption - return parameters.getCheckPDFACompliance() && isPDF(document.getDocument().getMimeType()) && document.getOpenDocumentPassword().length == 0; + return parameters.getCheckPDFACompliance() && isPDF(document.getDSSDocument().getMimeType()) && document.getOpenDocumentPassword().length == 0; } } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index 7da9a866..b6108870 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -42,9 +42,9 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti throws IOException, ParserConfigurationException, SAXException { var documentToDisplay = document; - if (isAsice(documentToDisplay.getDocument().getMimeType())) { + if (isAsice(documentToDisplay.getDSSDocument().getMimeType())) { try { - documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document.getDocument())); + documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document.getDSSDocument())); } catch (AutogramException e) { return new UnsupportedVisualization(job); } @@ -52,29 +52,29 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti var transformation = parameters.getTransformation(); - if (isDocumentSupportingTransformation(documentToDisplay.getDocument()) && isTranformationAvailable(transformation)) { + if (isDocumentSupportingTransformation(documentToDisplay.getDSSDocument()) && isTranformationAvailable(transformation)) { var transformationOutputMimeType = parameters.getXsltDestinationType(); if (transformationOutputMimeType.equals("HTML")) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); if (transformationOutputMimeType.equals("TXT")) - return new PlainTextVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); + return new PlainTextVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); return new UnsupportedVisualization(job); } - if (documentToDisplay.getDocument().getMimeType().equals(MimeTypeEnum.HTML)) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDocument(), transformation), job); + if (documentToDisplay.getDSSDocument().getMimeType().equals(MimeTypeEnum.HTML)) + return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); - if (isTxt(documentToDisplay.getDocument().getMimeType())) - return new PlainTextVisualization(new String(documentToDisplay.getDocument().openStream().readAllBytes(), StandardCharsets.UTF_8), job); + if (isTxt(documentToDisplay.getDSSDocument().getMimeType())) + return new PlainTextVisualization(new String(documentToDisplay.getDSSDocument().openStream().readAllBytes(), StandardCharsets.UTF_8), job); - if (isPDF(documentToDisplay.getDocument().getMimeType())) + if (isPDF(documentToDisplay.getDSSDocument().getMimeType())) return new PDFVisualization(documentToDisplay, job, userSettings); - if (isImage(documentToDisplay.getDocument().getMimeType())) - return new ImageVisualization(documentToDisplay.getDocument(), job); + if (isImage(documentToDisplay.getDSSDocument().getMimeType())) + return new ImageVisualization(documentToDisplay.getDSSDocument(), job); return new UnsupportedVisualization(job); } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java index 727fa028..41ffe1f4 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java @@ -26,7 +26,7 @@ public PDFVisualization(AutogramDocument document, SigningJob job, UserSettings } private ArrayList getPdfImages() throws IOException { - var pdfDocument = PDDocument.load(this.document.getDocument().openStream(), new String(this.document.getOpenDocumentPassword())); + var pdfDocument = PDDocument.load(this.document.getDSSDocument().openStream(), new String(this.document.getOpenDocumentPassword())); var pdfRenderer = new PDFRenderer(pdfDocument); var divs = new ArrayList(); for (int page = 0; page < pdfDocument.getNumberOfPages(); ++page) { diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index f30f544c..ae0fb634 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -32,7 +32,7 @@ public char[] getSigningPassword() { return openDocumentPassword.length > 0 ? openDocumentPassword : masterPassword; } - public DSSDocument getDocument() { + public DSSDocument getDSSDocument() { return document; } } diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index 6c8189bb..19b387a0 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -70,11 +70,11 @@ public void validateSigningParameters() throws RequestValidationException, Malfo if (parameters == null) throw new RequestValidationException("Parameters are required", ""); - parameters.validate(getDocument().getDocument().getMimeType()); + parameters.validate(getDocument().getDSSDocument().getMimeType()); } public SigningParameters getParameters(TSPSource tspSource, boolean plainXmlEnabled) { - return parameters.getSigningParameters(isBase64(), getDocument().getDocument(), tspSource, plainXmlEnabled); + return parameters.getSigningParameters(isBase64(), getDocument().getDSSDocument(), tspSource, plainXmlEnabled); } public String getBatchId() { diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index ec01f71d..abc06c71 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -36,7 +36,7 @@ public static void start(CommandLine cmd) { .toList(); if (settings.isPdfaCompliance()) { jobs.forEach(job -> { - System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getDocument().getName()); + System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getDSSDocument().getName()); autogram.checkPDFACompliance(job); }); } diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 6eeb6fec..0fcfecbc 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -47,7 +47,7 @@ public void startSigning(SigningJob job, Autogram autogram) { } private void sign(SigningJob job, Autogram autogram) { - System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getDocument().getName(), nJobsSigned++, + System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getDSSDocument().getName(), nJobsSigned++, nJobsTotal)); autogram.sign(job, activeKey); } diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index e8396fa1..0b7c3f23 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -16,7 +16,6 @@ import digital.slovensko.autogram.drivers.TokenDriver; import digital.slovensko.autogram.ui.BatchUiResult; import digital.slovensko.autogram.ui.UI; -import eu.europa.esig.dss.enumerations.KeyUsageBit; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import javafx.application.HostServices; import javafx.application.Platform; @@ -342,8 +341,8 @@ public void onSignatureCheckCompleted(ValidationReports reports) { public void showVisualization(Visualization visualization, Autogram autogram) { var title = "Dokument"; - if (visualization.getJob().getDocument().getDocument().getName() != null) - title = "Dokument " + visualization.getJob().getDocument().getDocument().getName(); + if (visualization.getJob().getDocument().getDSSDocument().getName() != null) + title = "Dokument " + visualization.getJob().getDocument().getDSSDocument().getName(); var controller = new SigningDialogController(visualization, autogram, this, title, userSettings.isSignaturesValidity()); jobControllers.put(visualization.getJob(), controller); diff --git a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java index 2a33947d..f054b50b 100644 --- a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java @@ -39,23 +39,23 @@ public static String buildTooltipLabel(DSSPrivateKeyEntry key) { } public static SignedDocumentValidator createDocumentValidator(AutogramDocument document) { - if (new PDFDocumentValidatorFactory().isSupported(document.getDocument())) { - var validator = new PDFDocumentValidator(document.getDocument()); + if (new PDFDocumentValidatorFactory().isSupported(document.getDSSDocument())) { + var validator = new PDFDocumentValidator(document.getDSSDocument()); validator.setPasswordProtection(document.getOpenDocumentPassword()); return validator; } - if (new XMLDocumentValidatorFactory().isSupported(document.getDocument())) - return new XMLDocumentValidatorFactory().create(document.getDocument()); + if (new XMLDocumentValidatorFactory().isSupported(document.getDSSDocument())) + return new XMLDocumentValidatorFactory().create(document.getDSSDocument()); - if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document.getDocument())) - return new ASiCContainerWithXAdESValidatorFactory().create(document.getDocument()); + if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document.getDSSDocument())) + return new ASiCContainerWithXAdESValidatorFactory().create(document.getDSSDocument()); - if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document.getDocument())) - return new ASiCContainerWithCAdESValidatorFactory().create(document.getDocument()); + if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document.getDSSDocument())) + return new ASiCContainerWithCAdESValidatorFactory().create(document.getDSSDocument()); - if (new CMSDocumentValidatorFactory().isSupported(document.getDocument())) - return new CMSDocumentValidatorFactory().create(document.getDocument()); + if (new CMSDocumentValidatorFactory().isSupported(document.getDSSDocument())) + return new CMSDocumentValidatorFactory().create(document.getDSSDocument()); return null; } From a8a2b5d26422821c0254a231e819b203ae93df93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 19:36:50 +0200 Subject: [PATCH 18/50] refactor: remove Autogram from buildFromRequest --- .../digital/slovensko/autogram/core/SigningJob.java | 2 +- .../slovensko/autogram/server/SignEndpoint.java | 2 +- .../digital/slovensko/autogram/AutogramTests.java | 8 ++++---- .../slovensko/autogram/TransformationTests.java | 12 ++---------- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 4cc70485..ee65dbdc 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -184,7 +184,7 @@ private static SigningJob build(AutogramDocument autogramDocument, SigningParame return new SigningJob(autogramDocument, params, responder); } - public static SigningJob buildFromRequest(AutogramDocument document, Autogram autogram, SigningParameters params, Responder responder) { + public static SigningJob buildFromRequest(AutogramDocument document, SigningParameters params, Responder responder) { return build(document, params, responder); } diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index 66971fa1..2b88a0c4 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -31,7 +31,7 @@ public void handle(HttpExchange exchange) throws IOException { var responder = body.getBatchId() == null ? new ServerResponder(exchange) : new ResponderInBatch(new ServerResponder(exchange), autogram.getBatch(body.getBatchId())); - var job = SigningJob.buildFromRequest(body.getDocument(), autogram, body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); + var job = SigningJob.buildFromRequest(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); if (body.getBatchId() != null) autogram.batchSign(job, body.getBatchId()); diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index 564ed87e..59143ac6 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -53,7 +53,7 @@ void testSignAsiceXadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -69,7 +69,7 @@ void testSignNonEformHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -92,7 +92,7 @@ void testSignAsiceCadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); } @ParameterizedTest @@ -106,7 +106,7 @@ void testSignPadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), autogram, parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index f067ccf2..1fbc3ea3 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -72,11 +72,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce document, null, true); - var newUI = new AutogramTests.FakeUI(); - var settings = new AutogramTests.TestSettings(); - var autogram = new Autogram(newUI, settings); - - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), autogram, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -153,11 +149,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio document, null, true); - var newUI = new AutogramTests.FakeUI(); - var settings = new AutogramTests.TestSettings(); - var autogram = new Autogram(newUI, settings); - - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), autogram, params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { From cf8473c94e12d7769c90c9445711abd98305b663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 19:46:14 +0200 Subject: [PATCH 19/50] fix: PDF/A compliant check --- src/main/java/digital/slovensko/autogram/core/Autogram.java | 6 ++++++ .../java/digital/slovensko/autogram/core/SigningJob.java | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index ceda7a8d..a5389813 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -57,6 +57,12 @@ public void checkPDFACompliance(SigningJob job) { return; ui.onWorkThreadDo(() -> { + // PDF/A doesn't support encryption + if (job.getDocument().getOpenDocumentPassword().length > 0) { + ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); + return; + } + var result = new PDFAStructureValidator().validate(job.getDocument().getDSSDocument()); if (!result.isCompliant()) { ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index ee65dbdc..f17df865 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -224,7 +224,6 @@ private static SigningParameters getParametersForFile(AutogramDocument document, } public boolean shouldCheckPDFCompliance() { - // PDF/A doesn't support encryption - return parameters.getCheckPDFACompliance() && isPDF(document.getDSSDocument().getMimeType()) && document.getOpenDocumentPassword().length == 0; + return parameters.getCheckPDFACompliance() && isPDF(document.getDSSDocument().getMimeType()); } } From ff4eca7e57da92ee5a91b59d19e5f6c877ea3292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 19:48:18 +0200 Subject: [PATCH 20/50] refactor: wrap to hasOpenDocumentPassword --- src/main/java/digital/slovensko/autogram/core/Autogram.java | 2 +- .../digital/slovensko/autogram/model/AutogramDocument.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index a5389813..fc105c4d 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -58,7 +58,7 @@ public void checkPDFACompliance(SigningJob job) { ui.onWorkThreadDo(() -> { // PDF/A doesn't support encryption - if (job.getDocument().getOpenDocumentPassword().length > 0) { + if (job.getDocument().hasOpenDocumentPassword()) { ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); return; } diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index ae0fb634..a63309fe 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -12,6 +12,10 @@ public AutogramDocument(DSSDocument document) { this.document = document; } + public boolean hasOpenDocumentPassword() { + return openDocumentPassword.length > 0; + } + public char[] getOpenDocumentPassword() { return openDocumentPassword; } @@ -29,7 +33,7 @@ public void setMasterPassword(char[] masterPassword) { } public char[] getSigningPassword() { - return openDocumentPassword.length > 0 ? openDocumentPassword : masterPassword; + return this.hasOpenDocumentPassword() ? openDocumentPassword : masterPassword; } public DSSDocument getDSSDocument() { From 3c03aef8b3a6b22217ba5a8e5254b3ea13939879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 20:23:19 +0200 Subject: [PATCH 21/50] fix: errors --- .../autogram/core/errors/AutogramException.java | 2 ++ .../core/errors/InvalidPasswordException.java | 7 +++++++ .../autogram/ui/BatchGuiFileResponder.java | 5 +++++ .../slovensko/autogram/ui/cli/CliApp.java | 3 +++ .../autogram/ui/gui/MainMenuController.java | 17 ++++++++++++----- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java diff --git a/src/main/java/digital/slovensko/autogram/core/errors/AutogramException.java b/src/main/java/digital/slovensko/autogram/core/errors/AutogramException.java index cf0cb67a..0a9c2f41 100644 --- a/src/main/java/digital/slovensko/autogram/core/errors/AutogramException.java +++ b/src/main/java/digital/slovensko/autogram/core/errors/AutogramException.java @@ -63,6 +63,8 @@ public static AutogramException createFromDSSException(DSSException e) { return new TsaServerMisconfiguredException("Nie je nastavená žiadna adresa TSA servera. Skontrolujte nastavenia TSA servera.", cause); } else if (cause instanceof IOException && (cause.getMessage().contains("The specified module could not be found") || cause.getMessage().contains("Zadaný modul sa nepodarilo"))) { return new PkcsEidWindowsDllException(e); + } else if (cause instanceof eu.europa.esig.dss.pades.exception.InvalidPasswordException) { + return new InvalidPasswordException("Zadali ste nesprávne heslo"); } } } diff --git a/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java b/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java new file mode 100644 index 00000000..8fbe06b8 --- /dev/null +++ b/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java @@ -0,0 +1,7 @@ +package digital.slovensko.autogram.core.errors; + +public class InvalidPasswordException extends AutogramException { + public InvalidPasswordException(String message) { + super("Nesprávne heslo", "Zadali ste nesprávne heslo", message); + } +} diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index e8bf0be5..9ad64207 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -15,6 +15,7 @@ import digital.slovensko.autogram.core.errors.AutogramException; import digital.slovensko.autogram.util.Logging; import eu.europa.esig.dss.enumerations.SignatureLevel; +import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; public class BatchGuiFileResponder extends BatchResponder { @@ -66,6 +67,10 @@ public void onBatchStartSuccess(Batch batch) { var job = SigningJob.buildFromFile(file, autogram, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); + } catch (DSSException e) { + autogram.onSigningFailed(AutogramException.createFromDSSException(e)); + + break; } catch (AutogramException e) { autogram.onSigningFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index abc06c71..5d6bf6e1 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -9,6 +9,7 @@ import java.io.File; import java.util.Arrays; +import eu.europa.esig.dss.model.DSSException; import org.apache.commons.cli.CommandLine; public class CliApp { @@ -45,6 +46,8 @@ public static void start(CommandLine cmd) { jobs.forEach(autogram::sign); + } catch (DSSException e) { + System.err.println(CliUI.parseError(AutogramException.createFromDSSException(e))); } catch (AutogramException e) { System.err.println(CliUI.parseError(e)); } diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index 21eae618..71a0f019 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -9,6 +9,7 @@ import digital.slovensko.autogram.core.errors.UnrecognizedException; import digital.slovensko.autogram.ui.BatchGuiFileResponder; import digital.slovensko.autogram.ui.SaveFileResponder; +import eu.europa.esig.dss.model.DSSException; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.Scene; @@ -112,11 +113,17 @@ private void signFiles(List list) { var file = filesList.get(0); autogram.wrapInWorkThread(() -> { - var job = SigningJob.buildFromFile(file, autogram, - new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), - userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); - - autogram.sign(job); + try { + var job = SigningJob.buildFromFile(file, autogram, + new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), + userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); + + autogram.sign(job); + } catch (DSSException e) { + autogram.onSigningFailed(AutogramException.createFromDSSException(e)); + } catch (AutogramException e) { + autogram.onSigningFailed(e); + } }); } else { autogram.batchStart(filesList.size(), new BatchGuiFileResponder(autogram, filesList, From 2940dffcffccdd742c02063a39f5b97135f3fda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 9 Oct 2024 20:26:33 +0200 Subject: [PATCH 22/50] style: change invalid pass subheading --- .../autogram/core/errors/InvalidPasswordException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java b/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java index 8fbe06b8..5532ebf2 100644 --- a/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java +++ b/src/main/java/digital/slovensko/autogram/core/errors/InvalidPasswordException.java @@ -2,6 +2,6 @@ public class InvalidPasswordException extends AutogramException { public InvalidPasswordException(String message) { - super("Nesprávne heslo", "Zadali ste nesprávne heslo", message); + super("Nesprávne heslo", "Heslo je nesprávne", message); } } From 762b7b9e7c633b2d11b3918c865d434b5d6c36e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sun, 13 Oct 2024 19:09:36 +0200 Subject: [PATCH 23/50] fix :tests --- .../java/digital/slovensko/autogram/SigningJobTests.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/digital/slovensko/autogram/SigningJobTests.java b/src/test/java/digital/slovensko/autogram/SigningJobTests.java index 9fe0fce8..1b636496 100644 --- a/src/test/java/digital/slovensko/autogram/SigningJobTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningJobTests.java @@ -51,12 +51,8 @@ void testEnd2EndHtmlTransformationEncoding() throws IOException, RequestValidati null, null, null); - var newUI = new AutogramTests.FakeUI(); - var settings = new AutogramTests.TestSettings(); - var autogram = new Autogram(newUI, settings); - var signRequestBody = new SignRequestBody(new Document(content), ssParams, "application/xml;base64"); - var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), autogram, signRequestBody.getParameters(null, true), null); + var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); Visualization visualization = null; try { visualization = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); From 72d33370e4f65ef7add69537eeb8b92029fa54a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sun, 13 Oct 2024 19:11:27 +0200 Subject: [PATCH 24/50] revert: revert some modifiers --- src/test/java/digital/slovensko/autogram/AutogramTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index 59143ac6..78f02993 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -193,7 +193,7 @@ public AbstractKeyStoreTokenConnection createToken(PasswordManager pm, Signature } } - public static class FakeUI implements UI { + private static class FakeUI implements UI { @Override public void startSigning(SigningJob signingJob, Autogram autogram) { @@ -318,7 +318,7 @@ public void updateBatch() { } } - public static class TestSettings extends UserSettings { + private static class TestSettings extends UserSettings { @Override public DriverDetector getDriverDetector() { List drivers = List.of(new FakeTokenDriver("fake")); From 39279d116fc6961875155d0a87ab1167527fe126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sat, 26 Oct 2024 17:32:28 +0200 Subject: [PATCH 25/50] refactor(AutogramDocument): dont use this --- .../java/digital/slovensko/autogram/model/AutogramDocument.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index a63309fe..d8845b18 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -33,7 +33,7 @@ public void setMasterPassword(char[] masterPassword) { } public char[] getSigningPassword() { - return this.hasOpenDocumentPassword() ? openDocumentPassword : masterPassword; + return hasOpenDocumentPassword() ? openDocumentPassword : masterPassword; } public DSSDocument getDSSDocument() { From d6660e17c088687cb7fcc20fa643550fc2ec1a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Fri, 15 Nov 2024 11:45:15 +0100 Subject: [PATCH 26/50] mv buildSigningJobFromFile to Autogram --- .../slovensko/autogram/core/Autogram.java | 9 +++++++++ .../slovensko/autogram/core/SigningJob.java | 16 ++-------------- .../slovensko/autogram/server/SignEndpoint.java | 2 +- .../autogram/ui/BatchGuiFileResponder.java | 2 +- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../autogram/ui/gui/MainMenuController.java | 2 +- .../slovensko/autogram/AutogramTests.java | 10 +++++----- .../slovensko/autogram/SigningJobTests.java | 2 +- .../slovensko/autogram/TransformationTests.java | 4 ++-- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index fc105c4d..02fe1ff3 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -9,6 +9,7 @@ import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; import digital.slovensko.autogram.util.PDFUtils; +import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.pdfa.PDFAStructureValidator; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; @@ -82,6 +83,14 @@ public void handleProtectedPdfDocument(AutogramDocument document) { } } + public SigningJob buildSigningJobFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + var document = SigningJob.createDSSFileDocumentFromFile(file); + handleProtectedPdfDocument(document); + + var parameters = SigningJob.getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); + return SigningJob.build(document, parameters, responder); + } + public void wrapInWorkThread(Runnable callback) { ui.onWorkThreadDo(callback); } diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index f17df865..21a349af 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -168,7 +168,7 @@ else if (isTxt(fileDocument.getMimeType())) return new AutogramDocument(fileDocument); } - private static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { + public static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { DSSDocument document = autogramDocument.getDSSDocument(); if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); @@ -184,19 +184,7 @@ private static SigningJob build(AutogramDocument autogramDocument, SigningParame return new SigningJob(autogramDocument, params, responder); } - public static SigningJob buildFromRequest(AutogramDocument document, SigningParameters params, Responder responder) { - return build(document, params, responder); - } - - public static SigningJob buildFromFile(File file, Autogram autogram, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { - var document = createDSSFileDocumentFromFile(file); - autogram.handleProtectedPdfDocument(document); - - var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); - return build(document, parameters, responder); - } - - private static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + public static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index 2b88a0c4..d11d4ab6 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -31,7 +31,7 @@ public void handle(HttpExchange exchange) throws IOException { var responder = body.getBatchId() == null ? new ServerResponder(exchange) : new ResponderInBatch(new ServerResponder(exchange), autogram.getBatch(body.getBatchId())); - var job = SigningJob.buildFromRequest(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); + var job = SigningJob.build(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); if (body.getBatchId() != null) autogram.batchSign(job, body.getBatchId()); diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index 9ad64207..afc6ec23 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -65,7 +65,7 @@ public void onBatchStartSuccess(Batch batch) { onAllFilesSigned(batch); }), batch); - var job = SigningJob.buildFromFile(file, autogram, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); + var job = autogram.buildSigningJobFromFile(file, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); } catch (DSSException e) { autogram.onSigningFailed(AutogramException.createFromDSSException(e)); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 5d6bf6e1..7339207f 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -31,7 +31,7 @@ public static void start(CommandLine cmd) { var source = settings.getSource(); var sourceList = source.isDirectory() ? source.listFiles() : new File[] { source }; var jobs = Arrays.stream(sourceList).filter(f -> f.isFile()) - .map(f -> SigningJob.buildFromFile(f, autogram, new SaveFileResponder(f, autogram, targetPathBuilder), + .map(f -> autogram.buildSigningJobFromFile(f, new SaveFileResponder(f, autogram, targetPathBuilder), settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), settings.getTspSource(), settings.isPlainXmlEnabled())) .toList(); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index 71a0f019..b15fb0d6 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -114,7 +114,7 @@ private void signFiles(List list) { autogram.wrapInWorkThread(() -> { try { - var job = SigningJob.buildFromFile(file, autogram, + var job = autogram.buildSigningJobFromFile(file, new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index 78f02993..a600f513 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -53,7 +53,7 @@ void testSignAsiceXadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -69,7 +69,7 @@ void testSignNonEformHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -92,7 +92,7 @@ void testSignAsiceCadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); } @ParameterizedTest @@ -106,7 +106,7 @@ void testSignPadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -137,7 +137,7 @@ void testSignBuildFromFileHappyScenario(InMemoryDocument document) throws IOExce var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromFile(file, autogram, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); + key -> autogram.sign(autogram.buildSigningJobFromFile(file, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); verify(responder).onDocumentSigned(any()); } diff --git a/src/test/java/digital/slovensko/autogram/SigningJobTests.java b/src/test/java/digital/slovensko/autogram/SigningJobTests.java index 1b636496..19aa6804 100644 --- a/src/test/java/digital/slovensko/autogram/SigningJobTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningJobTests.java @@ -52,7 +52,7 @@ void testEnd2EndHtmlTransformationEncoding() throws IOException, RequestValidati null, null); var signRequestBody = new SignRequestBody(new Document(content), ssParams, "application/xml;base64"); - var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); + var job = SigningJob.build(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); Visualization visualization = null; try { visualization = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index 1fbc3ea3..c3f02739 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -72,7 +72,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce document, null, true); - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -149,7 +149,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio document, null, true); - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { From 0a38cb2445ef659ec42d576fe6e4d705dfd010e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Fri, 15 Nov 2024 19:12:01 +0100 Subject: [PATCH 27/50] Revert "mv buildSigningJobFromFile to Autogram" This reverts commit d6660e17c088687cb7fcc20fa643550fc2ec1a4a. --- .../slovensko/autogram/core/Autogram.java | 9 --------- .../slovensko/autogram/core/SigningJob.java | 16 ++++++++++++++-- .../slovensko/autogram/server/SignEndpoint.java | 2 +- .../autogram/ui/BatchGuiFileResponder.java | 2 +- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../autogram/ui/gui/MainMenuController.java | 2 +- .../slovensko/autogram/AutogramTests.java | 10 +++++----- .../slovensko/autogram/SigningJobTests.java | 2 +- .../slovensko/autogram/TransformationTests.java | 4 ++-- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 02fe1ff3..fc105c4d 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -9,7 +9,6 @@ import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; import digital.slovensko.autogram.util.PDFUtils; -import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.pdfa.PDFAStructureValidator; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; @@ -83,14 +82,6 @@ public void handleProtectedPdfDocument(AutogramDocument document) { } } - public SigningJob buildSigningJobFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { - var document = SigningJob.createDSSFileDocumentFromFile(file); - handleProtectedPdfDocument(document); - - var parameters = SigningJob.getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); - return SigningJob.build(document, parameters, responder); - } - public void wrapInWorkThread(Runnable callback) { ui.onWorkThreadDo(callback); } diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 21a349af..f17df865 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -168,7 +168,7 @@ else if (isTxt(fileDocument.getMimeType())) return new AutogramDocument(fileDocument); } - public static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { + private static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { DSSDocument document = autogramDocument.getDSSDocument(); if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); @@ -184,7 +184,19 @@ public static SigningJob build(AutogramDocument autogramDocument, SigningParamet return new SigningJob(autogramDocument, params, responder); } - public static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + public static SigningJob buildFromRequest(AutogramDocument document, SigningParameters params, Responder responder) { + return build(document, params, responder); + } + + public static SigningJob buildFromFile(File file, Autogram autogram, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + var document = createDSSFileDocumentFromFile(file); + autogram.handleProtectedPdfDocument(document); + + var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); + return build(document, parameters, responder); + } + + private static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index d11d4ab6..2b88a0c4 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -31,7 +31,7 @@ public void handle(HttpExchange exchange) throws IOException { var responder = body.getBatchId() == null ? new ServerResponder(exchange) : new ResponderInBatch(new ServerResponder(exchange), autogram.getBatch(body.getBatchId())); - var job = SigningJob.build(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); + var job = SigningJob.buildFromRequest(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); if (body.getBatchId() != null) autogram.batchSign(job, body.getBatchId()); diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index afc6ec23..9ad64207 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -65,7 +65,7 @@ public void onBatchStartSuccess(Batch batch) { onAllFilesSigned(batch); }), batch); - var job = autogram.buildSigningJobFromFile(file, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); + var job = SigningJob.buildFromFile(file, autogram, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); } catch (DSSException e) { autogram.onSigningFailed(AutogramException.createFromDSSException(e)); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 7339207f..5d6bf6e1 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -31,7 +31,7 @@ public static void start(CommandLine cmd) { var source = settings.getSource(); var sourceList = source.isDirectory() ? source.listFiles() : new File[] { source }; var jobs = Arrays.stream(sourceList).filter(f -> f.isFile()) - .map(f -> autogram.buildSigningJobFromFile(f, new SaveFileResponder(f, autogram, targetPathBuilder), + .map(f -> SigningJob.buildFromFile(f, autogram, new SaveFileResponder(f, autogram, targetPathBuilder), settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), settings.getTspSource(), settings.isPlainXmlEnabled())) .toList(); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index b15fb0d6..71a0f019 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -114,7 +114,7 @@ private void signFiles(List list) { autogram.wrapInWorkThread(() -> { try { - var job = autogram.buildSigningJobFromFile(file, + var job = SigningJob.buildFromFile(file, autogram, new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index a600f513..78f02993 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -53,7 +53,7 @@ void testSignAsiceXadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -69,7 +69,7 @@ void testSignNonEformHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -92,7 +92,7 @@ void testSignAsiceCadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); } @ParameterizedTest @@ -106,7 +106,7 @@ void testSignPadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -137,7 +137,7 @@ void testSignBuildFromFileHappyScenario(InMemoryDocument document) throws IOExce var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(autogram.buildSigningJobFromFile(file, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); + key -> autogram.sign(SigningJob.buildFromFile(file, autogram, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); verify(responder).onDocumentSigned(any()); } diff --git a/src/test/java/digital/slovensko/autogram/SigningJobTests.java b/src/test/java/digital/slovensko/autogram/SigningJobTests.java index 19aa6804..1b636496 100644 --- a/src/test/java/digital/slovensko/autogram/SigningJobTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningJobTests.java @@ -52,7 +52,7 @@ void testEnd2EndHtmlTransformationEncoding() throws IOException, RequestValidati null, null); var signRequestBody = new SignRequestBody(new Document(content), ssParams, "application/xml;base64"); - var job = SigningJob.build(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); + var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); Visualization visualization = null; try { visualization = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index c3f02739..1fbc3ea3 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -72,7 +72,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce document, null, true); - SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -149,7 +149,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio document, null, true); - SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { From 1a51bcad58b55bb7ece25194427726e8382496bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 09:46:33 +0100 Subject: [PATCH 28/50] Revert "Revert "mv buildSigningJobFromFile to Autogram"" This reverts commit 0a38cb2445ef659ec42d576fe6e4d705dfd010e5. --- .../slovensko/autogram/core/Autogram.java | 9 +++++++++ .../slovensko/autogram/core/SigningJob.java | 16 ++-------------- .../slovensko/autogram/server/SignEndpoint.java | 2 +- .../autogram/ui/BatchGuiFileResponder.java | 2 +- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../autogram/ui/gui/MainMenuController.java | 2 +- .../slovensko/autogram/AutogramTests.java | 10 +++++----- .../slovensko/autogram/SigningJobTests.java | 2 +- .../slovensko/autogram/TransformationTests.java | 4 ++-- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index fc105c4d..02fe1ff3 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -9,6 +9,7 @@ import digital.slovensko.autogram.ui.UI; import digital.slovensko.autogram.util.Logging; import digital.slovensko.autogram.util.PDFUtils; +import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.model.DSSException; import eu.europa.esig.dss.pdfa.PDFAStructureValidator; import eu.europa.esig.dss.spi.x509.tsp.TSPSource; @@ -82,6 +83,14 @@ public void handleProtectedPdfDocument(AutogramDocument document) { } } + public SigningJob buildSigningJobFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + var document = SigningJob.createDSSFileDocumentFromFile(file); + handleProtectedPdfDocument(document); + + var parameters = SigningJob.getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); + return SigningJob.build(document, parameters, responder); + } + public void wrapInWorkThread(Runnable callback) { ui.onWorkThreadDo(callback); } diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index f17df865..21a349af 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -168,7 +168,7 @@ else if (isTxt(fileDocument.getMimeType())) return new AutogramDocument(fileDocument); } - private static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { + public static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { DSSDocument document = autogramDocument.getDSSDocument(); if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); @@ -184,19 +184,7 @@ private static SigningJob build(AutogramDocument autogramDocument, SigningParame return new SigningJob(autogramDocument, params, responder); } - public static SigningJob buildFromRequest(AutogramDocument document, SigningParameters params, Responder responder) { - return build(document, params, responder); - } - - public static SigningJob buildFromFile(File file, Autogram autogram, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { - var document = createDSSFileDocumentFromFile(file); - autogram.handleProtectedPdfDocument(document); - - var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource, plainXmlEnabled); - return build(document, parameters, responder); - } - - private static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { + public static SigningParameters getParametersForFile(AutogramDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource, boolean plainXmlEnabled) { var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: diff --git a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java index 2b88a0c4..d11d4ab6 100644 --- a/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java +++ b/src/main/java/digital/slovensko/autogram/server/SignEndpoint.java @@ -31,7 +31,7 @@ public void handle(HttpExchange exchange) throws IOException { var responder = body.getBatchId() == null ? new ServerResponder(exchange) : new ResponderInBatch(new ServerResponder(exchange), autogram.getBatch(body.getBatchId())); - var job = SigningJob.buildFromRequest(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); + var job = SigningJob.build(body.getDocument(), body.getParameters(autogram.getTspSource(), autogram.isPlainXmlEnabled()), responder); if (body.getBatchId() != null) autogram.batchSign(job, body.getBatchId()); diff --git a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java index 9ad64207..afc6ec23 100644 --- a/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java +++ b/src/main/java/digital/slovensko/autogram/ui/BatchGuiFileResponder.java @@ -65,7 +65,7 @@ public void onBatchStartSuccess(Batch batch) { onAllFilesSigned(batch); }), batch); - var job = SigningJob.buildFromFile(file, autogram, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); + var job = autogram.buildSigningJobFromFile(file, responder, checkPDFACompliance, pDFSignatureLevel, isEn319132, tspSource, plainXmlEnabled); autogram.batchSign(job, batch.getBatchId()); } catch (DSSException e) { autogram.onSigningFailed(AutogramException.createFromDSSException(e)); diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 5d6bf6e1..7339207f 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -31,7 +31,7 @@ public static void start(CommandLine cmd) { var source = settings.getSource(); var sourceList = source.isDirectory() ? source.listFiles() : new File[] { source }; var jobs = Arrays.stream(sourceList).filter(f -> f.isFile()) - .map(f -> SigningJob.buildFromFile(f, autogram, new SaveFileResponder(f, autogram, targetPathBuilder), + .map(f -> autogram.buildSigningJobFromFile(f, new SaveFileResponder(f, autogram, targetPathBuilder), settings.isPdfaCompliance(), settings.getSignatureLevel(), settings.isEn319132(), settings.getTspSource(), settings.isPlainXmlEnabled())) .toList(); diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java index 71a0f019..b15fb0d6 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/MainMenuController.java @@ -114,7 +114,7 @@ private void signFiles(List list) { autogram.wrapInWorkThread(() -> { try { - var job = SigningJob.buildFromFile(file, autogram, + var job = autogram.buildSigningJobFromFile(file, new SaveFileResponder(file, autogram, userSettings.shouldSignPDFAsPades()), userSettings.isPdfaCompliance(), userSettings.getSignatureLevel(), userSettings.isEn319132(), tspSource, userSettings.isPlainXmlEnabled()); diff --git a/src/test/java/digital/slovensko/autogram/AutogramTests.java b/src/test/java/digital/slovensko/autogram/AutogramTests.java index 78f02993..a600f513 100644 --- a/src/test/java/digital/slovensko/autogram/AutogramTests.java +++ b/src/test/java/digital/slovensko/autogram/AutogramTests.java @@ -53,7 +53,7 @@ void testSignAsiceXadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -69,7 +69,7 @@ void testSignNonEformHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -92,7 +92,7 @@ void testSignAsiceCadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); } @ParameterizedTest @@ -106,7 +106,7 @@ void testSignPadesHappyScenario(DSSDocument document) { var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromRequest(new AutogramDocument(document), parameters, responder), key)); + key -> autogram.sign(SigningJob.build(new AutogramDocument(document), parameters, responder), key)); verify(responder).onDocumentSigned(any()); } @@ -137,7 +137,7 @@ void testSignBuildFromFileHappyScenario(InMemoryDocument document) throws IOExce var responder = mock(Responder.class); autogram.pickSigningKeyAndThen( - key -> autogram.sign(SigningJob.buildFromFile(file, autogram, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); + key -> autogram.sign(autogram.buildSigningJobFromFile(file, responder, false, SignatureLevel.XAdES_BASELINE_B, false, null, false), key)); verify(responder).onDocumentSigned(any()); } diff --git a/src/test/java/digital/slovensko/autogram/SigningJobTests.java b/src/test/java/digital/slovensko/autogram/SigningJobTests.java index 1b636496..19aa6804 100644 --- a/src/test/java/digital/slovensko/autogram/SigningJobTests.java +++ b/src/test/java/digital/slovensko/autogram/SigningJobTests.java @@ -52,7 +52,7 @@ void testEnd2EndHtmlTransformationEncoding() throws IOException, RequestValidati null, null); var signRequestBody = new SignRequestBody(new Document(content), ssParams, "application/xml;base64"); - var job = SigningJob.buildFromRequest(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); + var job = SigningJob.build(signRequestBody.getDocument(), signRequestBody.getParameters(null, true), null); Visualization visualization = null; try { visualization = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); diff --git a/src/test/java/digital/slovensko/autogram/TransformationTests.java b/src/test/java/digital/slovensko/autogram/TransformationTests.java index 1fbc3ea3..c3f02739 100644 --- a/src/test/java/digital/slovensko/autogram/TransformationTests.java +++ b/src/test/java/digital/slovensko/autogram/TransformationTests.java @@ -72,7 +72,7 @@ void testSigningJobTransformToHtml() throws IOException, ParserConfigurationExce document, null, true); - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { @@ -149,7 +149,7 @@ void testSigningJobTransformSb() throws IOException, ParserConfigurationExceptio document, null, true); - SigningJob job = SigningJob.buildFromRequest(new AutogramDocument(document), params, dummyResponder); + SigningJob job = SigningJob.build(new AutogramDocument(document), params, dummyResponder); var visualizedDocument = DocumentVisualizationBuilder.fromJob(job, UserSettings.load()); if (visualizedDocument instanceof HTMLVisualization d) { From d9369777806f332a75a5f1f5ebe7312cb00699e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 09:55:04 +0100 Subject: [PATCH 29/50] lock ubuntu runner version --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 28f20fd6..88786509 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,7 +17,7 @@ jobs: strategy: matrix: config: - - os: ubuntu-latest + - os: ubuntu-24.04 - os: macos-latest - os: windows-latest From 6f99e223e8a6a83b3c68e0c301791961db789ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 10:45:56 +0100 Subject: [PATCH 30/50] bump gh actions --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 88786509..634a76b8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,22 +17,22 @@ jobs: strategy: matrix: config: - - os: ubuntu-24.04 + - os: ubuntu-latest - os: macos-latest - os: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17.0.7+7' distribution: 'liberica' java-package: 'jdk+fx' - name: Cache local Maven repository and JDK cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.m2/repository From a5d58991c14abdfc786973b92d0d41d14d5d7515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 10:47:36 +0100 Subject: [PATCH 31/50] temp rm cache from gh actions --- .github/workflows/test.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 634a76b8..d15a1a57 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,16 +31,16 @@ jobs: distribution: 'liberica' java-package: 'jdk+fx' - - name: Cache local Maven repository and JDK cache - uses: actions/cache@v4 - with: - path: | - ~/.m2/repository - target/jdkCache - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - +# - name: Cache local Maven repository and JDK cache +# uses: actions/cache@v4 +# with: +# path: | +# ~/.m2/repository +# target/jdkCache +# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} +# restore-keys: | +# ${{ runner.os }}-maven- +# - name: Run tests run: ./mvnw test env: From 7d94479039ff3ff723713fd891088ea31c81af68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 10:56:35 +0100 Subject: [PATCH 32/50] bump jdk minor version --- .github/workflows/package.yaml | 4 ++-- .github/workflows/test.yaml | 2 +- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index 0727c5cb..0807bf99 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -91,7 +91,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: "17.0.7+7" + java-version: "17.0.13+12" distribution: "liberica" java-package: "jdk+fx" @@ -180,7 +180,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: "17.0.7+7" + java-version: "17.0.13+12" distribution: "liberica" java-package: "jdk+fx" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d15a1a57..4af25a7e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -27,7 +27,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: '17.0.7+7' + java-version: '17.0.13+12' distribution: 'liberica' java-package: 'jdk+fx' diff --git a/pom.xml b/pom.xml index f423284d..11eb58cc 100644 --- a/pom.xml +++ b/pom.xml @@ -319,7 +319,7 @@ BELLSOFT jdk - 17.0.7+7 + 17.0.13+12 amd64-full From 1cc94b59994f3778ba9aa0c820eeb3fa0633c1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 11:08:01 +0100 Subject: [PATCH 33/50] use system jdk in github actions --- .github/workflows/test.yaml | 2 +- pom.xml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4af25a7e..dbd429cc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,7 +42,7 @@ jobs: # ${{ runner.os }}-maven- # - name: Run tests - run: ./mvnw test + run: ./mvnw test -P system-jdk env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/pom.xml b/pom.xml index 11eb58cc..660c59e8 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,7 @@ 2.2 1.3.0 HttpSmokeTest + false @@ -313,6 +314,7 @@ cache-jdk + ${skip-jdk-cache} jlink.jdk.path ${project.build.directory}${file.separator}jdkCache ${github.auth} @@ -504,6 +506,14 @@ + + system-jdk + + ${env.JAVA_HOME} + true + + + smoke From 6c15d52c470600ad9cab30a3b3644b6890959fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 11:12:12 +0100 Subject: [PATCH 34/50] use debug logging in gh actions --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dbd429cc..72748609 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,7 +42,7 @@ jobs: # ${{ runner.os }}-maven- # - name: Run tests - run: ./mvnw test -P system-jdk + run: ./mvnw test -e -P system-jdk env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e5870868ae7dbb4cfbbf590480e98aca2792ed96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 11:24:41 +0100 Subject: [PATCH 35/50] commit classpath --- .classpath | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.classpath b/.classpath index d725c2db..a9fc18c9 100644 --- a/.classpath +++ b/.classpath @@ -22,6 +22,8 @@ + + From 5a1a71efb1b8fca15b545e75c474dc2a54dc305f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 11:40:06 +0100 Subject: [PATCH 36/50] add full stack trace gh actions --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 72748609..e851473a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,7 +42,7 @@ jobs: # ${{ runner.os }}-maven- # - name: Run tests - run: ./mvnw test -e -P system-jdk + run: ./mvnw test -e -X -P system-jdk env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 0df85f7ed533505393206baf04a8386a77e48c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 11:55:13 +0100 Subject: [PATCH 37/50] ignore classpath --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5b6c02c2..4e5aa818 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ secret /fakeTokenDriver /cache + +.classpath From eebceae16bed92af8b263a3281bd56f6d04d80a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 12:23:58 +0100 Subject: [PATCH 38/50] Revert "use system jdk in github actions" This reverts commit 1cc94b59994f3778ba9aa0c820eeb3fa0633c1d5. --- .github/workflows/test.yaml | 2 +- pom.xml | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e851473a..7e897621 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,7 +42,7 @@ jobs: # ${{ runner.os }}-maven- # - name: Run tests - run: ./mvnw test -e -X -P system-jdk + run: ./mvnw test -e env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/pom.xml b/pom.xml index d7d22be6..0e279a68 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,6 @@ 2.2 1.3.0 HttpSmokeTest - false @@ -314,7 +313,6 @@ cache-jdk - ${skip-jdk-cache} jlink.jdk.path ${project.build.directory}${file.separator}jdkCache ${github.auth} @@ -506,14 +504,6 @@ - - system-jdk - - ${env.JAVA_HOME} - true - - - smoke From 5266922a4ed7ad986b4f114ae997e13c64f22e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sat, 16 Nov 2024 12:35:54 +0100 Subject: [PATCH 39/50] revert liberica version --- .github/workflows/package.yaml | 4 ++-- .github/workflows/test.yaml | 2 +- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index 0807bf99..0727c5cb 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -91,7 +91,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: "17.0.13+12" + java-version: "17.0.7+7" distribution: "liberica" java-package: "jdk+fx" @@ -180,7 +180,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: "17.0.13+12" + java-version: "17.0.7+7" distribution: "liberica" java-package: "jdk+fx" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7e897621..3f0b6f70 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -27,7 +27,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: '17.0.13+12' + java-version: '17.0.7+7' distribution: 'liberica' java-package: 'jdk+fx' diff --git a/pom.xml b/pom.xml index 0e279a68..901644d8 100644 --- a/pom.xml +++ b/pom.xml @@ -319,7 +319,7 @@ BELLSOFT jdk - 17.0.13+12 + 17.0.7+7 amd64-full From c06499295e6223b3432d61ce9285b860be4372ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sun, 17 Nov 2024 20:24:42 +0100 Subject: [PATCH 40/50] fix compilation error --- .../core/visualization/DocumentVisualizationBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index 7304d65f..d71a5a9a 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -59,7 +59,7 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); if (transformationOutputMimeType.equals("XHTML")) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); if (transformationOutputMimeType.equals("TXT")) return new PlainTextVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); From a0a9e42e8534f7ade3865ea2f7dcef61386b261b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Sun, 17 Nov 2024 20:42:07 +0100 Subject: [PATCH 41/50] make test pipeline faster --- .github/workflows/test.yaml | 24 +++++++++++------------- pom.xml | 10 ++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3f0b6f70..d18e0e29 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,20 +31,18 @@ jobs: distribution: 'liberica' java-package: 'jdk+fx' -# - name: Cache local Maven repository and JDK cache -# uses: actions/cache@v4 -# with: -# path: | -# ~/.m2/repository -# target/jdkCache -# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} -# restore-keys: | -# ${{ runner.os }}-maven- -# + - name: Cache local Maven repository and JDK cache + uses: actions/cache@v4 + with: + path: | + ~/.m2/repository + target/jdkCache + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Run tests - run: ./mvnw test -e - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./mvnw test -P system-jdk - name: JaCoCo Code Coverage Report id: jacoco_report diff --git a/pom.xml b/pom.xml index 901644d8..d4002164 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,7 @@ 2.2 1.3.0 HttpSmokeTest + false @@ -313,6 +314,7 @@ cache-jdk + ${skip-jdk-cache} jlink.jdk.path ${project.build.directory}${file.separator}jdkCache ${github.auth} @@ -504,6 +506,14 @@ + + system-jdk + + ${env.JAVA_HOME} + true + + + smoke From b69a83b597d325377ce8a0389053f9c31c97c23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 16:57:31 +0100 Subject: [PATCH 42/50] refactor: cleanup --- .../slovensko/autogram/core/Autogram.java | 2 +- .../slovensko/autogram/core/SigningJob.java | 6 +++--- .../DocumentVisualizationBuilder.java | 16 ++++++++-------- .../core/visualization/PDFVisualization.java | 2 +- .../autogram/model/AutogramDocument.java | 15 +++++++++++++++ .../autogram/server/dto/SignRequestBody.java | 2 +- .../slovensko/autogram/ui/cli/CliApp.java | 2 +- .../digital/slovensko/autogram/ui/cli/CliUI.java | 2 +- .../digital/slovensko/autogram/ui/gui/GUI.java | 4 ++-- 9 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 02fe1ff3..3ee36b50 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -184,7 +184,7 @@ public void batchSign(SigningJob job, String batchId) { ui.onWorkThreadDo(() -> { try { signCommonAndThen(job, batch.getSigningKey(), (jobNew) -> { - Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getDSSDocument().getName()); + Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getName()); }); } catch (AutogramException e) { job.onDocumentSignFailed(e); diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 21a349af..569b415f 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -46,7 +46,7 @@ public int getVisualizationWidth() { } public void signWithKeyAndRespond(SigningKey key) throws InterruptedException, AutogramException { - Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getDSSDocument().getName()); + Logging.log("Signing Job: " + this.hashCode() + " file " + getDocument().getName()); boolean isContainer = getParameters().getContainer() != null; var doc = switch (getParameters().getSignatureType()) { case XAdES -> isContainer ? signDocumentAsAsiCWithXAdeS(key) : signDocumentAsXAdeS(key); @@ -197,7 +197,7 @@ public static SigningParameters getParametersForFile(AutogramDocument document, ; } - if (isPDF(document.getDSSDocument().getMimeType())) switch (signatureType) { + if (isPDF(document.getMimeType())) switch (signatureType) { case PAdES_BASELINE_B: return SigningParameters.buildForPDF(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource); case XAdES_BASELINE_B: @@ -212,6 +212,6 @@ public static SigningParameters getParametersForFile(AutogramDocument document, } public boolean shouldCheckPDFCompliance() { - return parameters.getCheckPDFACompliance() && isPDF(document.getDSSDocument().getMimeType()); + return parameters.getCheckPDFACompliance() && isPDF(document.getMimeType()); } } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index d71a5a9a..9f78b550 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -42,7 +42,7 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti throws IOException, ParserConfigurationException, SAXException { var documentToDisplay = document; - if (isAsice(documentToDisplay.getDSSDocument().getMimeType())) { + if (isAsice(documentToDisplay.getMimeType())) { try { documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document.getDSSDocument())); } catch (AutogramException e) { @@ -52,7 +52,7 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti var transformation = parameters.getTransformation(); - if (isDocumentSupportingTransformation(documentToDisplay.getDSSDocument()) && isTranformationAvailable(transformation)) { + if (isDocumentSupportingTransformation(documentToDisplay) && isTranformationAvailable(transformation)) { var transformationOutputMimeType = parameters.getXsltDestinationType(); if (transformationOutputMimeType.equals("HTML")) @@ -67,16 +67,16 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti return new UnsupportedVisualization(job); } - if (documentToDisplay.getDSSDocument().getMimeType().equals(MimeTypeEnum.HTML)) + if (documentToDisplay.getMimeType().equals(MimeTypeEnum.HTML)) return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); - if (isTxt(documentToDisplay.getDSSDocument().getMimeType())) - return new PlainTextVisualization(new String(documentToDisplay.getDSSDocument().openStream().readAllBytes(), StandardCharsets.UTF_8), job); + if (isTxt(documentToDisplay.getMimeType())) + return new PlainTextVisualization(new String(documentToDisplay.openStream().readAllBytes(), StandardCharsets.UTF_8), job); - if (isPDF(documentToDisplay.getDSSDocument().getMimeType())) + if (isPDF(documentToDisplay.getMimeType())) return new PDFVisualization(documentToDisplay, job, userSettings); - if (isImage(documentToDisplay.getDSSDocument().getMimeType())) + if (isImage(documentToDisplay.getMimeType())) return new ImageVisualization(documentToDisplay.getDSSDocument(), job); return new UnsupportedVisualization(job); @@ -86,7 +86,7 @@ private boolean isTranformationAvailable(String transformation) { return transformation != null; } - private boolean isDocumentSupportingTransformation(DSSDocument document) { + private boolean isDocumentSupportingTransformation(AutogramDocument document) { return isXDC(document.getMimeType()) || isXML(document.getMimeType()); } } diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java index 41ffe1f4..e333d7f5 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/PDFVisualization.java @@ -26,7 +26,7 @@ public PDFVisualization(AutogramDocument document, SigningJob job, UserSettings } private ArrayList getPdfImages() throws IOException { - var pdfDocument = PDDocument.load(this.document.getDSSDocument().openStream(), new String(this.document.getOpenDocumentPassword())); + var pdfDocument = PDDocument.load(this.document.openStream(), new String(this.document.getOpenDocumentPassword())); var pdfRenderer = new PDFRenderer(pdfDocument); var divs = new ArrayList(); for (int page = 0; page < pdfDocument.getNumberOfPages(); ++page) { diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index d8845b18..bbaa519f 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -1,7 +1,10 @@ package digital.slovensko.autogram.model; +import eu.europa.esig.dss.enumerations.MimeType; import eu.europa.esig.dss.model.DSSDocument; +import java.io.InputStream; + public class AutogramDocument { private final DSSDocument document; @@ -36,6 +39,18 @@ public char[] getSigningPassword() { return hasOpenDocumentPassword() ? openDocumentPassword : masterPassword; } + public String getName() { + return document.getName(); + } + + public MimeType getMimeType() { + return document.getMimeType(); + } + + public InputStream openStream() { + return document.openStream(); + } + public DSSDocument getDSSDocument() { return document; } diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index 19b387a0..65cc897e 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -70,7 +70,7 @@ public void validateSigningParameters() throws RequestValidationException, Malfo if (parameters == null) throw new RequestValidationException("Parameters are required", ""); - parameters.validate(getDocument().getDSSDocument().getMimeType()); + parameters.validate(getDocument().getMimeType()); } public SigningParameters getParameters(TSPSource tspSource, boolean plainXmlEnabled) { diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java index 7339207f..69ee9869 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliApp.java @@ -37,7 +37,7 @@ public static void start(CommandLine cmd) { .toList(); if (settings.isPdfaCompliance()) { jobs.forEach(job -> { - System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getDSSDocument().getName()); + System.out.println("Checking PDF/A file compatibility for " + job.getDocument().getName()); autogram.checkPDFACompliance(job); }); } diff --git a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java index 0fcfecbc..49a459bd 100644 --- a/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/cli/CliUI.java @@ -47,7 +47,7 @@ public void startSigning(SigningJob job, Autogram autogram) { } private void sign(SigningJob job, Autogram autogram) { - System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getDSSDocument().getName(), nJobsSigned++, + System.out.println("Starting signing file \"%s\" [%d/%d]".formatted(job.getDocument().getName(), nJobsSigned++, nJobsTotal)); autogram.sign(job, activeKey); } diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java index 0b7c3f23..cecedf04 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/GUI.java @@ -341,8 +341,8 @@ public void onSignatureCheckCompleted(ValidationReports reports) { public void showVisualization(Visualization visualization, Autogram autogram) { var title = "Dokument"; - if (visualization.getJob().getDocument().getDSSDocument().getName() != null) - title = "Dokument " + visualization.getJob().getDocument().getDSSDocument().getName(); + if (visualization.getJob().getDocument().getName() != null) + title = "Dokument " + visualization.getJob().getDocument().getName(); var controller = new SigningDialogController(visualization, autogram, this, title, userSettings.isSignaturesValidity()); jobControllers.put(visualization.getJob(), controller); From 577cd03092ad781e23901e2239a4b0c4914c96ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 16:58:57 +0100 Subject: [PATCH 43/50] refactor: cleanup --- .classpath | 1 - 1 file changed, 1 deletion(-) diff --git a/.classpath b/.classpath index a9fc18c9..fb66acc3 100644 --- a/.classpath +++ b/.classpath @@ -22,7 +22,6 @@ - From d230231153c3520703a82ec2c15c33ab71ccb42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 16:59:22 +0100 Subject: [PATCH 44/50] refactor: cleanup --- .classpath | 1 - 1 file changed, 1 deletion(-) diff --git a/.classpath b/.classpath index fb66acc3..d725c2db 100644 --- a/.classpath +++ b/.classpath @@ -22,7 +22,6 @@ - From 10bd450c5f7a2bbeb2cdd2982ebc01cf9ad26a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 16:59:52 +0100 Subject: [PATCH 45/50] refactor: cleanup --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index d4002164..901644d8 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,6 @@ 2.2 1.3.0 HttpSmokeTest - false @@ -314,7 +313,6 @@ cache-jdk - ${skip-jdk-cache} jlink.jdk.path ${project.build.directory}${file.separator}jdkCache ${github.auth} @@ -506,14 +504,6 @@ - - system-jdk - - ${env.JAVA_HOME} - true - - - smoke From 91dd90d115fa7597e2af8e591e86a77467ffe54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 17:00:12 +0100 Subject: [PATCH 46/50] refactor: cleanup --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4e5aa818..5b6c02c2 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,3 @@ secret /fakeTokenDriver /cache - -.classpath From 5b6c2a8d01d8b073825bdabec021ac87fb3b5fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 17:01:01 +0100 Subject: [PATCH 47/50] revert: test ci --- .github/workflows/test.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d18e0e29..173f66f8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,17 +22,17 @@ jobs: - os: windows-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - name: Set up JDK - uses: actions/setup-java@v4 + uses: actions/setup-java@v3 with: java-version: '17.0.7+7' distribution: 'liberica' java-package: 'jdk+fx' - name: Cache local Maven repository and JDK cache - uses: actions/cache@v4 + uses: actions/cache@v3 with: path: | ~/.m2/repository @@ -42,7 +42,9 @@ jobs: ${{ runner.os }}-maven- - name: Run tests - run: ./mvnw test -P system-jdk + run: ./mvnw test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: JaCoCo Code Coverage Report id: jacoco_report @@ -65,4 +67,4 @@ jobs: with: name: code-coverage-report-markdown path: ./*/coverage-results.md - retention-days: 1 + retention-days: 1 \ No newline at end of file From 9e84caf9db5614e4aa98e93e27adbc69842d2e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 17:05:10 +0100 Subject: [PATCH 48/50] feat: make autogram document implements dssdocument --- .../slovensko/autogram/core/Autogram.java | 6 ++-- .../slovensko/autogram/core/SigningJob.java | 36 +++++++++---------- .../DocumentVisualizationBuilder.java | 12 +++---- .../autogram/model/AutogramDocument.java | 30 +++++++++++++++- .../autogram/server/dto/SignRequestBody.java | 2 +- .../slovensko/autogram/util/DSSUtils.java | 20 +++++------ 6 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/Autogram.java b/src/main/java/digital/slovensko/autogram/core/Autogram.java index 3ee36b50..4cd65063 100644 --- a/src/main/java/digital/slovensko/autogram/core/Autogram.java +++ b/src/main/java/digital/slovensko/autogram/core/Autogram.java @@ -64,7 +64,7 @@ public void checkPDFACompliance(SigningJob job) { return; } - var result = new PDFAStructureValidator().validate(job.getDocument().getDSSDocument()); + var result = new PDFAStructureValidator().validate(job.getDocument()); if (!result.isCompliant()) { ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); } @@ -72,11 +72,11 @@ public void checkPDFACompliance(SigningJob job) { } public void handleProtectedPdfDocument(AutogramDocument document) { - var protection = PDFUtils.determinePDFProtection(document.getDSSDocument()); + var protection = PDFUtils.determinePDFProtection(document); if (protection == PDFUtils.PDFProtection.NONE) return; - var password = ui.getDocumentPassword(document.getDSSDocument()); + var password = ui.getDocumentPassword(document); switch (protection) { case OPEN_DOCUMENT_PASSWORD -> document.setOpenDocumentPassword(password); case MASTER_PASSWORD -> document.setMasterPassword(password); diff --git a/src/main/java/digital/slovensko/autogram/core/SigningJob.java b/src/main/java/digital/slovensko/autogram/core/SigningJob.java index 569b415f..c791c79a 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningJob.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningJob.java @@ -72,10 +72,10 @@ private DSSDocument signDocumentAsCAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { @@ -90,10 +90,10 @@ private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.XAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, getParameters().getDigestAlgorithm()); - return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsXAdeS(SigningKey key) { @@ -106,10 +106,10 @@ private DSSDocument signDocumentAsXAdeS(SigningKey key) { signatureParameters.setCertificateChain(key.getCertificateChain()); signatureParameters.setSignWithExpiredCertificate(true); - var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { @@ -125,10 +125,10 @@ private DSSDocument signDocumentAsASiCWithCAdeS(SigningKey key) { if (signatureParameters.getSignatureLevel().equals(SignatureLevel.CAdES_BASELINE_T)) service.setTspSource(getParameters().getTspSource()); - var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument(), signatureParameters, signatureValue); } private DSSDocument signDocumentAsPAdeS(SigningKey key) { @@ -147,10 +147,10 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { signatureParameters.setContentSize(9472*2); } - var dataToSign = service.getDataToSign(getDocument().getDSSDocument(), signatureParameters); + var dataToSign = service.getDataToSign(getDocument(), signatureParameters); var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); - return service.signDocument(getDocument().getDSSDocument(), signatureParameters, signatureValue); + return service.signDocument(getDocument(), signatureParameters, signatureValue); } public static AutogramDocument createDSSFileDocumentFromFile(File file) { @@ -169,7 +169,7 @@ else if (isTxt(fileDocument.getMimeType())) } public static SigningJob build(AutogramDocument autogramDocument, SigningParameters params, Responder responder) { - DSSDocument document = autogramDocument.getDSSDocument(); + DSSDocument document = autogramDocument; if (params.shouldCreateXdc() && !isXDC(document.getMimeType()) && !isAsice(document.getMimeType())) autogramDocument = new AutogramDocument(XDCBuilder.transform(params, document.getName(), EFormUtils.getXmlFromDocument(document))); @@ -188,27 +188,27 @@ public static SigningParameters getParametersForFile(AutogramDocument document, var level = SignatureValidator.getSignedDocumentSignatureLevel(SignatureValidator.getSignedDocumentSimpleReport(document)); if (level != null) switch (level.getSignatureForm()) { case PAdES: - return SigningParameters.buildForPDF(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); case XAdES: - return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES: - return SigningParameters.buildForASiCWithCAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } if (isPDF(document.getMimeType())) switch (signatureType) { case PAdES_BASELINE_B: - return SigningParameters.buildForPDF(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource); + return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); case XAdES_BASELINE_B: - return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); case CAdES_BASELINE_B: - return SigningParameters.buildForASiCWithCAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithCAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); default: ; } - return SigningParameters.buildForASiCWithXAdES(document.getDSSDocument(), checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); + return SigningParameters.buildForASiCWithXAdES(document, checkPDFACompliance, isEn319132, tspSource, plainXmlEnabled); } public boolean shouldCheckPDFCompliance() { diff --git a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java index 9f78b550..db54690d 100644 --- a/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/visualization/DocumentVisualizationBuilder.java @@ -44,7 +44,7 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti var documentToDisplay = document; if (isAsice(documentToDisplay.getMimeType())) { try { - documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document.getDSSDocument())); + documentToDisplay = new AutogramDocument(AsicContainerUtils.getOriginalDocument(document)); } catch (AutogramException e) { return new UnsupportedVisualization(job); } @@ -56,19 +56,19 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti var transformationOutputMimeType = parameters.getXsltDestinationType(); if (transformationOutputMimeType.equals("HTML")) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); if (transformationOutputMimeType.equals("XHTML")) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); if (transformationOutputMimeType.equals("TXT")) - return new PlainTextVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); + return new PlainTextVisualization(EFormUtils.transform(documentToDisplay, transformation), job); return new UnsupportedVisualization(job); } if (documentToDisplay.getMimeType().equals(MimeTypeEnum.HTML)) - return new HTMLVisualization(EFormUtils.transform(documentToDisplay.getDSSDocument(), transformation), job); + return new HTMLVisualization(EFormUtils.transform(documentToDisplay, transformation), job); if (isTxt(documentToDisplay.getMimeType())) return new PlainTextVisualization(new String(documentToDisplay.openStream().readAllBytes(), StandardCharsets.UTF_8), job); @@ -77,7 +77,7 @@ private Visualization createVisualization(SigningJob job, UserSettings userSetti return new PDFVisualization(documentToDisplay, job, userSettings); if (isImage(documentToDisplay.getMimeType())) - return new ImageVisualization(documentToDisplay.getDSSDocument(), job); + return new ImageVisualization(documentToDisplay, job); return new UnsupportedVisualization(job); } diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index bbaa519f..c7680722 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -1,11 +1,14 @@ package digital.slovensko.autogram.model; +import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeType; import eu.europa.esig.dss.model.DSSDocument; +import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; -public class AutogramDocument { +public class AutogramDocument implements DSSDocument { private final DSSDocument document; private char[] openDocumentPassword = new char[0]; @@ -43,14 +46,39 @@ public String getName() { return document.getName(); } + @Override + public void setName(String s) { + + } + public MimeType getMimeType() { return document.getMimeType(); } + @Override + public void setMimeType(MimeType mimeType) { + document.setMimeType(mimeType); + } + + @Override + public void save(String s) throws IOException { + document.save(s); + } + + @Override + public String getDigest(DigestAlgorithm digestAlgorithm) { + return document.getDigest(digestAlgorithm); + } + public InputStream openStream() { return document.openStream(); } + @Override + public void writeTo(OutputStream outputStream) throws IOException { + document.writeTo(outputStream); + } + public DSSDocument getDSSDocument() { return document; } diff --git a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java index 65cc897e..51f97e7b 100644 --- a/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java +++ b/src/main/java/digital/slovensko/autogram/server/dto/SignRequestBody.java @@ -74,7 +74,7 @@ public void validateSigningParameters() throws RequestValidationException, Malfo } public SigningParameters getParameters(TSPSource tspSource, boolean plainXmlEnabled) { - return parameters.getSigningParameters(isBase64(), getDocument().getDSSDocument(), tspSource, plainXmlEnabled); + return parameters.getSigningParameters(isBase64(), getDocument(), tspSource, plainXmlEnabled); } public String getBatchId() { diff --git a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java index f054b50b..d37f81cc 100644 --- a/src/main/java/digital/slovensko/autogram/util/DSSUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/DSSUtils.java @@ -39,23 +39,23 @@ public static String buildTooltipLabel(DSSPrivateKeyEntry key) { } public static SignedDocumentValidator createDocumentValidator(AutogramDocument document) { - if (new PDFDocumentValidatorFactory().isSupported(document.getDSSDocument())) { - var validator = new PDFDocumentValidator(document.getDSSDocument()); + if (new PDFDocumentValidatorFactory().isSupported(document)) { + var validator = new PDFDocumentValidator(document); validator.setPasswordProtection(document.getOpenDocumentPassword()); return validator; } - if (new XMLDocumentValidatorFactory().isSupported(document.getDSSDocument())) - return new XMLDocumentValidatorFactory().create(document.getDSSDocument()); + if (new XMLDocumentValidatorFactory().isSupported(document)) + return new XMLDocumentValidatorFactory().create(document); - if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document.getDSSDocument())) - return new ASiCContainerWithXAdESValidatorFactory().create(document.getDSSDocument()); + if (new ASiCContainerWithXAdESValidatorFactory().isSupported(document)) + return new ASiCContainerWithXAdESValidatorFactory().create(document); - if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document.getDSSDocument())) - return new ASiCContainerWithCAdESValidatorFactory().create(document.getDSSDocument()); + if (new ASiCContainerWithCAdESValidatorFactory().isSupported(document)) + return new ASiCContainerWithCAdESValidatorFactory().create(document); - if (new CMSDocumentValidatorFactory().isSupported(document.getDSSDocument())) - return new CMSDocumentValidatorFactory().create(document.getDSSDocument()); + if (new CMSDocumentValidatorFactory().isSupported(document)) + return new CMSDocumentValidatorFactory().create(document); return null; } From 5803279a1b280979cba4ad3db897beb87262148a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 17:05:40 +0100 Subject: [PATCH 49/50] feat: make autogram document implements dssdocument --- .../digital/slovensko/autogram/model/AutogramDocument.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java index c7680722..9ae1ca33 100644 --- a/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java +++ b/src/main/java/digital/slovensko/autogram/model/AutogramDocument.java @@ -42,15 +42,17 @@ public char[] getSigningPassword() { return hasOpenDocumentPassword() ? openDocumentPassword : masterPassword; } + @Override public String getName() { return document.getName(); } @Override public void setName(String s) { - + document.setName(s); } + @Override public MimeType getMimeType() { return document.getMimeType(); } @@ -70,6 +72,7 @@ public String getDigest(DigestAlgorithm digestAlgorithm) { return document.getDigest(digestAlgorithm); } + @Override public InputStream openStream() { return document.openStream(); } From 6b0d033fa0b798ab364c777643258196459252ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 18 Dec 2024 17:08:27 +0100 Subject: [PATCH 50/50] refactor: cleanup --- .../digital/slovensko/autogram/core/SigningParameters.java | 1 - .../slovensko/autogram/core/eforms/xdc/XDCBuilder.java | 2 +- .../digital/slovensko/autogram/util/AsicContainerUtils.java | 6 ------ .../java/digital/slovensko/autogram/XDCBuilderTests.java | 1 - 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java index 549668b8..c5f3f634 100644 --- a/src/main/java/digital/slovensko/autogram/core/SigningParameters.java +++ b/src/main/java/digital/slovensko/autogram/core/SigningParameters.java @@ -6,7 +6,6 @@ import digital.slovensko.autogram.core.errors.AutogramException; import digital.slovensko.autogram.core.errors.SigningParametersException; import digital.slovensko.autogram.core.errors.UnknownEformException; -import digital.slovensko.autogram.model.AutogramDocument; import digital.slovensko.autogram.util.AsicContainerUtils; import digital.slovensko.autogram.core.eforms.EFormUtils; import digital.slovensko.autogram.core.eforms.xdc.XDCValidator; diff --git a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java index f596b111..b061a9a6 100644 --- a/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java +++ b/src/main/java/digital/slovensko/autogram/core/eforms/xdc/XDCBuilder.java @@ -11,9 +11,9 @@ import static digital.slovensko.autogram.util.XMLUtils.getSecureDocumentBuilder; import eu.europa.esig.dss.enumerations.DigestAlgorithm; - import eu.europa.esig.dss.model.DSSDocument; import eu.europa.esig.dss.model.InMemoryDocument; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; diff --git a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java index 53af9457..298f3f31 100644 --- a/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java +++ b/src/main/java/digital/slovensko/autogram/util/AsicContainerUtils.java @@ -3,9 +3,7 @@ import digital.slovensko.autogram.core.AutogramMimeType; import digital.slovensko.autogram.core.errors.MultipleOriginalDocumentsFoundException; import digital.slovensko.autogram.core.errors.OriginalDocumentNotFoundException; -import digital.slovensko.autogram.model.AutogramDocument; import eu.europa.esig.dss.asic.xades.ASiCWithXAdESContainerExtractor; -import eu.europa.esig.dss.enumerations.DigestAlgorithm; import eu.europa.esig.dss.enumerations.MimeType; import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.model.DSSDocument; @@ -14,10 +12,6 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - import static digital.slovensko.autogram.core.AutogramMimeType.isXML; public class AsicContainerUtils { diff --git a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java index 0f1f9c63..e344c7c9 100644 --- a/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java +++ b/src/test/java/digital/slovensko/autogram/XDCBuilderTests.java @@ -9,7 +9,6 @@ import eu.europa.esig.dss.enumerations.MimeTypeEnum; import eu.europa.esig.dss.enumerations.SignatureLevel; import eu.europa.esig.dss.enumerations.SignaturePackaging; - import eu.europa.esig.dss.model.InMemoryDocument; import org.junit.jupiter.api.Test;