Search in sources :

Example 1 with Signer

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);
    }
}
Also used : SelfSignedCertificate(tech.pegasys.signers.hashicorp.dsl.certificates.SelfSignedCertificate) TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder) IOException(java.io.IOException)

Example 2 with Signer

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);
}
Also used : TomlStringBuilder(tech.pegasys.signers.secp256k1.common.TomlStringBuilder)

Example 3 with Signer

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);
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) SignatureData(org.web3j.crypto.Sign.SignatureData) Signature(tech.pegasys.signers.secp256k1.api.Signature) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 4 with Signer

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);
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) Test(org.junit.jupiter.api.Test)

Example 5 with Signer

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);
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) FileSignerConfig(tech.pegasys.signers.secp256k1.filebased.FileSignerConfig) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 Signer (tech.pegasys.signers.secp256k1.api.Signer)7 Signature (tech.pegasys.signers.secp256k1.api.Signature)4 Bytes (org.apache.tuweni.bytes.Bytes)3 PublicKeySignerIdentifier (tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier)3 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)3 TomlStringBuilder (tech.pegasys.signers.secp256k1.common.TomlStringBuilder)3 BigInteger (java.math.BigInteger)2 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)2 AzureKeyVaultSignerFactory (tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory)2 FileSignerConfig (tech.pegasys.signers.secp256k1.filebased.FileSignerConfig)2 FileBasedSigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile)2 CryptographyClient (com.azure.security.keyvault.keys.cryptography.CryptographyClient)1 JsonWebKey (com.azure.security.keyvault.keys.models.JsonWebKey)1 File (java.io.File)1 IOException (java.io.IOException)1 ECPublicKey (java.security.interfaces.ECPublicKey)1 Credentials (org.web3j.crypto.Credentials)1 ECDSASignature (org.web3j.crypto.ECDSASignature)1 SignatureData (org.web3j.crypto.Sign.SignatureData)1