use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreFactoryTest method testCreate.
@Test
public void testCreate() {
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME, "Workload-Table");
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME, "Workload-Service-Index");
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME, "Workload-Ip-Index");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory();
WorkloadRecordStore store = factory.create(keyStore);
Assert.assertNotNull(store);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class JDBCWorkloadRecordStoreFactoryTest method testCreate.
@Test
public void testCreate() {
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_STORE, "jdbc:mysql://localhost");
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_USER, "user");
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_PASSWORD, "password");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
Mockito.doReturn("password").when(keyStore).getApplicationSecret("jdbc", "password");
JDBCWorkloadRecordStoreFactory factory = new JDBCWorkloadRecordStoreFactory();
WorkloadRecordStore store = factory.create(keyStore);
Assert.assertNotNull(store);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class ZTSUtils method getAthenzServerSSLContext.
public static SSLContext getAthenzServerSSLContext(PrivateKeyStore privateKeyStore) {
final String keyStorePath = System.getProperty(ATHENZ_PROP_KEYSTORE_PATH);
if (keyStorePath == null) {
LOGGER.error("Unable to create client ssl context: no keystore path specified");
return null;
}
final String keyStorePasswordAppName = System.getProperty(ATHENZ_PROP_KEYSTORE_PASSWORD_APPNAME);
final String keyStorePassword = System.getProperty(ATHENZ_PROP_KEYSTORE_PASSWORD);
final String keyStoreType = System.getProperty(ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");
final String trustStorePath = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PATH);
if (trustStorePath == null) {
LOGGER.error("Unable to create client ssl context: no truststore path specified");
return null;
}
final String trustStorePassword = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PASSWORD);
final String trustStorePasswordAppName = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PASSWORD_APPNAME);
final String trustStoreType = System.getProperty(ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");
SSLContext sslcontext = null;
try {
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
try (FileInputStream instream = new FileInputStream(trustStorePath)) {
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
final String password = getApplicationSecret(privateKeyStore, trustStorePasswordAppName, trustStorePassword);
trustStore.load(instream, getPasswordChars(password));
tmfactory.init(trustStore);
}
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
try (FileInputStream instream = new FileInputStream(keyStorePath)) {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
final String password = getApplicationSecret(privateKeyStore, keyStorePasswordAppName, keyStorePassword);
keyStore.load(instream, getPasswordChars(password));
kmfactory.init(keyStore, getPasswordChars(password));
}
KeyManager[] keymanagers = kmfactory.getKeyManagers();
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
sslcontext = SSLContext.getInstance("TLSv1.2");
sslcontext.init(keymanagers, trustmanagers, new SecureRandom());
} catch (Exception ex) {
LOGGER.error("Unable to create server client ssl context", ex);
}
return sslcontext;
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class JDBCCertRecordStoreFactoryTest method testCreate.
@Test
public void testCreate() {
System.setProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_STORE, "jdbc:mysql://localhost");
System.setProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_USER, "user");
System.setProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_PASSWORD, "password");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
Mockito.doReturn("password").when(keyStore).getApplicationSecret("jdbc", "password");
JDBCCertRecordStoreFactory factory = new JDBCCertRecordStoreFactory();
CertRecordStore store = factory.create(keyStore);
assertNotNull(store);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class FilePrivateKeyStoreTest method testRetrievePrivateKeyInValid.
@SuppressWarnings("deprecation")
@Test
public void testRetrievePrivateKeyInValid() {
FilePrivateKeyStoreFactory factory = new FilePrivateKeyStoreFactory();
PrivateKeyStore store = factory.create();
String saveProp = System.getProperty(FilePrivateKeyStore.ATHENZ_PROP_PRIVATE_KEY);
System.setProperty(FilePrivateKeyStore.ATHENZ_PROP_PRIVATE_KEY, "src/test/resources/zts_private_k0_invalid.pem");
try {
StringBuilder keyId = new StringBuilder(256);
store.getPrivateKey("zts", "localhost", keyId);
fail();
} catch (Exception ex) {
assertTrue(true);
}
System.clearProperty(FilePrivateKeyStore.ATHENZ_PROP_PRIVATE_KEY);
StringBuilder keyId = new StringBuilder(256);
assertNull(store.getPrivateKey("zts", "localhost", keyId));
if (saveProp == null) {
System.clearProperty(FilePrivateKeyStore.ATHENZ_PROP_PRIVATE_KEY);
} else {
System.setProperty(FilePrivateKeyStore.ATHENZ_PROP_PRIVATE_KEY, saveProp);
}
}
Aggregations