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);
}
}
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);
}
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));
}
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");
}
Aggregations