From ec95a4a9d7aec5d978881719c1bd19d6df4540e5 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Fri, 3 Oct 2014 10:19:29 +0200 Subject: Register IAIK Providers order --- .../wag/egov/egiz/cfg/SettingsReader.java | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'pdf-as-lib') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index 832f952..7473590 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; +import java.security.Provider; import java.security.Security; import java.util.ArrayList; import java.util.Enumeration; @@ -426,8 +427,8 @@ public class SettingsReader implements Serializable logger_.info(StringUtils.repeat("*", length + 25)); if (registerProvider) { - IAIK.addAsProvider(); - ECCProvider.addAsProvider(); + registerProvider(new IAIK(), 1); + registerProvider(new ECCProvider(), 2); } else { if (Security.getProvider("IAIK") == null) { logger_.debug("Default IAIK JCE provider not registered."); @@ -905,6 +906,34 @@ public class SettingsReader implements Serializable logger_.info("PDF-AS info\n" + paddingString + "\n" + versionString + "\n" + paddingString); } + protected static void registerProvider(Provider provider, int position) { + String name = provider.getName(); + if (Security.getProvider(name) == null) { + // register IAIK provider at first position + try { + if (position < 0) { + // add provider add default position. + Security.addProvider(provider); + } else { + Security.insertProviderAt(provider, position); + } + } catch (SecurityException e) { + logger_.info("Failed to register required security Provider.", e); + } + } else { + logger_.info("Required security Provider " + name + " already registered."); + } + + } + + protected static void listRegisteredSecurityProviders() { + Provider[] providers = Security.getProviders(); + logger_.debug("Registered Security Providers:"); + for (int i = 0; i < providers.length; i++) { + logger_.debug(" " + i + ": " + providers[i].getName() + " => " + providers[i].getInfo()); + } + } + public Properties getProperties() { return this.properties_; } -- cgit v1.2.3