diff --git a/src/main/java/digital/slovensko/autogram/ui/gui/PresentSignaturesDialogController.java b/src/main/java/digital/slovensko/autogram/ui/gui/PresentSignaturesDialogController.java index 6d0765c42..b21b12d67 100644 --- a/src/main/java/digital/slovensko/autogram/ui/gui/PresentSignaturesDialogController.java +++ b/src/main/java/digital/slovensko/autogram/ui/gui/PresentSignaturesDialogController.java @@ -2,10 +2,11 @@ import java.text.SimpleDateFormat; +import javax.security.auth.x500.X500Principal; + import digital.slovensko.autogram.core.SigningJob; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; +import eu.europa.esig.dss.validation.reports.Reports; import javafx.fxml.FXML; -import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; @@ -43,6 +44,8 @@ public void onSignatureValidationCompleted() { signatureValidationMessage.setText(""); signatureValidationMessage.setVisible(false); signatureDetailsButton.setVisible(true); + + showSignatures(); } public void onSignatureDetailsButtonAction() { @@ -59,31 +62,64 @@ public void onSignatureDetailsButtonAction() { } public void showSignatures() { - var rep = signingJob.getSignatureCheckReport().getSimpleReport(); - var docValidator = signingJob.getDocumentValidator(); - docValidator.setCertificateVerifier(new CommonCertificateVerifier()); - var format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); + if (signingJob.getSignatureValidationReport() != null) + renderSignatures(signingJob.getSignatureValidationReport(), true); + + else + renderSignatures(signingJob.getSignatureCheckReport(), false); + } + + public void renderSignatures(Reports reports, boolean isValidated) { + signaturesBox.getChildren().clear(); - for (var signatureId : rep.getSignatureIdList()) { - var subjectPrincipal = docValidator.getSignatureById(signatureId).getCertificates().get(0).getCertificate().getSubjectX500Principal(); - var name = rep.getSignedBy(signatureId); - var subjectStr = subjectPrincipal.getName("RFC1779").replace(", ", "\n"); - var signingTime = format.format(rep.getSigningTime(signatureId)); - var timestampCount = Integer.toString(rep.getSignatureTimestamps(signatureId).size()); + var s = reports.getSimpleReport(); + + var format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); + for (var signatureId : s.getSignatureIdList()) { + var subject = new X500Principal(reports.getDiagnosticData().getSignatureById(signatureId).getSigningCertificate().getCertificateDN()).getName(X500Principal.RFC1779); + var name = s.getSignedBy(signatureId); + var subjectStr = subject.replace(", ", "\n"); + var signingTime = format.format(s.getSigningTime(signatureId)); + var timestampCount = Integer.toString(s.getSignatureTimestamps(signatureId).size()); var signatureBox = new VBox(); signatureBox.setStyle("-fx-border-color: -autogram-border-colour; -fx-border-width: 1px;"); var nameText = new Text(name); - nameText.getStyleClass().add("autogram-heading-s"); + nameText.getStyleClass().add("autogram-heading-m"); var nameFlow = new TextFlow(nameText); nameFlow.setStyle("-fx-padding: 1.25em 1.25em;"); nameFlow.setPrefWidth(248); - var validText = new Text("Prebieha overovanie platnosti..."); - validText.getStyleClass().add("autogram-body"); - var validFlow = new TextFlow(validText); - validFlow.setStyle("-fx-padding: 1.25em 1.25em;"); + var signatureType = isValidated ? reports.getDetailedReport().getSignatureQualification(signatureId).getLabel() : "Prebieha overovanie..."; + + var validText = new Text("Prebieha overovanie..."); + var validFlow = new TextFlow(); + validFlow.setStyle("-fx-padding: 1.1875em 1.25em;"); + + if (!isValidated) { + validFlow.getChildren().add(validText); + validText.getStyleClass().add("autogram-body"); + + } else { + validText.getStyleClass().add("autogram-heading-s"); + var validBox = new VBox(); + validBox.getChildren().add(validText); + validBox.getStyleClass().add("autogram-tag"); + + if (s.isValid(signatureId)) { + validText.setText("Platný"); + validText.getStyleClass().add("autogram-tag-valid--text"); + validBox.getStyleClass().add("autogram-tag-valid"); + + } else { + validText.setText("Neplatný"); + validText.getStyleClass().add("autogram-tag-invalid--text"); + validBox.getStyleClass().add("autogram-tag-invalid"); + } + + validFlow.getChildren().add(validBox); + } var nameBox = new HBox(); nameBox.getChildren().addAll(nameFlow, validFlow); @@ -94,18 +130,22 @@ public void showSignatures() { signatureDetailsBox.setStyle("-fx-padding: 0.5em 1.25em 1.25em 1.25em;"); signatureBox.getChildren().add(signatureDetailsBox); signatureDetailsBox.getChildren().add(createTableRow("Certifikát", subjectStr)); - signatureDetailsBox.getChildren().add(createTableRow("Typ podpisu", "Prebieha overovanie...")); + signatureDetailsBox.getChildren().add(createTableRow("Typ podpisu", signatureType)); signatureDetailsBox.getChildren().add(createTableRow("Čas", signingTime)); - signatureDetailsBox.getChildren().add(createTableRow("Časové pečiatky", timestampCount)); + signatureDetailsBox.getChildren().add(createTableRow("Časové pečiatky", timestampCount, true)); signaturesBox.getChildren().add(signatureBox); } } private HBox createTableRow(String label, String value) { + return createTableRow(label, value, false); + } + + private HBox createTableRow(String label, String value, boolean isLast) { var row = new HBox(); - var labelNode = createTableCell(label, "autogram-heading-s"); - var valueNode = createTableCell(value, "autogram-body"); + var labelNode = createTableCell(label, "autogram-heading-s", isLast); + var valueNode = createTableCell(value, "autogram-body", isLast); labelNode.setPrefWidth(248); valueNode.setPrefWidth(400); @@ -115,9 +155,9 @@ private HBox createTableRow(String label, String value) { return row; } - private TextFlow createTableCell(String value, String textStyle) { + private TextFlow createTableCell(String value, String textStyle, boolean isLast) { var cell = new TextFlow(); - cell.getStyleClass().addAll("autogram-table-cell"); + cell.getStyleClass().addAll(isLast ? "autogram-table-cell--last" : "autogram-table-cell"); var text = new Text(value); text.getStyleClass().add(textStyle); cell.getChildren().add(text); diff --git a/src/main/resources/digital/slovensko/autogram/ui/gui/idsk.css b/src/main/resources/digital/slovensko/autogram/ui/gui/idsk.css index 50eebf27a..0a4b46c1e 100644 --- a/src/main/resources/digital/slovensko/autogram/ui/gui/idsk.css +++ b/src/main/resources/digital/slovensko/autogram/ui/gui/idsk.css @@ -498,6 +498,10 @@ TextFlow.autogram-body-s { -fx-padding: 0.625em 0 0.625em 0; } +.autogram-table-cell--last { + -fx-padding: 0.625em 0 0.5em 0; +} + /* Custom styles */ @@ -569,3 +573,29 @@ TextFlow.autogram-body-s { -fx-shape: "M571 512c118-85 197-240 197-384 0-71-172-128-384-128s-384 57-384 128c0 144 80 299 197 384-118 85-197 240-197 384 0 71 172 128 384 128s384-57 384-128c0-144-80-299-197-384z m-187-448c141 0 256 29 256 64s-115 64-256 64-256-29-256-64 115-64 256-64z m-64 706c-154 7-238 40-253 82 16-114 75-189 141-251 73-68 112-60 112-103v273z m-105-352c-70-55-122-130-142-215 70 32 183 53 311 53s241-21 311-53c-20 85-72 160-142 215-24-17-70-34-169-34s-145 17-169 34z m233 352v-273c0 43 39 35 112 103 66 62 125 138 141 251-14-41-99-75-253-82z"; -fx-background-color: -autogram-border-colour; } + + +.autogram-tag { + -fx-border-width: 2px; + -fx-padding: 0.1875em 0.25em; +} + +.autogram-tag-valid { + -fx-background-color: #cce2d8; + -fx-border-color: #cce2d8; +} + +.autogram-tag-invalid { + -fx-background-color: #f8d7da; + -fx-border-color: #f8d7da; +} + +.autogram-tag-valid--text { + -fx-text-fill: #005a30; + -fx-fill: #005a30; +} + +.autogram-tag-invalid--text { + -fx-text-fill: #721c24; + -fx-fill: #721c24; +}