diff options
author | kstranacher_eGovL <kstranacher_eGovL@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2012-07-13 10:15:53 +0000 |
---|---|---|
committer | kstranacher_eGovL <kstranacher_eGovL@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2012-07-13 10:15:53 +0000 |
commit | 07b0306ca470cca10eecceab1a762f995b894fb0 (patch) | |
tree | f93b4dcb1e6b14ca97698d862587a49a0f28da47 /common/src/main/java/at/gv/egovernment/moa/util/KeyStoreUtils.java | |
parent | 1626ac9867cd5406b83e73651080e33c11fb98d1 (diff) | |
download | moa-id-spss-07b0306ca470cca10eecceab1a762f995b894fb0.tar.gz moa-id-spss-07b0306ca470cca10eecceab1a762f995b894fb0.tar.bz2 moa-id-spss-07b0306ca470cca10eecceab1a762f995b894fb0.zip |
Integration of STORK
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@1286 d688527b-c9ab-4aba-bd8d-4036d912da1d
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 | 54 |
1 files changed, 54 insertions, 0 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 78fe8a345..9db3ca6e3 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 @@ -26,14 +26,19 @@ package at.gv.egovernment.moa.util; import iaik.x509.X509Certificate; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; 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. @@ -42,6 +47,18 @@ import java.security.cert.Certificate; * @version $Id$ */ public class KeyStoreUtils { + + /** + * JAVA KeyStore + */ + private static final String KEYSTORE_TYPE_JKS = "JKS"; + + /** + * PKCS12 KeyStore + */ + private static final String KEYSTORE_TYPE_PKCS12 = "PKCS12"; + + /** * Loads a key store from file. @@ -154,5 +171,42 @@ public class KeyStoreUtils { in.close(); return cert; } + + + /** + * Loads a keyStore without knowing the keyStore type + * @param keyStorePath URL to the keyStore + * @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(String keyStorePath, String password) throws KeyStoreException, IOException{ + + //InputStream is = new FileInputStream(keyStorePath); + URL keystoreURL = new URL(keyStorePath); + InputStream in = keystoreURL.openStream(); + InputStream isBuffered = new BufferedInputStream(in); + + isBuffered.mark(1024*1024); + KeyStore ks = null; + try { + try { + ks = loadKeyStore(KEYSTORE_TYPE_PKCS12, isBuffered, password); + } catch (IOException e2) { + isBuffered.reset(); + ks = loadKeyStore(KEYSTORE_TYPE_JKS, isBuffered, password); + } + } catch(Exception e) { + e.printStackTrace(); + //throw new KeyStoreException(e); + } + return ks; + + } + + + } |