Search in sources :

Example 1 with HashicorpConnection

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

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

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

Example 4 with HashicorpConnection

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

the class HashicorpVaultAccessAcceptanceTest method fetchSecretFromVault.

private String fetchSecretFromVault(final Path configFilePath) {
    final HashicorpKeyConfig config = TomlConfigLoader.fromToml(configFilePath, null);
    final HashicorpConnectionFactory factory = new HashicorpConnectionFactory(vertx);
    final HashicorpConnection connection = factory.create(config.getConnectionParams());
    return connection.fetchKey(config.getKeyDefinition());
}
Also used : HashicorpConnectionFactory(tech.pegasys.signers.hashicorp.HashicorpConnectionFactory) HashicorpConnection(tech.pegasys.signers.hashicorp.HashicorpConnection) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)

Aggregations

HashicorpConnection (tech.pegasys.signers.hashicorp.HashicorpConnection)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)2 ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)2 KeyDefinition (tech.pegasys.signers.hashicorp.config.KeyDefinition)2 TlsOptions (tech.pegasys.signers.hashicorp.config.TlsOptions)2 Credentials (org.web3j.crypto.Credentials)1 HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)1 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)1 CredentialSigner (tech.pegasys.signers.secp256k1.filebased.CredentialSigner)1