Skip to content

Commit

Permalink
Merge pull request #466 from slovensko-digital/add-multiple-tsp
Browse files Browse the repository at this point in the history
Add support for multiple TSP
  • Loading branch information
celuchmarek authored Jun 25, 2024
2 parents af69389 + c4ac577 commit 0e485d3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public static void printUsage() {
autogram --cli -s target/directory-example -t target/non-existent-dir/output-example --parents
autogram --cli -s target/directory-example/file-example.pdf -pdfa
autogram --cli -s target/directory-example/file-example.pdf -d eid
autogram --cli -s target/file-example.pdf -d eid --tsa-server http://tsa.izenpe.com
autogram --cli -s target/file-example.pdf -d eid --tsa-server http://tsa.belgium.be/connect
autogram --cli -s target/file-example.pdf -d eid --tsa-server "http://tsa.belgium.be/connect,http://ts.quovadisglobal.com/eu,http://tsa.sep.bg"
""";
final PrintWriter pw = new PrintWriter(System.out);
formatter.printUsage(pw, 80, syntax);
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/digital/slovensko/autogram/core/UserSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import digital.slovensko.autogram.ui.gui.SignatureLevelStringConverter;
import eu.europa.esig.dss.enumerations.SignatureLevel;
import eu.europa.esig.dss.service.http.commons.TimestampDataLoader;
import eu.europa.esig.dss.service.tsp.OnlineTSPSource;
import eu.europa.esig.dss.spi.x509.tsp.CompositeTSPSource;
import eu.europa.esig.dss.spi.x509.tsp.TSPSource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.prefs.Preferences;

Expand All @@ -25,7 +28,7 @@ public class UserSettings implements PasswordManagerSettings, SignatureTokenSett
private List<String> trustedList;
private String customKeystorePath;
private String tsaServer;
private TSPSource tspSource;
private CompositeTSPSource tspSource;
private boolean tsaEnabled;
private String customTsaServer;
private boolean bulkEnabled;
Expand All @@ -47,9 +50,9 @@ public static UserSettings load() {
settings.setPdfaCompliance(prefs.getBoolean("PDFA_COMPLIANCE", true));
settings.setServerEnabled(prefs.getBoolean("SERVER_ENABLED", true));
settings.setExpiredCertsEnabled(prefs.getBoolean("EXPIRED_CERTS_ENABLED", false));
settings.setTrustedList(prefs.get("TRUSTED_LIST", "SK,CZ,AT,PL,HU,ES,BE"));
settings.setTrustedList(prefs.get("TRUSTED_LIST", "SK,CZ,AT,PL,HU,BE,NL,BG"));
settings.setCustomKeystorePath(prefs.get("CUSTOM_KEYSTORE_PATH", ""));
settings.setTsaServer(prefs.get("TSA_SERVER", "http://tsa.izenpe.com"));
settings.setTsaServer(prefs.get("TSA_SERVER", "http://tsa.belgium.be/connect,http://ts.quovadisglobal.com/eu,http://tsa.sep.bg"));
settings.setCustomTsaServer(prefs.get("CUSTOM_TSA_SERVER", ""));
settings.setTsaEnabled(prefs.getBoolean("TSA_ENABLE", false));
settings.setPdfDpi(prefs.getInt("PDF_DPI", 100));
Expand Down Expand Up @@ -206,11 +209,18 @@ public String getTsaServer() {

public void setTsaServer(String value) {
tsaServer = value;
if (value == null)
if (value == null) {
tspSource = null;
return;
}

else
tspSource = new OnlineTSPSource(tsaServer);
tspSource = new CompositeTSPSource();
var timestampDataLoader = new TimestampDataLoader();
var tspSources = new HashMap<String, TSPSource>();
for (var tsaServer : tsaServer.split(","))
tspSources.put(tsaServer, new OnlineTSPSource(tsaServer, timestampDataLoader));

tspSource.setTspSources(tspSources);
}

public String getCustomTsaServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public class SettingsDialogController {

private final UserSettings userSettings;
private final List<String> preDefinedTsaServers = List.of(
"http://tsa.izenpe.com",
"http://tsa.belgium.be/connect",
"http://kstamp.keynectis.com/KSign/"
"http://tsa.belgium.be/connect,http://ts.quovadisglobal.com/eu,http://tsa.sep.bg",
"http://ts.quovadisglobal.com/eu",
"http://tsa.sep.bg"
);

public SettingsDialogController(UserSettings userSettings) {
Expand Down Expand Up @@ -143,6 +143,8 @@ private void initializeTsaServer() {

if (!preDefinedTsaServers.contains(userSettings.getTsaServer())) {
tsaChoiceBox.setValue(USE_CUSTOM_TSA_LABEL);
customTsaServerTextField.setText(userSettings.getTsaServer());
userSettings.setCustomTsaServer(userSettings.getTsaServer());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@
<VBox styleClass="left">
<TextFlow>
<Text styleClass="autogram-heading-s">
Zdroj časových pečiatok
Zdroje časových pečiatok
</Text>
</TextFlow>
<TextFlow>
<Text styleClass="autogram-description">
Je možné použiť niektorý z preddefinovaných voľne dostupných poskytovateľov alebo nastaviť vlastnú adresu.
Je možné použiť preddefinovaných voľne dostupných poskytovateľov alebo nastaviť vlastné adresy.
</Text>
</TextFlow>
<TextFlow>
<Text styleClass="autogram-description">
Pre správne overenie platnosti časovej pečiatky je potrebné, aby bola TSA v zozname dôveryhodných poskytovateľov a aby krajina jej pôvodu bola nastavená v záložke "Overovanie podpisov".
Pre správne overenie platnosti časovej pečiatky je potrebné, aby bola TSA kvalifikovaná a aby krajina jej pôvodu bola nastavená v záložke "Overovanie podpisov".
</Text>
</TextFlow>
</VBox>
Expand All @@ -113,12 +113,12 @@
<VBox styleClass="left">
<TextFlow>
<Text styleClass="autogram-heading-s">
Vlastná adresa TSA servera
Vlastné adresy TSP serverov
</Text>
</TextFlow>
<TextFlow>
<Text styleClass="autogram-description">
URL adresa iného servera autority časových pečiatok.
URL adresy serverov poskytovateľov časových pečiatok. Viaceré adresy je možné oddeliť čiarkou bez medzier.
</Text>
</TextFlow>
</VBox>
Expand Down

0 comments on commit 0e485d3

Please sign in to comment.