Search in sources :

Example 1 with TrustedCertificateEntry

use of com.emc.storageos.security.keystore.impl.TrustedCertificateEntry in project coprhd-controller by CoprHD.

the class TrustManagerTest method testCheckServerTrusted.

@Test
public void testCheckServerTrusted() throws Exception {
    DistributedKeyStore zookeeperKeystore = new DistributedKeyStoreImpl();
    zookeeperKeystore.init(loadStoreParam);
    zookeeperKeystore.setTrustedCertificates(null);
    KeyStoreUtil.setAcceptAllCertificates(zkhHelper, Boolean.FALSE);
    ViPRX509TrustManager tm = new ViPRX509TrustManager(coordinatorClient);
    KeyCertificatePairGenerator gen = new KeyCertificatePairGenerator();
    gen.setKeyCertificateAlgorithmValuesHolder(new KeyCertificateAlgorithmValuesHolder(coordinatorClient));
    KeyCertificateEntry entry = gen.generateKeyCertificatePair();
    X509Certificate[] chainToVerify = new X509Certificate[] { (X509Certificate) entry.getCertificateChain()[0] };
    boolean exceptionThrown = false;
    try {
        tm.checkServerTrusted(chainToVerify, "RSA_EXPORT");
    } catch (CertificateException e) {
        exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
    TrustedCertificateEntry trustedCert = new TrustedCertificateEntry(entry.getCertificateChain()[0], new Date());
    zookeeperKeystore.addTrustedCertificate("someAlias", trustedCert);
    // creating a new instance since trust manager caches all the certs
    tm = new ViPRX509TrustManager(coordinatorClient);
    try {
        tm.checkServerTrusted(chainToVerify, "RSA_EXPORT");
    } catch (CertificateException e) {
        Assert.fail();
    }
    KeyStoreUtil.setAcceptAllCertificates(zkhHelper, Boolean.TRUE);
    entry = gen.generateKeyCertificatePair();
    chainToVerify = new X509Certificate[] { (X509Certificate) entry.getCertificateChain()[0] };
    try {
        tm.checkServerTrusted(chainToVerify, "RSA_EXPORT");
    } catch (CertificateException e) {
        Assert.fail();
    }
}
Also used : KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) DistributedKeyStoreImpl(com.emc.storageos.security.keystore.impl.DistributedKeyStoreImpl) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) CertificateException(java.security.cert.CertificateException) ViPRX509TrustManager(com.emc.storageos.security.ssl.ViPRX509TrustManager) KeyCertificateEntry(com.emc.storageos.security.keystore.impl.KeyCertificateEntry) X509Certificate(java.security.cert.X509Certificate) Date(java.util.Date) TrustedCertificateEntry(com.emc.storageos.security.keystore.impl.TrustedCertificateEntry) Test(org.junit.Test)

Example 2 with TrustedCertificateEntry

use of com.emc.storageos.security.keystore.impl.TrustedCertificateEntry in project coprhd-controller by CoprHD.

the class KeystoreTest method testZookeeperKeystore.

@Test
public void testZookeeperKeystore() throws IOException {
    DistributedKeyStore zookeeperKeystore = new DistributedKeyStoreImpl();
    boolean exceptionThrown = false;
    try {
        zookeeperKeystore.init(invalidLoadStoreParam);
    } catch (SecurityException e) {
        exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
    zookeeperKeystore.init(loadStoreParam);
    // this is in case this test was run previously
    zookeeperKeystore.setTrustedCertificates(null);
    KeyCertificateEntry origEntry = gen.generateKeyCertificatePair();
    origEntry.setCreationDate(new Date());
    zookeeperKeystore.setKeyCertificatePair(origEntry);
    KeyCertificateEntry storedEntry = zookeeperKeystore.getKeyCertificatePair();
    assertKeyCertificateEntriesEquals(origEntry, storedEntry);
    origEntry = gen.generateKeyCertificatePair();
    TrustedCertificateEntry origCertEntry = new TrustedCertificateEntry(origEntry.getCertificateChain()[0], new Date());
    Map<String, TrustedCertificateEntry> origCertEntries = new HashMap<String, TrustedCertificateEntry>();
    origCertEntries.put("trustedCert1", origCertEntry);
    zookeeperKeystore.addTrustedCertificate("trustedCert1", origCertEntry);
    origEntry = gen.generateKeyCertificatePair();
    origCertEntry = new TrustedCertificateEntry(origEntry.getCertificateChain()[0], new Date());
    origCertEntries.put("trustedCert2", origCertEntry);
    zookeeperKeystore.addTrustedCertificate("trustedCert2", origCertEntry);
    assertTrustedCertsEquals(origCertEntries, zookeeperKeystore.getTrustedCertificates());
    origEntry = gen.generateKeyCertificatePair();
    origCertEntry = new TrustedCertificateEntry(origEntry.getCertificateChain()[0], new Date());
    origCertEntries.put("trustedCert3", origCertEntry);
    zookeeperKeystore.setTrustedCertificates(origCertEntries);
    assertTrustedCertsEquals(origCertEntries, zookeeperKeystore.getTrustedCertificates());
    origCertEntries.remove("trustedCert3");
    zookeeperKeystore.setTrustedCertificates(origCertEntries);
    assertTrustedCertsEquals(origCertEntries, zookeeperKeystore.getTrustedCertificates());
    origCertEntries.remove("trustedCert2");
    zookeeperKeystore.removeTrustedCertificate("trustedCert2");
    assertTrustedCertsEquals(origCertEntries, zookeeperKeystore.getTrustedCertificates());
    zookeeperKeystore.removeTrustedCertificate("trustedCert10");
}
Also used : DistributedKeyStoreImpl(com.emc.storageos.security.keystore.impl.DistributedKeyStoreImpl) HashMap(java.util.HashMap) SecurityException(com.emc.storageos.security.exceptions.SecurityException) KeyCertificateEntry(com.emc.storageos.security.keystore.impl.KeyCertificateEntry) Date(java.util.Date) TrustedCertificateEntry(com.emc.storageos.security.keystore.impl.TrustedCertificateEntry) Test(org.junit.Test)

Aggregations

DistributedKeyStoreImpl (com.emc.storageos.security.keystore.impl.DistributedKeyStoreImpl)2 KeyCertificateEntry (com.emc.storageos.security.keystore.impl.KeyCertificateEntry)2 TrustedCertificateEntry (com.emc.storageos.security.keystore.impl.TrustedCertificateEntry)2 Date (java.util.Date)2 Test (org.junit.Test)2 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 KeyCertificateAlgorithmValuesHolder (com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder)1 KeyCertificatePairGenerator (com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)1 ViPRX509TrustManager (com.emc.storageos.security.ssl.ViPRX509TrustManager)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1