summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java40
1 files changed, 28 insertions, 12 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
index 0cdb4a65..9db38670 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
@@ -57,6 +57,10 @@ public class EaafKeyStoreFactory {
private static final String HSM_FACADE_PROVIDER_CLASS = "at.asitplus.hsmfacade.provider.HsmFacadeProvider";
private static final String HSM_FACADE_KEYSTORELOADPARAMETERS_CLASS
= "at.asitplus.hsmfacade.provider.RemoteKeyStoreLoadParameter";
+ private static final String HSM_FACADE_PROVIDER_METHOD_CONSTRUCT = "getInstance";
+ private static final String HSM_FACADE_PROVIDER_METHOD_INIT = "init";
+ private static final String HSM_FACADE_PROVIDER_INIT_ERROR_MSG
+ = "Has HSM-Facade class supported '{}' method: {}";
private static final String HSM_FACADE_PROVIDER = "HsmFacade";
private static final String HSM_FACADE_KEYSTORE_TYPE = "RemoteKeyStore";
@@ -134,22 +138,34 @@ public class EaafKeyStoreFactory {
//initialize HSM-Facade by using JAVA Reflection, because in that case HSM-Facade
//has not be in ClassPath on every project
- Method initMethod = hsmProviderClazz.getMethod("init",
- X509Certificate.class, String.class, String.class, String.class, int.class);
- Object rawProvider =
- hsmProviderClazz.getMethod("getInstance", new Class[]{}).invoke(hsmProviderClazz);
- if (rawProvider instanceof Provider && initMethod != null) {
+
+ Method constructor = hsmProviderClazz.getMethod(HSM_FACADE_PROVIDER_METHOD_CONSTRUCT, new Class[]{});
+ Method initMethod = hsmProviderClazz.getMethod(HSM_FACADE_PROVIDER_METHOD_INIT,
+ X509Certificate.class, String.class, String.class, String.class, int.class);
+ if (initMethod != null && constructor != null) {
+ Object rawProvider = constructor.invoke(hsmProviderClazz);
initMethod.invoke(
rawProvider, getHsmFacadeTrustSslCertificate(),
clientUsername, clientPassword, hsmFacadeHost, port);
- Security.insertProviderAt((Provider) rawProvider, 0);
- isHsmFacadeInitialized = true;
- log.info("HSM Facade is initialized. {} can provide KeyStores based on remote HSM",
- EaafKeyStoreFactory.class.getSimpleName());
+
+ if (rawProvider instanceof Provider) {
+ Security.insertProviderAt((Provider) rawProvider, 0);
+ isHsmFacadeInitialized = true;
+ log.info("HSM Facade is initialized. {} can provide KeyStores based on remote HSM",
+ EaafKeyStoreFactory.class.getSimpleName());
+
+ } else {
+ log.warn("Is HSM-Facade class type of 'java.security.Provider': {}",
+ rawProvider instanceof Provider);
+ throw new EaafException(ERRORCODE_10, new Object[] {HSM_FACADE_PROVIDER_CLASS});
+
+ }
- } else {
- log.warn("Is HSM-Facade class type of 'java.security.Provider': {}", rawProvider instanceof Provider);
- log.warn("Has HSM-Facade class supported 'init' method: {}", initMethod != null);
+ } else {
+ log.warn(HSM_FACADE_PROVIDER_INIT_ERROR_MSG,
+ HSM_FACADE_PROVIDER_METHOD_CONSTRUCT, constructor != null);
+ log.warn(HSM_FACADE_PROVIDER_INIT_ERROR_MSG,
+ HSM_FACADE_PROVIDER_METHOD_INIT, initMethod != null);
throw new EaafException(ERRORCODE_10, new Object[] {HSM_FACADE_PROVIDER_CLASS});
}