Search in sources :

Example 1 with HashicorpException

use of tech.pegasys.signers.hashicorp.HashicorpException 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)

Example 2 with HashicorpException

use of tech.pegasys.signers.hashicorp.HashicorpException in project signers by ConsenSys.

the class TomlConfigLoader method loadTlsOptions.

private Optional<TlsOptions> loadTlsOptions(final TomlTable tomlInput) {
    final boolean tlsEnabled = tomlInput.getBoolean(PROP_HASHICORP_TLS_ENABLE, () -> true);
    final String trustStoreString = tomlInput.getString(PROP_HASHICORP_TLS_TS_TYPE);
    final String trustStorePath = tomlInput.getString(PROP_HASHICORP_TLS_TS_PATH);
    final String trustStorePassword = tomlInput.getString(PROP_HASHICORP_TLS_TS_PASSWORD);
    if (!tlsEnabled) {
        return Optional.empty();
    }
    final TrustStoreType trustStoreType = decodeTrustStoreType(trustStoreString);
    if (trustStoreType != null) {
        if (trustStorePath == null) {
            final String error = String.format("%s must be specified if custom trust store (%s) is specified", PROP_HASHICORP_TLS_TS_PATH, PROP_HASHICORP_TLS_TS_TYPE);
            throw new HashicorpException(error);
        }
        if (trustStoreType.isPasswordRequired() && (trustStorePassword == null)) {
            final String error = String.format("%s must be specified if custom trust store (%s) is specified", PROP_HASHICORP_TLS_TS_PASSWORD, trustStoreType.name());
            throw new HashicorpException(constructErrorMessage(error));
        }
    }
    return Optional.of(new TlsOptions(Optional.ofNullable(trustStoreType), trustStorePath == null ? null : Path.of(trustStorePath), trustStorePassword));
}
Also used : HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) TrustStoreType(tech.pegasys.signers.hashicorp.TrustStoreType) TlsOptions(tech.pegasys.signers.hashicorp.config.TlsOptions)

Example 3 with HashicorpException

use of tech.pegasys.signers.hashicorp.HashicorpException in project signers by ConsenSys.

the class HashicorpSignerFactory method create.

public Signer create(final HashicorpKeyConfig keyConfig) {
    try {
        final HashicorpConnectionFactory connectionFactory = new HashicorpConnectionFactory(vertx);
        final HashicorpConnection connection = connectionFactory.create(keyConfig.getConnectionParams());
        final String secret = connection.fetchKey(keyConfig.getKeyDefinition());
        final Credentials credentials = Credentials.create(secret);
        return new CredentialSigner(credentials);
    } catch (final HashicorpException e) {
        throw new SignerInitializationException("Failed to extract secret from Hashicorp vault.", e);
    }
}
Also used : SignerInitializationException(tech.pegasys.signers.secp256k1.common.SignerInitializationException) CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) HashicorpConnectionFactory(tech.pegasys.signers.hashicorp.HashicorpConnectionFactory) HashicorpConnection(tech.pegasys.signers.hashicorp.HashicorpConnection) HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) Credentials(org.web3j.crypto.Credentials)

Aggregations

HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)3 TomlParseResult (org.apache.tuweni.toml.TomlParseResult)1 TomlTable (org.apache.tuweni.toml.TomlTable)1 Credentials (org.web3j.crypto.Credentials)1 HashicorpConnection (tech.pegasys.signers.hashicorp.HashicorpConnection)1 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)1 TrustStoreType (tech.pegasys.signers.hashicorp.TrustStoreType)1 ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)1 HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)1 KeyDefinition (tech.pegasys.signers.hashicorp.config.KeyDefinition)1 TlsOptions (tech.pegasys.signers.hashicorp.config.TlsOptions)1 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)1 CredentialSigner (tech.pegasys.signers.secp256k1.filebased.CredentialSigner)1