use of tech.pegasys.signers.secp256k1.api.Signer 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.api.Signer 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.api.Signer in project signers by ConsenSys.
the class AzureKeyVaultSignerTest method azureWithoutHashingDoesntHashData.
@Test
void azureWithoutHashingDoesntHashData() throws SignatureException {
final AzureConfig config = new AzureConfig(keyVaultName, KEY_NAME, "", clientId, clientSecret, tenantId);
final Signer azureNonHashedDataSigner = new AzureKeyVaultSignerFactory(false).createSigner(config);
final BigInteger publicKey = Numeric.toBigInt(EthPublicKeyUtils.toByteArray(azureNonHashedDataSigner.getPublicKey()));
final byte[] dataToSign = "Hello World".getBytes(UTF_8);
// manual hash before sending to remote signing
final byte[] hashedData = Hash.sha3(dataToSign);
final Signature signature = azureNonHashedDataSigner.sign(hashedData);
// Determine if Web3j thinks the signature comes from the public key used (really proves
// that the hashedData isn't hashed a second time).
final SignatureData sigData = new SignatureData(signature.getV().toByteArray(), Numeric.toBytesPadded(signature.getR(), 32), Numeric.toBytesPadded(signature.getS(), 32));
final BigInteger recoveredPublicKey = Sign.signedMessageHashToKey(hashedData, sigData);
assertThat(recoveredPublicKey).isEqualTo(publicKey);
}
use of tech.pegasys.signers.secp256k1.api.Signer in project signers by ConsenSys.
the class AzureKeyVaultSignerTest method azureSignerCanSignTwice.
@Test
public void azureSignerCanSignTwice() {
final AzureConfig config = new AzureConfig(keyVaultName, KEY_NAME, "", clientId, clientSecret, tenantId);
final AzureKeyVaultSignerFactory factory = new AzureKeyVaultSignerFactory();
final Signer signer = factory.createSigner(config);
final byte[] dataToHash = "Hello World".getBytes(UTF_8);
signer.sign(dataToHash);
signer.sign(dataToHash);
}
use of tech.pegasys.signers.secp256k1.api.Signer in project signers by ConsenSys.
the class MultiKeySignerProviderTest method signerIsLoadedSuccessfullyWhenAddressHasCaseMismatchToFilename.
@Test
void signerIsLoadedSuccessfullyWhenAddressHasCaseMismatchToFilename() throws URISyntaxException {
final FileBasedSigningMetadataFile capitalisedMetadata = new FileBasedSigningMetadataFile(LOWERCASE_ADDRESS + ".toml", new FileSignerConfig(Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(KEY_FILENAME), Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(PASSWORD_FILENAME)));
final Signer signer = signerFactory.createSigner(capitalisedMetadata);
assertThat(signer).isNotNull();
assertThat(EthPublicKeyUtils.toHexString(signer.getPublicKey())).isEqualTo("0x" + LOWER_CASE_PUBLIC_KEY);
}
Aggregations