Search in sources :

Example 1 with ArtifactSigner

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

the class SignerLoaderTest method signerReturnedWhenFileExtensionIsUpperCase.

@Test
void signerReturnedWhenFileExtensionIsUpperCase() throws IOException {
    final String filename = PUBLIC_KEY1 + ".YAML";
    final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
    when(signerParser.parse(any())).thenReturn(artifactSigner);
    final List<ArtifactSigner> signerList = Lists.newArrayList(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY1);
    verify(signerParser).parse(Files.readString(metadataFile, StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 2 with ArtifactSigner

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

the class SignerLoaderTest method signerIdentifiersNotReturnedForHiddenFiles.

@Test
void signerIdentifiersNotReturnedForHiddenFiles() throws IOException {
    final Path key1 = createFileInConfigsDirectory(PUBLIC_KEY1 + "." + FILE_EXTENSION, PRIVATE_KEY1);
    FileHiddenUtil.makeFileHidden(key1);
    final Path key2 = createFileInConfigsDirectory(PUBLIC_KEY2 + "." + FILE_EXTENSION, PRIVATE_KEY2);
    // Using lenient so it's clear key is not returned due file being hidden instead no stub
    final Map<String, String> unencryptedKeyMetadataFile = new HashMap<>();
    unencryptedKeyMetadataFile.put("type", "file-raw");
    unencryptedKeyMetadataFile.put("privateKey", "0x" + PRIVATE_KEY1);
    final String yamlContentKey1 = YAML_OBJECT_MAPPER.writeValueAsString(unencryptedKeyMetadataFile);
    lenient().when(signerParser.parse(yamlContentKey1)).thenReturn(createArtifactSigner(PRIVATE_KEY1));
    when(signerParser.parse(Files.readString(key2, StandardCharsets.UTF_8))).thenReturn(createArtifactSigner(PRIVATE_KEY2));
    final List<ArtifactSigner> signerList = Lists.newArrayList(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY2);
    verify(signerParser, never()).parse(yamlContentKey1);
    verify(signerParser).parse(Files.readString(key2, StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 3 with ArtifactSigner

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

the class SignerLoaderTest method signerReturnedWhenIdentifierHasCaseMismatchToFilename.

@Test
void signerReturnedWhenIdentifierHasCaseMismatchToFilename() throws IOException {
    final String filename = "arbitraryFilename." + FILE_EXTENSION;
    final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
    when(signerParser.parse(any())).thenReturn(artifactSigner);
    final List<ArtifactSigner> signerList = Lists.newArrayList(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY1);
    verify(signerParser).parse(Files.readString(metadataFile, StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 4 with ArtifactSigner

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

the class SignerLoaderTest method signerReturnedForValidMetadataFile.

@Test
void signerReturnedForValidMetadataFile() throws IOException {
    final String filename = PUBLIC_KEY1 + "." + FILE_EXTENSION;
    final Path metadataFile = createFileInConfigsDirectory(filename, PRIVATE_KEY1);
    when(signerParser.parse(Files.readString(metadataFile, StandardCharsets.UTF_8))).thenReturn(artifactSigner);
    final List<ArtifactSigner> signerList = Lists.newArrayList(SignerLoader.load(configsDirectory, FILE_EXTENSION, signerParser));
    verify(signerParser).parse(Files.readString(metadataFile, StandardCharsets.UTF_8));
    assertThat(signerList.size()).isOne();
    assertThat(signerList.get(0).getIdentifier()).isEqualTo("0x" + PUBLIC_KEY1);
}
Also used : Path(java.nio.file.Path) ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) Test(org.junit.jupiter.api.Test)

Example 5 with ArtifactSigner

use of tech.pegasys.web3signer.core.signing.ArtifactSigner 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)

Aggregations

ArtifactSigner (tech.pegasys.web3signer.core.signing.ArtifactSigner)20 Test (org.junit.jupiter.api.Test)18 BlsArtifactSigner (tech.pegasys.web3signer.core.signing.BlsArtifactSigner)16 Path (java.nio.file.Path)10 HashMap (java.util.HashMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)6 AzureSecretSigningMetadata (tech.pegasys.web3signer.core.multikey.metadata.AzureSecretSigningMetadata)3 FileKeyStoreMetadata (tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata)3 FileRawSigningMetadata (tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1