Search in sources :

Example 1 with AzureKeyVaultSignerFactory

use of tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory 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 2 with AzureKeyVaultSignerFactory

use of tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory 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 3 with AzureKeyVaultSignerFactory

use of tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory in project signers by ConsenSys.

the class MultiKeySignerProvider method createSigner.

@Override
public Signer createSigner(final AzureSigningMetadataFile metadataFile) {
    try {
        final AzureConfig config = metadataFile.getConfig();
        final AzureKeyVaultSignerFactory azureFactory = new AzureKeyVaultSignerFactory();
        return azureFactory.createSigner(config);
    } catch (final SignerInitializationException e) {
        LOG.error("Failed to construct Azure signer from " + metadataFile.getFilename());
        return null;
    }
}
Also used : SignerInitializationException(tech.pegasys.signers.secp256k1.common.SignerInitializationException) AzureConfig(tech.pegasys.signers.secp256k1.azure.AzureConfig) AzureKeyVaultSignerFactory(tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory)

Example 4 with AzureKeyVaultSignerFactory

use of tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory in project web3signer by ConsenSys.

the class FilecoinRunner method createArtifactSignerProvider.

@Override
protected ArtifactSignerProvider createArtifactSignerProvider(final Vertx vertx, final MetricsSystem metricsSystem) {
    return new DefaultArtifactSignerProvider(() -> {
        final AzureKeyVaultSignerFactory azureFactory = new AzureKeyVaultSignerFactory();
        final HashicorpConnectionFactory hashicorpConnectionFactory = new HashicorpConnectionFactory(vertx);
        try (final InterlockKeyProvider interlockKeyProvider = new InterlockKeyProvider(vertx);
            final YubiHsmOpaqueDataProvider yubiHsmOpaqueDataProvider = new YubiHsmOpaqueDataProvider();
            final AwsSecretsManagerProvider awsSecretsManagerProvider = new AwsSecretsManagerProvider(AWS_CACHE_MAXIMUM_SIZE)) {
            final AbstractArtifactSignerFactory blsArtifactSignerFactory = new BlsArtifactSignerFactory(config.getKeyConfigPath(), metricsSystem, hashicorpConnectionFactory, interlockKeyProvider, yubiHsmOpaqueDataProvider, awsSecretsManagerProvider, (args) -> new FcBlsArtifactSigner(args.getKeyPair(), network));
            final AbstractArtifactSignerFactory secpArtifactSignerFactory = new Secp256k1ArtifactSignerFactory(hashicorpConnectionFactory, config.getKeyConfigPath(), azureFactory, interlockKeyProvider, yubiHsmOpaqueDataProvider, signer -> new FcSecpArtifactSigner(signer, network), false);
            return new SignerLoader().load(config.getKeyConfigPath(), "yaml", new YamlSignerParser(List.of(blsArtifactSignerFactory, secpArtifactSignerFactory)));
        }
    });
}
Also used : HashicorpConnectionFactory(tech.pegasys.signers.hashicorp.HashicorpConnectionFactory) FcBlsArtifactSigner(tech.pegasys.web3signer.signing.FcBlsArtifactSigner) YamlSignerParser(tech.pegasys.web3signer.signing.config.metadata.parser.YamlSignerParser) AbstractArtifactSignerFactory(tech.pegasys.web3signer.signing.config.metadata.AbstractArtifactSignerFactory) SignerLoader(tech.pegasys.web3signer.signing.config.SignerLoader) InterlockKeyProvider(tech.pegasys.web3signer.signing.config.metadata.interlock.InterlockKeyProvider) AwsSecretsManagerProvider(tech.pegasys.signers.aws.AwsSecretsManagerProvider) Secp256k1ArtifactSignerFactory(tech.pegasys.web3signer.signing.config.metadata.Secp256k1ArtifactSignerFactory) YubiHsmOpaqueDataProvider(tech.pegasys.web3signer.signing.config.metadata.yubihsm.YubiHsmOpaqueDataProvider) DefaultArtifactSignerProvider(tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider) BlsArtifactSignerFactory(tech.pegasys.web3signer.signing.config.metadata.BlsArtifactSignerFactory) FcSecpArtifactSigner(tech.pegasys.web3signer.signing.FcSecpArtifactSigner) AzureKeyVaultSignerFactory(tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory)

