Search in sources :

Example 1 with HashicorpKeyConfig

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);
}
Also used : Path(java.nio.file.Path) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) TlsOptions(tech.pegasys.signers.hashicorp.config.TlsOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HashicorpKeyConfig

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);
}
Also used : Path(java.nio.file.Path) KeyStoreFactory(org.mockserver.socket.tls.KeyStoreFactory) MockServerLogger(org.mockserver.logging.MockServerLogger) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) ClientAndServer(org.mockserver.integration.ClientAndServer) Test(org.junit.jupiter.api.Test)

Example 3 with HashicorpKeyConfig

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");
}
Also used : SigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.SigningMetadataFile) HashicorpSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.HashicorpSigningMetadataFile) TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) ConnectionParameters(tech.pegasys.signers.hashicorp.config.ConnectionParameters) HashicorpSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.HashicorpSigningMetadataFile) Test(org.junit.jupiter.api.Test)

Example 4 with HashicorpKeyConfig

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);
}
Also used : Path(java.nio.file.Path) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with HashicorpKeyConfig

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();
}
Also used : Path(java.nio.file.Path) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)12 Test (org.junit.jupiter.api.Test)9 Path (java.nio.file.Path)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ClientAndServer (org.mockserver.integration.ClientAndServer)4 ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)2 HashicorpSigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.HashicorpSigningMetadataFile)2 TomlParseResult (org.apache.tuweni.toml.TomlParseResult)1 TomlTable (org.apache.tuweni.toml.TomlTable)1 MockServerLogger (org.mockserver.logging.MockServerLogger)1 KeyStoreFactory (org.mockserver.socket.tls.KeyStoreFactory)1 HashicorpConnection (tech.pegasys.signers.hashicorp.HashicorpConnection)1 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)1 HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 KeyDefinition (tech.pegasys.signers.hashicorp.config.KeyDefinition)1 TlsOptions (tech.pegasys.signers.hashicorp.config.TlsOptions)1 TomlStringBuilder (tech.pegasys.signers.secp256k1.common.TomlStringBuilder)1 SigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.SigningMetadataFile)1