summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java
index 99b87819..be51426c 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyStoreUtils.java
@@ -30,12 +30,16 @@ import java.security.KeyStoreException;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
+import at.gv.egiz.eaaf.core.impl.credential.KeyStoreConfiguration.KeyStoreType;
+import lombok.extern.slf4j.Slf4j;
+
/**
* Utility for creating and loading key stores.
*
* @author Paul Ivancsics
* @version $Id$
*/
+@Slf4j
public class KeyStoreUtils {
/**
@@ -110,6 +114,32 @@ public class KeyStoreUtils {
}
/**
+ * Loads a keyStore with known keyStore type.
+ *
+ * @param is input stream
+ * @param password Password protecting the keyStore
+ * @param keyStoreType Type of the KeyStore
+ * @return loaded KeyStore
+ * @throws IOException In case of a general error
+ * @throws GeneralSecurityException In case of a KeyStore access error
+ */
+ public static KeyStore loadKeyStore(final InputStream is, final String password, KeyStoreType keyStoreType)
+ throws IOException, GeneralSecurityException {
+ String internalType = KEYSTORE_TYPE_PKCS12;
+ if (keyStoreType.equals(KeyStoreType.JKS)) {
+ internalType = KEYSTORE_TYPE_JKS;
+
+ } else if (keyStoreType.equals(KeyStoreType.PKCS12)) {
+ internalType = KEYSTORE_TYPE_PKCS12;
+
+ }
+
+ return loadKeyStore(internalType, is, password);
+
+ }
+
+
+ /**
* Loads a keyStore without knowing the keyStore type.
*
* @param is input stream
@@ -125,14 +155,18 @@ public class KeyStoreUtils {
try {
try {
ks = loadKeyStore(KEYSTORE_TYPE_PKCS12, is, password);
+
} catch (final IOException e2) {
is.reset();
ks = loadKeyStore(KEYSTORE_TYPE_JKS, is, password);
+
}
+
} catch (final Exception e) {
- e.printStackTrace();
-
+ log.warn("Can not load keystore", e);
+
}
+
return ks;
}