diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-17 17:54:04 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-17 17:54:04 +0100 |
commit | f62bafa252e6e0dfaaa9ba4acbc34b47ee627e21 (patch) | |
tree | bd4f87cf6e131902e4f7637f4a36737e48748728 /eaaf_core_utils/src/test/java | |
parent | 7848c74de2cdafed8bee69d1d5b8e5efa7535bc6 (diff) | |
download | EAAF-Components-f62bafa252e6e0dfaaa9ba4acbc34b47ee627e21.tar.gz EAAF-Components-f62bafa252e6e0dfaaa9ba4acbc34b47ee627e21.tar.bz2 EAAF-Components-f62bafa252e6e0dfaaa9ba4acbc34b47ee627e21.zip |
update EaafKeyStoreFactory to get the Security Provider if the KeyStore depends on a special provider implementation
Diffstat (limited to 'eaaf_core_utils/src/test/java')
-rw-r--r-- | eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/EaafKeyStoreFactoryTest.java | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/EaafKeyStoreFactoryTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/EaafKeyStoreFactoryTest.java index 01c3d6f1..5b6b8170 100644 --- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/EaafKeyStoreFactoryTest.java +++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/EaafKeyStoreFactoryTest.java @@ -3,6 +3,7 @@ package at.gv.egiz.eaaf.core.test.credentials; import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; +import java.security.Provider; import java.security.cert.X509Certificate; import java.util.List; @@ -210,8 +211,10 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.setSoftKeyStoreFilePath(PATH_TO_SOFTWARE_KEYSTORE_JKS); keyStoreConfig.setSoftKeyStorePassword(SOFTWARE_KEYSTORE_PASSWORD); - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNull("KeyStore is null", keyStore.getSecond()); } @@ -274,8 +277,10 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.validate(); - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNull("KeyStore is null", keyStore.getSecond()); } @@ -292,24 +297,26 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.validate(); - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNull("KeyStore is null", keyStore.getSecond()); //read trusted certs - final List<X509Certificate> trustedCerts = EaafKeyStoreUtils.readCertsFromKeyStore(keyStore); + final List<X509Certificate> trustedCerts = EaafKeyStoreUtils.readCertsFromKeyStore(keyStore.getFirst()); Assert.assertNotNull("Trusted certs", trustedCerts); Assert.assertEquals("Trusted certs size", 2, trustedCerts.size()); //read priv. key final Pair<Key, X509Certificate[]> privCred1 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "meta", "password".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), "meta", "password".toCharArray(), true, "jUnit test"); Assert.assertNotNull("Credential 1", privCred1); Assert.assertNotNull("Credential 1 priv. key", privCred1.getFirst()); Assert.assertNotNull("Credential 1 certificate", privCred1.getSecond()); //read priv. key final Pair<Key, X509Certificate[]> privCred2 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "sig", "password".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), "sig", "password".toCharArray(), true, "jUnit test"); Assert.assertNotNull("Credential 2", privCred2); Assert.assertNotNull("Credential 2 priv. key", privCred2.getFirst()); Assert.assertNotNull("Credential 2 certificate", privCred2.getSecond()); @@ -317,17 +324,17 @@ public class EaafKeyStoreFactoryTest { //read priv. key final Pair<Key, X509Certificate[]> privCred3 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "notexist", "password".toCharArray(), false, "jUnit test"); + keyStore.getFirst(), "notexist", "password".toCharArray(), false, "jUnit test"); Assert.assertNull("Credential 3", privCred3); //read priv. key final Pair<Key, X509Certificate[]> privCred4 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "meta", "wrong".toCharArray(), false, "jUnit test"); + keyStore.getFirst(), "meta", "wrong".toCharArray(), false, "jUnit test"); Assert.assertNull("Credential 3", privCred4); try { EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "meta", "wrong".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), "meta", "wrong".toCharArray(), true, "jUnit test"); Assert.fail("Wrong password not detected"); } catch (final EaafKeyAccessException e) { @@ -336,7 +343,7 @@ public class EaafKeyStoreFactoryTest { try { EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "wrong", "password".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), "wrong", "password".toCharArray(), true, "jUnit test"); Assert.fail("Wrong alias not detected"); } catch (final EaafKeyAccessException e) { @@ -359,8 +366,10 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.validate(); - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNull("KeyStore is null", keyStore.getSecond()); } @@ -593,8 +602,10 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.validate(); try { - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNotNull("KeyStore is null", keyStore.getSecond()); } catch (final StatusRuntimeException e) { // because there is no mockup of HSM facade available @@ -618,31 +629,34 @@ public class EaafKeyStoreFactoryTest { keyStoreConfig.validate(); - final KeyStore keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); + final Pair<KeyStore, Provider> keyStore = keyStoreFactory.buildNewKeyStore(keyStoreConfig); Assert.assertNotNull("KeyStore is null", keyStore); + Assert.assertNotNull("KeyStore is null", keyStore.getFirst()); + Assert.assertNotNull("KeyStore is null", keyStore.getSecond()); //read trusted certs - final List<X509Certificate> trustedCerts = EaafKeyStoreUtils.readCertsFromKeyStore(keyStore); + final List<X509Certificate> trustedCerts = EaafKeyStoreUtils.readCertsFromKeyStore( + keyStore.getFirst()); Assert.assertNotNull("Trusted certs", trustedCerts); Assert.assertEquals("Trusted certs size", 0, trustedCerts.size()); //read priv. key final Pair<Key, X509Certificate[]> privCred1 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, HSM_FACADE_KEY_ALIAS, null, true, "jUnit test"); + keyStore.getFirst(), HSM_FACADE_KEY_ALIAS, null, true, "jUnit test"); Assert.assertNotNull("Credential 1", privCred1); Assert.assertNotNull("Credential 1 priv. key", privCred1.getFirst()); Assert.assertNotNull("Credential 1 certificate", privCred1.getSecond()); //read priv. key final Pair<Key, X509Certificate[]> privCred2 = EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, HSM_FACADE_KEY_ALIAS, "shouldBeIgnord".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), HSM_FACADE_KEY_ALIAS, "shouldBeIgnord".toCharArray(), true, "jUnit test"); Assert.assertNotNull("Credential 2", privCred2); Assert.assertNotNull("Credential 2 priv. key", privCred2.getFirst()); Assert.assertNotNull("Credential 2 certificate", privCred2.getSecond()); try { EaafKeyStoreUtils.getPrivateKeyAndCertificates( - keyStore, "notExist", "wrong".toCharArray(), true, "jUnit test"); + keyStore.getFirst(), "notExist", "wrong".toCharArray(), true, "jUnit test"); Assert.fail("Wrong password not detected"); } catch (final EaafKeyAccessException e) { |