use of tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig in project signers by ConsenSys.
the class TomlConfigLoaderTest method tlsValuesAreExtracted.
@Test
void tlsValuesAreExtracted() throws IOException {
final Path configFile = HashicorpConfigUtil.createConfigFile(HOST, PORT, TOKEN, KEY_PATH, KEY_NAME, TIMEOUT, true, TRUST_STORE_TYPE, TRUST_STORE_PATH_STRING, TRUST_STORE_PASSWORD);
final HashicorpKeyConfig config = TomlConfigLoader.fromToml(configFile, null);
assertThat(config.getConnectionParams().getTlsOptions()).isNotEmpty();
final TlsOptions tlsOptions = config.getConnectionParams().getTlsOptions().get();
assertThat(tlsOptions.getTrustStoreType().get()).isEqualTo(TrustStoreType.fromString(TRUST_STORE_TYPE).get());
assertThat(tlsOptions.getTrustStorePath()).isEqualTo(Path.of(TRUST_STORE_PATH_STRING));
assertThat(tlsOptions.getTrustStorePassword()).isEqualTo(TRUST_STORE_PASSWORD);
}
use of tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig in project signers by ConsenSys.
the class HashicorpIntegrationTest method hashicorpVaultReturnsEncryptionKeyOverTls.
@Test
void hashicorpVaultReturnsEncryptionKeyOverTls() throws IOException {
KeyStoreFactory keyStoreFactory = new KeyStoreFactory(new MockServerLogger());
keyStoreFactory.loadOrCreateKeyStore();
HttpsURLConnection.setDefaultSSLSocketFactory(keyStoreFactory.sslContext().getSocketFactory());
final ClientAndServer clientAndServer = new ClientAndServer(0);
clientAndServer.when(request().withPath(".*")).respond(response().withStatusCode(200).withBody("{\"data\":{\"data\":{\"value\":\"" + EXPECTED_KEY_STRING + "\"}}}"));
final Path configFile = createConfigFile(DEFAULT_HOST, clientAndServer.getLocalPort(), ROOT_TOKEN, KEY_PATH, null, TIMEOUT_MILLISECONDS, true, "JKS", keyStoreFactory.keyStoreFileName, KeyStoreFactory.KEY_STORE_PASSWORD);
final HashicorpKeyConfig keyConfig = TomlConfigLoader.fromToml(configFile, null);
final HashicorpConnection connection = factory.create(keyConfig.getConnectionParams());
final String keyFetched = connection.fetchKey(keyConfig.getKeyDefinition());
assertThat(keyFetched).isEqualTo(EXPECTED_KEY_STRING);
}
use of tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig in project signers by ConsenSys.
the class HashicorpSigningMetadataTomlConfigLoaderTest method hashicorpConfigIsLoadedIfHashicorpMetadataFileInDirectory.
@Test
void hashicorpConfigIsLoadedIfHashicorpMetadataFileInDirectory() throws IOException {
final String hashicorpSignerToml = HashicorpConfigUtil.createTomlConfig("Host", 9999, "token", "/path/to/key", "key_name", 10000, true, null, null, null);
final TomlStringBuilder tomlBuilder = new TomlStringBuilder("signing");
tomlBuilder.withQuotedString("type", "hashicorp-signer");
final String toml = tomlBuilder.build() + hashicorpSignerToml;
createTomlFile(toml);
final Collection<SigningMetadataFile> metadataFiles = loader.loadAvailableSigningMetadataTomlConfigs(entry -> true);
assertThat(metadataFiles.size()).isOne();
assertThat(metadataFiles.toArray()[0]).isInstanceOf(HashicorpSigningMetadataFile.class);
final HashicorpSigningMetadataFile metadataFile = (HashicorpSigningMetadataFile) metadataFiles.toArray()[0];
final HashicorpKeyConfig hashicorpConfig = metadataFile.getConfig();
final ConnectionParameters connectionParams = hashicorpConfig.getConnectionParams();
assertThat(connectionParams.getServerHost()).isEqualTo("Host");
assertThat(connectionParams.getServerPort().get()).isEqualTo(9999);
assertThat(connectionParams.getTimeoutMilliseconds().get()).isEqualTo(10000);
assertThat(connectionParams.getTlsOptions()).isNotEmpty();
assertThat(connectionParams.getTlsOptions().get().getTrustStoreType()).isEmpty();
assertThat(hashicorpConfig.getKeyDefinition().getKeyPath()).isEqualTo("/path/to/key");
assertThat(hashicorpConfig.getKeyDefinition().getKeyName().get()).isEqualTo("key_name");
assertThat(hashicorpConfig.getKeyDefinition().getToken()).isEqualTo("token");
}
use of tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig in project signers by ConsenSys.
the class TomlConfigLoaderTest method valuesInATomlFileWithNoTlsAreExtractedAsPerFileContent.
@Test
void valuesInATomlFileWithNoTlsAreExtractedAsPerFileContent() throws IOException {
final Path configFile = HashicorpConfigUtil.createConfigFileWithoutTls(HOST, PORT, TOKEN, KEY_PATH, KEY_NAME, TIMEOUT);
final HashicorpKeyConfig config = TomlConfigLoader.fromToml(configFile, null);
assertThat(config.getConnectionParams().getServerHost()).isEqualTo(HOST);
assertThat(config.getConnectionParams().getServerPort().get()).isEqualTo(PORT);
assertThat(config.getConnectionParams().getTimeoutMilliseconds().get()).isEqualTo(TIMEOUT);
assertThat(config.getConnectionParams().getTlsOptions()).isEmpty();
assertThat(config.getKeyDefinition().getToken()).isEqualTo(TOKEN);
assertThat(config.getKeyDefinition().getKeyPath()).isEqualTo(KEY_PATH);
assertThat(config.getKeyDefinition().getKeyName().get()).isEqualTo(KEY_NAME);
}
use of tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig in project signers by ConsenSys.
the class TomlConfigLoaderTest method ifTlsIsDisabledAllFieldsNoFieldsAreReadIntoConfig.
@Test
void ifTlsIsDisabledAllFieldsNoFieldsAreReadIntoConfig() throws IOException {
final Path configFile = HashicorpConfigUtil.createConfigFile(HOST, PORT, TOKEN, KEY_PATH, KEY_NAME, TIMEOUT, false, TRUST_STORE_TYPE, TRUST_STORE_PATH_STRING, TRUST_STORE_PASSWORD);
final HashicorpKeyConfig config = TomlConfigLoader.fromToml(configFile, null);
assertThat(config.getConnectionParams().getTlsOptions()).isEmpty();
}
Aggregations