Search in sources :

Example 6 with KeyCertificatePairGenerator

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

the class KeyCertificatePairGeneratorTest method testLoadKey.

@Test
public void testLoadKey() throws SecurityException, NoSuchAlgorithmException {
    // test the defaults
    KeyCertificatePairGenerator rsaGen = new KeyCertificatePairGenerator();
    rsaGen.setKeyCertificateAlgorithmValuesHolder(defaultValues);
    KeyCertificateEntry pair = rsaGen.generateKeyCertificatePair();
    byte[] RSAKeyBytes = pair.getKey();
    PrivateKey loadedRSAKey = KeyCertificatePairGenerator.loadPrivateKeyFromBytes(RSAKeyBytes);
    byte[] loadedRSAKeyBytes = loadedRSAKey.getEncoded();
    Assert.assertEquals(RSAKeyBytes.length, loadedRSAKeyBytes.length);
    Assert.assertArrayEquals(RSAKeyBytes, loadedRSAKeyBytes);
}
Also used : PrivateKey(java.security.PrivateKey) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) KeyCertificateEntry(com.emc.storageos.security.keystore.impl.KeyCertificateEntry) Test(org.junit.Test)

Example 7 with KeyCertificatePairGenerator

use of com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator 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 8 with KeyCertificatePairGenerator

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

the class VirtualDataCenterService method getGenerator.

private KeyCertificatePairGenerator getGenerator() {
    if (generator == null) {
        generator = new KeyCertificatePairGenerator();
        generator.setKeyCertificateAlgorithmValuesHolder(new KeyCertificateAlgorithmValuesHolder(coordinator));
    }
    return generator;
}
Also used : KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)

Aggregations

KeyCertificatePairGenerator (com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)8 KeyCertificateAlgorithmValuesHolder (com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder)5 KeyCertificateEntry (com.emc.storageos.security.keystore.impl.KeyCertificateEntry)4 Test (org.junit.Test)4 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)3 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)3 ZkConnection (com.emc.storageos.coordinator.common.impl.ZkConnection)3 FileInputStream (java.io.FileInputStream)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 Before (org.junit.Before)3 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 DistributedKeyStoreImpl (com.emc.storageos.security.keystore.impl.DistributedKeyStoreImpl)1 DistributedLoadKeyStoreParam (com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam)1 TrustedCertificateEntry (com.emc.storageos.security.keystore.impl.TrustedCertificateEntry)1 ViPRX509TrustManager (com.emc.storageos.security.ssl.ViPRX509TrustManager)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 GeneralSecurityException (java.security.GeneralSecurityException)1