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);
}
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();
}
}
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;
}
Aggregations