Search in sources :

Example 1 with TomlStringBuilder

use of tech.pegasys.signers.secp256k1.common.TomlStringBuilder in project signers by ConsenSys.

the class MultiKeyTomlFileUtil method createHashicorpTomlFileAt.

public static void createHashicorpTomlFileAt(final Path tomlPath, final HashicorpSigningParams hashicorpNode) {
    try {
        final Optional<SelfSignedCertificate> tlsCert = hashicorpNode.getServerCertificate();
        String trustStorePath = null;
        if (tlsCert.isPresent()) {
            trustStorePath = CertificateHelpers.createFingerprintFile(tomlPath.getParent(), tlsCert.get(), Optional.of(hashicorpNode.getPort())).toString();
        }
        final String hashicorpSignerToml = HashicorpConfigUtil.createTomlConfig(hashicorpNode.getHost(), hashicorpNode.getPort(), hashicorpNode.getVaultToken(), hashicorpNode.getSecretHttpPath(), hashicorpNode.getSecretName(), 10_000, tlsCert.isPresent(), tlsCert.map(ignored -> "WHITELIST").orElse(null), trustStorePath, null);
        final TomlStringBuilder tomlBuilder = new TomlStringBuilder("signing");
        tomlBuilder.withQuotedString("type", "hashicorp-signer");
        final String toml = tomlBuilder.build() + hashicorpSignerToml;
        createTomlFile(tomlPath, toml);
    } catch (final Exception e) {
        throw new RuntimeException("Failed to construct a valid hashicorp TOML file", e);
    }
}
Also used : SelfSignedCertificate(tech.pegasys.signers.hashicorp.dsl.certificates.SelfSignedCertificate) TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder) IOException(java.io.IOException)

Example 2 with TomlStringBuilder

use of tech.pegasys.signers.secp256k1.common.TomlStringBuilder in project signers by ConsenSys.

the class MultiKeyTomlFileUtil method createRawSignerTomlFileAt.

public static void createRawSignerTomlFileAt(final Path tomlPath, final String privKeyHexString) {
    final String toml = new TomlStringBuilder("signing").withQuotedString("type", "raw-signer").withQuotedString("priv-key", privKeyHexString).build();
    createTomlFile(tomlPath, toml);
}
Also used : TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder)

Example 3 with TomlStringBuilder

use of tech.pegasys.signers.secp256k1.common.TomlStringBuilder in project signers by ConsenSys.

the class HashicorpSigningMetadataTomlConfigLoaderTest method createTomlFile.

private void createTomlFile(final String toml) throws IOException {
    // creates metadata
    final String metaDataToml = new TomlStringBuilder("metadata").withNonQuotedString("createdAt", DateTimeFormatter.ISO_INSTANT.format(Instant.now())).withQuotedString("description", "Test Multisign Toml").build();
    Files.write(Files.createTempFile(configsDirectory, "test", ".toml"), List.of(metaDataToml, toml));
}
Also used : TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder)

Example 4 with TomlStringBuilder

use of tech.pegasys.signers.secp256k1.common.TomlStringBuilder 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)

Aggregations

TomlStringBuilder (tech.pegasys.signers.secp256k1.common.TomlStringBuilder)4 IOException (java.io.IOException)1 Test (org.junit.jupiter.api.Test)1 ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)1 HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)1 SelfSignedCertificate (tech.pegasys.signers.hashicorp.dsl.certificates.SelfSignedCertificate)1 HashicorpSigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.HashicorpSigningMetadataFile)1 SigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.SigningMetadataFile)1