Search in sources :

Example 1 with BlsArtifactSigner

use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.

the class YamlSignerParserTest method azureSecretMetadataInfoReturnsMetadata.

@Test
void azureSecretMetadataInfoReturnsMetadata() throws IOException {
    final BlsArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.AZURE);
    when(blsArtifactSignerFactory.create(any(AzureSecretSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> azureMetaDataMap = new HashMap<>();
    azureMetaDataMap.put("type", "azure-secret");
    azureMetaDataMap.put("clientId", "sample-client-id");
    azureMetaDataMap.put("clientSecret", "sample-client-secret");
    azureMetaDataMap.put("tenantId", "sample-tenant-id");
    azureMetaDataMap.put("vaultName", "sample-vault-name");
    azureMetaDataMap.put("secretName", "TEST-KEY");
    azureMetaDataMap.put("keyType", "BLS");
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasCorrectAzureMetadataArguments(AzureAuthenticationMode.CLIENT_SECRET));
}
Also used : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) AzureSecretSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.AzureSecretSigningMetadata) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with BlsArtifactSigner

use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.

the class YamlSignerParserTest method unencryptedMetaDataInfoWith0xPrefixPrivateKeyReturnsMetadata.

@Test
void unencryptedMetaDataInfoWith0xPrefixPrivateKeyReturnsMetadata() throws IOException {
    final ArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.FILE_RAW);
    when(blsArtifactSignerFactory.create(any(FileRawSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> unencryptedKeyMetadataFile = new HashMap<>();
    unencryptedKeyMetadataFile.put("type", "file-raw");
    unencryptedKeyMetadataFile.put("privateKey", "0x" + PRIVATE_KEY);
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(unencryptedKeyMetadataFile);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasPrivateKey(PRIVATE_KEY));
}
Also used : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) FileRawSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BlsArtifactSigner

use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.

the class YamlSignerParserTest method unencryptedMetaDataInfoWithPrivateKeyReturnsMetadata.

@Test
void unencryptedMetaDataInfoWithPrivateKeyReturnsMetadata() throws IOException {
    final ArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.FILE_RAW);
    when(blsArtifactSignerFactory.create(any(FileRawSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> unencryptedKeyMetadataFile = new HashMap<>();
    unencryptedKeyMetadataFile.put("type", "file-raw");
    unencryptedKeyMetadataFile.put("privateKey", PRIVATE_KEY);
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(unencryptedKeyMetadataFile);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasPrivateKey(PRIVATE_KEY));
}
Also used : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) FileRawSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BlsArtifactSigner

use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.

the class ImportKeystoresHandler method decryptKeystoreAndCreateSigner.

private BlsArtifactSigner decryptKeystoreAndCreateSigner(String jsonKeystoreData, String password) throws JsonProcessingException, KeyStoreValidationException {
    final KeyStoreData keyStoreData = objectMapper.readValue(jsonKeystoreData, KeyStoreData.class);
    final Bytes privateKey = KeyStore.decrypt(password, keyStoreData);
    final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKey)));
    return new BlsArtifactSigner(keyPair, SignerOrigin.FILE_KEYSTORE, Optional.ofNullable(keyStoreData.getPath()));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 5 with BlsArtifactSigner

use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.

the class YamlSignerParserTest method azureSecretMetadataWithAuthenticationModeReturnsMetadata.

@ParameterizedTest
@EnumSource(AzureAuthenticationMode.class)
void azureSecretMetadataWithAuthenticationModeReturnsMetadata(final AzureAuthenticationMode authenticationMode) throws IOException {
    final BlsArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.AZURE);
    when(blsArtifactSignerFactory.create(any(AzureSecretSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> azureMetaDataMap = new HashMap<>();
    azureMetaDataMap.put("type", "azure-secret");
    azureMetaDataMap.put("clientId", "sample-client-id");
    azureMetaDataMap.put("clientSecret", "sample-client-secret");
    azureMetaDataMap.put("tenantId", "sample-tenant-id");
    azureMetaDataMap.put("vaultName", "sample-vault-name");
    azureMetaDataMap.put("secretName", "TEST-KEY");
    azureMetaDataMap.put("authenticationMode", authenticationMode.name());
    azureMetaDataMap.put("keyType", "BLS");
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasCorrectAzureMetadataArguments(authenticationMode));
}
Also used : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) AzureSecretSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.AzureSecretSigningMetadata) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)8 BlsArtifactSigner (tech.pegasys.web3signer.core.signing.BlsArtifactSigner)8 ArtifactSigner (tech.pegasys.web3signer.core.signing.ArtifactSigner)7 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 AzureSecretSigningMetadata (tech.pegasys.web3signer.core.multikey.metadata.AzureSecretSigningMetadata)3 Path (java.nio.file.Path)2 Bytes (org.apache.tuweni.bytes.Bytes)2 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)2 FileKeyStoreMetadata (tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata)2 FileRawSigningMetadata (tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata)2 Vertx (io.vertx.core.Vertx)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Bytes48 (org.apache.tuweni.bytes.Bytes48)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 AssertionsForClassTypes.fail (org.assertj.core.api.AssertionsForClassTypes.fail)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1