-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AG-103 Časové pečiatky #341
Changes from 3 commits
93b014f
b40f8cf
62c3223
2e8c881
501676b
c4823ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
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; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
@@ -23,16 +24,18 @@ public class Autogram { | |
private final DriverDetector driverDetector; | ||
private final boolean shouldDisplayVisualizationError; | ||
private final Integer slotId; | ||
private final TSPSource tspSource; | ||
|
||
public Autogram(UI ui, boolean shouldDisplayVisualizationError , DriverDetector driverDetector) { | ||
this(ui, shouldDisplayVisualizationError, driverDetector, -1); | ||
public Autogram(UI ui, boolean shouldDisplayVisualizationError , DriverDetector driverDetector, TSPSource tspSource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu sa nam to zacina kopit a imho by vlastne mal do Autogramu vliezt nejaky settings. To by potom riesilo aj problem, ze potrebujeme restart. |
||
this(ui, shouldDisplayVisualizationError, driverDetector, -1, tspSource); | ||
} | ||
|
||
public Autogram(UI ui, boolean shouldDisplayVisualizationError , DriverDetector driverDetector, Integer slotId) { | ||
public Autogram(UI ui, boolean shouldDisplayVisualizationError , DriverDetector driverDetector, Integer slotId, TSPSource tspSource) { | ||
this.ui = ui; | ||
this.driverDetector = driverDetector; | ||
this.slotId = slotId; | ||
this.shouldDisplayVisualizationError = shouldDisplayVisualizationError; | ||
this.tspSource = tspSource; | ||
} | ||
|
||
public void sign(SigningJob job) { | ||
|
@@ -234,4 +237,8 @@ public void initializeSignatureValidator(ScheduledExecutorService scheduledExecu | |
scheduledExecutorService.scheduleAtFixedRate(() -> SignatureValidator.getInstance().refresh(), | ||
480, 480, java.util.concurrent.TimeUnit.MINUTES); | ||
} | ||
|
||
public TSPSource getTspSource() { | ||
return tspSource; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package digital.slovensko.autogram.core; | ||
|
||
import java.io.File; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
import digital.slovensko.autogram.core.eforms.EFormUtils; | ||
import digital.slovensko.autogram.core.eforms.XDCBuilder; | ||
|
@@ -10,10 +11,15 @@ | |
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.DigestAlgorithm; | ||
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.service.http.commons.TimestampDataLoader; | ||
import eu.europa.esig.dss.service.tsp.OnlineTSPSource; | ||
import eu.europa.esig.dss.spi.DSSUtils; | ||
import eu.europa.esig.dss.spi.x509.tsp.TSPSource; | ||
import eu.europa.esig.dss.validation.CommonCertificateVerifier; | ||
import eu.europa.esig.dss.xades.signature.XAdESService; | ||
|
||
|
@@ -85,6 +91,9 @@ private DSSDocument signDocumentAsAsiCWithXAdeS(SigningKey key) { | |
signatureParameters.setCertificateChain(key.getCertificateChain()); | ||
signatureParameters.setSignWithExpiredCertificate(true); | ||
|
||
if (signatureParameters.getSignatureLevel().equals(SignatureLevel.XAdES_BASELINE_T)) | ||
service.setTspSource(getParameters().getTspSource()); | ||
|
||
var dataToSign = service.getDataToSign(getDocument(), signatureParameters); | ||
var signatureValue = key.sign(dataToSign, getParameters().getDigestAlgorithm()); | ||
|
||
|
@@ -133,6 +142,9 @@ private DSSDocument signDocumentAsPAdeS(SigningKey key) { | |
signatureParameters.setCertificateChain(key.getCertificateChain()); | ||
signatureParameters.setSignWithExpiredCertificate(true); | ||
|
||
if (signatureParameters.getSignatureLevel().equals(SignatureLevel.PAdES_BASELINE_T)) | ||
service.setTspSource(getParameters().getTspSource()); | ||
|
||
var dataToSign = service.getDataToSign(getDocument(), signatureParameters); | ||
var signatureValue = key.sign(dataToSign, jobParameters.getDigestAlgorithm()); | ||
|
||
|
@@ -164,44 +176,38 @@ public static SigningJob buildFromRequest(DSSDocument document, SigningParameter | |
return build(document, params, responder); | ||
} | ||
|
||
public static SigningJob buildFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132) { | ||
var document = createDSSFileDocumentFromFile(file); | ||
var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132); | ||
return build(document, parameters, responder); | ||
} | ||
|
||
public static SigningJob buildFromFileBatch(File file, Autogram autogram, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132) { | ||
public static SigningJob buildFromFile(File file, Responder responder, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aj tu by voslo settings a tspsource + isEn319132 si nastavis podla settings (aktualnych) |
||
var document = createDSSFileDocumentFromFile(file); | ||
var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132); | ||
var parameters = getParametersForFile(document, checkPDFACompliance, signatureType, isEn319132, tspSource); | ||
return build(document, parameters, responder); | ||
} | ||
|
||
private static SigningParameters getParametersForFile(FileDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132) { | ||
private static SigningParameters getParametersForFile(FileDocument document, boolean checkPDFACompliance, SignatureLevel signatureType, boolean isEn319132, TSPSource tspSource) { | ||
var level = SignatureValidator.getSignedDocumentSignatureLevel(document); | ||
if (level != null) switch (level) { | ||
case PAdES_BASELINE_B: | ||
return SigningParameters.buildForPDF(document.getName(), document, checkPDFACompliance, isEn319132); | ||
return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); | ||
case XAdES_BASELINE_B: | ||
return SigningParameters.buildForASiCWithXAdES(document.getName(), document, isEn319132); | ||
return SigningParameters.buildForASiCWithXAdES(document, isEn319132, tspSource); | ||
case CAdES_BASELINE_B: | ||
return SigningParameters.buildForASiCWithCAdES(document.getName(), document, isEn319132); | ||
return SigningParameters.buildForASiCWithCAdES(document, isEn319132, tspSource); | ||
default: | ||
; | ||
} | ||
|
||
var filename = document.getName(); | ||
if (isPDF(document.getMimeType())) switch (signatureType) { | ||
case PAdES_BASELINE_B: | ||
return SigningParameters.buildForPDF(filename, document, checkPDFACompliance, isEn319132); | ||
return SigningParameters.buildForPDF(document, checkPDFACompliance, isEn319132, tspSource); | ||
case XAdES_BASELINE_B: | ||
return SigningParameters.buildForASiCWithXAdES(filename, document, isEn319132); | ||
return SigningParameters.buildForASiCWithXAdES(document, isEn319132, tspSource); | ||
case CAdES_BASELINE_B: | ||
return SigningParameters.buildForASiCWithCAdES(filename, document, isEn319132); | ||
return SigningParameters.buildForASiCWithCAdES(document, isEn319132, tspSource); | ||
Comment on lines
+201
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ak by sme tu tieto veci vytahovali zo settings, tak nemusime restart? |
||
default: | ||
; | ||
} | ||
|
||
return SigningParameters.buildForASiCWithXAdES(filename, document, isEn319132); | ||
return SigningParameters.buildForASiCWithXAdES(document, isEn319132, tspSource); | ||
} | ||
|
||
public boolean shouldCheckPDFCompliance() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre GUI nevidim asi settings ci zle pozeram?