diff options
Diffstat (limited to 'common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java')
-rw-r--r-- | common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java b/common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java index 9db3ca6e3..3d28f4f2b 100644 --- a/common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java +++ b/common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java @@ -36,9 +36,7 @@ import java.net.URL; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; import java.security.cert.Certificate; -import java.security.cert.CertificateException; /** * Utility for creating and loading key stores. @@ -187,16 +185,29 @@ public class KeyStoreUtils { //InputStream is = new FileInputStream(keyStorePath); URL keystoreURL = new URL(keyStorePath); InputStream in = keystoreURL.openStream(); - InputStream isBuffered = new BufferedInputStream(in); + InputStream isBuffered = new BufferedInputStream(in); + return loadKeyStore(isBuffered, password); - isBuffered.mark(1024*1024); + } + + /** + * Loads a keyStore without knowing the keyStore type + * @param in input stream + * @param password Password protecting the keyStore + * @return keyStore loaded + * @throws KeyStoreException thrown if keyStore cannot be loaded + * @throws FileNotFoundException + * @throws IOException + */ +public static KeyStore loadKeyStore(InputStream is, String password) throws KeyStoreException, IOException{ + is.mark(1024*1024); KeyStore ks = null; try { try { - ks = loadKeyStore(KEYSTORE_TYPE_PKCS12, isBuffered, password); + ks = loadKeyStore(KEYSTORE_TYPE_PKCS12, is, password); } catch (IOException e2) { - isBuffered.reset(); - ks = loadKeyStore(KEYSTORE_TYPE_JKS, isBuffered, password); + is.reset(); + ks = loadKeyStore(KEYSTORE_TYPE_JKS, is, password); } } catch(Exception e) { e.printStackTrace(); @@ -205,7 +216,7 @@ public class KeyStoreUtils { return ks; } - + |