/** * Sets up a bunch of objects that we need to run tests * * @param tdhDirectHost * @param tdhDirectPort * @param tdhOnionHost * @param tdhOnionPort * @param passPhrase * @param createClientBuilder * @param context * @param directProxy Normally null but sometimes not for some odder tests, this is used for what * are supposed to be local calls. * @param onionProxy This is the proxy that should be used with values like tdhOnionHost and * tdhOnionPort * @throws NoSuchAlgorithmException * @throws IOException * @throws UnrecoverableEntryException * @throws KeyStoreException * @throws KeyManagementException */ public ConfigureRequestObjects( String tdhDirectHost, int tdhDirectPort, String tdhOnionHost, int tdhOnionPort, char[] passPhrase, CreateClientBuilder createClientBuilder, Context context, Proxy directProxy, Proxy onionProxy) throws NoSuchAlgorithmException, IOException, UnrecoverableEntryException, KeyStoreException, KeyManagementException { File clientFilesDir = new File(context.getFilesDir(), clientSubDirectory); // We want to start with a new identity if (clientFilesDir.exists()) { FileUtils.deleteDirectory(clientFilesDir); } if (clientFilesDir.mkdirs() == false) { throw new RuntimeException(); } thaliCouchDbInstance = ThaliClientToDeviceHubUtilities.GetLocalCouchDbInstance( clientFilesDir, createClientBuilder, tdhDirectHost, tdhDirectPort, passPhrase, directProxy); thaliCouchDbInstance.deleteDatabase(ThaliTestUtilities.TestDatabaseName); thaliCouchDbInstance.deleteDatabase(ThaliTestEktorpClient.ReplicationTestDatabaseName); testDatabaseConnector = thaliCouchDbInstance.createConnector(ThaliTestUtilities.TestDatabaseName, false); clientKeyStore = ThaliCryptoUtilities.validateThaliKeyStore(clientFilesDir); org.apache.http.client.HttpClient httpClientNoServerValidation = createClientBuilder.CreateApacheClient( tdhDirectHost, tdhDirectPort, null, clientKeyStore, passPhrase, directProxy); serverPublicKey = ThaliClientToDeviceHubUtilities.getServersRootPublicKey(httpClientNoServerValidation); KeyStore.PrivateKeyEntry clientPrivateKeyEntry = ThaliCryptoUtilities.getThaliListenerKeyStoreEntry(clientKeyStore, passPhrase); clientPublicKey = clientPrivateKeyEntry.getCertificate().getPublicKey(); replicationDatabaseConnector = thaliCouchDbInstance.createConnector( ThaliTestEktorpClient.ReplicationTestDatabaseName, false); if (tdhOnionHost != null && tdhOnionHost.isEmpty() == false) { HttpClient torHttpClient = createClientBuilder.CreateEktorpClient( tdhOnionHost, tdhOnionPort, serverPublicKey, clientKeyStore, passPhrase, onionProxy); torThaliCouchDbInstance = new ThaliCouchDbInstance(torHttpClient); torTestDatabaseConnector = torThaliCouchDbInstance.createConnector(ThaliTestUtilities.TestDatabaseName, false); torReplicationDatabaseConnector = torThaliCouchDbInstance.createConnector( ThaliTestEktorpClient.ReplicationTestDatabaseName, false); } else { torThaliCouchDbInstance = null; torTestDatabaseConnector = null; torReplicationDatabaseConnector = null; } }