Search in sources :

Example 1 with KeyDefinition

use of tech.pegasys.signers.hashicorp.config.KeyDefinition in project web3signer by ConsenSys.

the class AbstractArtifactSignerFactory method extractBytesFromVault.

protected Bytes extractBytesFromVault(final HashicorpSigningMetadata metadata) {
    final Optional<TlsOptions> tlsOptions = buildTlsOptions(metadata);
    try {
        final HashicorpConnection connection = hashicorpConnectionFactory.create(new ConnectionParameters(metadata.getServerHost(), Optional.ofNullable(metadata.getServerPort()), tlsOptions, Optional.ofNullable(metadata.getTimeout())));
        final String secret = connection.fetchKey(new KeyDefinition(metadata.getKeyPath(), Optional.ofNullable(metadata.getKeyName()), metadata.getToken()));
        return Bytes.fromHexString(secret);
    } catch (final Exception e) {
        throw new SigningMetadataException("Failed to fetch secret from hashicorp vault", e);
    }
}
Also used : HashicorpConnection(tech.pegasys.signers.hashicorp.HashicorpConnection) ConnectionParameters(tech.pegasys.signers.hashicorp.config.ConnectionParameters) TlsOptions(tech.pegasys.signers.hashicorp.config.TlsOptions) KeyDefinition(tech.pegasys.signers.hashicorp.config.KeyDefinition) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with KeyDefinition

use of tech.pegasys.signers.hashicorp.config.KeyDefinition in project web3signer by ConsenSys.

the class AbstractArtifactSignerFactory method extractBytesFromVault.

protected Bytes extractBytesFromVault(final HashicorpSigningMetadata metadata) {
    final Optional<TlsOptions> tlsOptions = buildTlsOptions(metadata);
    try {
        final HashicorpConnection connection = hashicorpConnectionFactory.create(new ConnectionParameters(metadata.getServerHost(), Optional.ofNullable(metadata.getServerPort()), tlsOptions, Optional.ofNullable(metadata.getTimeout())));
        final String secret = connection.fetchKey(new KeyDefinition(metadata.getKeyPath(), Optional.ofNullable(metadata.getKeyName()), metadata.getToken()));
        return Bytes.fromHexString(secret);
    } catch (final Exception e) {
        throw new SigningMetadataException("Failed to fetch secret from hashicorp vault", e);
    }
}
Also used : HashicorpConnection(tech.pegasys.signers.hashicorp.HashicorpConnection) ConnectionParameters(tech.pegasys.signers.hashicorp.config.ConnectionParameters) TlsOptions(tech.pegasys.signers.hashicorp.config.TlsOptions) KeyDefinition(tech.pegasys.signers.hashicorp.config.KeyDefinition) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with KeyDefinition

use of tech.pegasys.signers.hashicorp.config.KeyDefinition in project signers by ConsenSys.

the class TomlConfigLoader method parse.

public HashicorpKeyConfig parse(final String tableName) {
    final TomlParser tomlParser = new TomlParser();
    final TomlParseResult tomlResult = tomlParser.getTomlParseResult(fileToParse);
    TomlTable tableToParse = tomlResult;
    if (tableName != null) {
        tableToParse = tomlResult.getTable(tableName);
    }
    if (tableToParse == null) {
        final String error = String.format("Toml table %s is missing", tableName);
        throw new HashicorpException(constructErrorMessage(error));
    }
    final KeyDefinition keyDefinition = loadKeyDefinition(tableToParse);
    final ConnectionParameters connectionsParams = loadConnectionParams(tableToParse);
    return new HashicorpKeyConfig(connectionsParams, keyDefinition);
}
Also used : TomlTable(org.apache.tuweni.toml.TomlTable) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) ConnectionParameters(tech.pegasys.signers.hashicorp.config.ConnectionParameters) HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) KeyDefinition(tech.pegasys.signers.hashicorp.config.KeyDefinition) TomlParseResult(org.apache.tuweni.toml.TomlParseResult)

Aggregations

ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)3 KeyDefinition (tech.pegasys.signers.hashicorp.config.KeyDefinition)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashicorpConnection (tech.pegasys.signers.hashicorp.HashicorpConnection)2 TlsOptions (tech.pegasys.signers.hashicorp.config.TlsOptions)2 TomlParseResult (org.apache.tuweni.toml.TomlParseResult)1 TomlTable (org.apache.tuweni.toml.TomlTable)1 HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)1