Example 5 with AzureKeyVaultSignerFactory

use of tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory in project web3signer by ConsenSys.

the class Eth1Runner method createArtifactSignerProvider.

@Override
protected ArtifactSignerProvider createArtifactSignerProvider(final Vertx vertx, final MetricsSystem metricsSystem) {
    return new DefaultArtifactSignerProvider(() -> {
        final AzureKeyVaultSignerFactory azureFactory = new AzureKeyVaultSignerFactory();
        final HashicorpConnectionFactory hashicorpConnectionFactory = new HashicorpConnectionFactory(vertx);
        try (final InterlockKeyProvider interlockKeyProvider = new InterlockKeyProvider(vertx);
            final YubiHsmOpaqueDataProvider yubiHsmOpaqueDataProvider = new YubiHsmOpaqueDataProvider()) {
            final Secp256k1ArtifactSignerFactory ethSecpArtifactSignerFactory = new Secp256k1ArtifactSignerFactory(hashicorpConnectionFactory, config.getKeyConfigPath(), azureFactory, interlockKeyProvider, yubiHsmOpaqueDataProvider, EthSecpArtifactSigner::new, true);
            return new SignerLoader().load(config.getKeyConfigPath(), "yaml", new YamlSignerParser(List.of(ethSecpArtifactSignerFactory)));
        }
    });
}
Also used : YubiHsmOpaqueDataProvider(tech.pegasys.web3signer.signing.config.metadata.yubihsm.YubiHsmOpaqueDataProvider) EthSecpArtifactSigner(tech.pegasys.web3signer.signing.EthSecpArtifactSigner) HashicorpConnectionFactory(tech.pegasys.signers.hashicorp.HashicorpConnectionFactory) DefaultArtifactSignerProvider(tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider) YamlSignerParser(tech.pegasys.web3signer.signing.config.metadata.parser.YamlSignerParser) SignerLoader(tech.pegasys.web3signer.signing.config.SignerLoader) InterlockKeyProvider(tech.pegasys.web3signer.signing.config.metadata.interlock.InterlockKeyProvider) Secp256k1ArtifactSignerFactory(tech.pegasys.web3signer.signing.config.metadata.Secp256k1ArtifactSignerFactory) AzureKeyVaultSignerFactory(tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory)

Aggregations

AzureKeyVaultSignerFactory (tech.pegasys.signers.secp256k1.azure.AzureKeyVaultSignerFactory)3 Test (org.junit.jupiter.api.Test)2 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)2 Signer (tech.pegasys.signers.secp256k1.api.Signer)2 DefaultArtifactSignerProvider (tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider)2 SignerLoader (tech.pegasys.web3signer.signing.config.SignerLoader)2 Secp256k1ArtifactSignerFactory (tech.pegasys.web3signer.signing.config.metadata.Secp256k1ArtifactSignerFactory)2 InterlockKeyProvider (tech.pegasys.web3signer.signing.config.metadata.interlock.InterlockKeyProvider)2 YamlSignerParser (tech.pegasys.web3signer.signing.config.metadata.parser.YamlSignerParser)2 YubiHsmOpaqueDataProvider (tech.pegasys.web3signer.signing.config.metadata.yubihsm.YubiHsmOpaqueDataProvider)2 BigInteger (java.math.BigInteger)1 SignatureData (org.web3j.crypto.Sign.SignatureData)1 AwsSecretsManagerProvider (tech.pegasys.signers.aws.AwsSecretsManagerProvider)1 Signature (tech.pegasys.signers.secp256k1.api.Signature)1 AzureConfig (tech.pegasys.signers.secp256k1.azure.AzureConfig)1 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)1 EthSecpArtifactSigner (tech.pegasys.web3signer.signing.EthSecpArtifactSigner)1 FcBlsArtifactSigner (tech.pegasys.web3signer.signing.FcBlsArtifactSigner)1 FcSecpArtifactSigner (tech.pegasys.web3signer.signing.FcSecpArtifactSigner)1 AbstractArtifactSignerFactory (tech.pegasys.web3signer.signing.config.metadata.AbstractArtifactSignerFactory)1