Search in sources :

Example 31 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) Test(org.testng.annotations.Test)

Example 32 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) Test(org.testng.annotations.Test)

Example 33 with PrivateKeyStore

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;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManager(javax.net.ssl.TrustManager)

Example 34 with PrivateKeyStore

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);
}
Also used : CertRecordStore(com.yahoo.athenz.common.server.cert.CertRecordStore) PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Example 35 with PrivateKeyStore

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);
    }
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Aggregations

PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)36 Test (org.testng.annotations.Test)35 ResourceException (com.yahoo.athenz.zts.ResourceException)8 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)6 ServerPrivateKey (com.yahoo.athenz.auth.ServerPrivateKey)3 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)3 ZTSClientNotificationSender (com.yahoo.athenz.zts.ZTSClientNotificationSender)3 ZTSClientNotificationSenderImpl (com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl)3 CertRecordStore (com.yahoo.athenz.common.server.cert.CertRecordStore)2 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)2 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)2 FilePrivateKeyStore (com.yahoo.athenz.auth.impl.FilePrivateKeyStore)1 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 SecureRandom (java.security.SecureRandom)1 KeyManager (javax.net.ssl.KeyManager)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1