Search in sources :

Example 11 with FileStreamSignature

use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testInvalidMetadataSignature.

@Test
void testInvalidMetadataSignature() throws GeneralSecurityException {
    byte[] fileHash = TestUtils.generateRandomByteArray(48);
    byte[] metadataHash = TestUtils.generateRandomByteArray(48);
    FileStreamSignature fileStreamSignature = buildFileStreamSignature(fileHash, signHash(fileHash), metadataHash, corruptSignature(signHash(fileHash)));
    List<FileStreamSignature> fileStreamSignatures = Arrays.asList(buildBareBonesFileStreamSignature());
    Exception e = assertThrows(SignatureVerificationException.class, () -> nodeSignatureVerifier.verify(fileStreamSignatures));
    assertTrue(e.getMessage().contains("Signature verification failed for file"));
}
Also used : FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) GeneralSecurityException(java.security.GeneralSecurityException) SignatureVerificationException(com.hedera.mirror.importer.exception.SignatureVerificationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.jupiter.api.Test)

Example 12 with FileStreamSignature

use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testVerifiedWithFullConsensusRequired.

@Test
void testVerifiedWithFullConsensusRequired() throws GeneralSecurityException {
    Map<String, PublicKey> nodeAccountIDPubKeyMap = new HashMap();
    nodeAccountIDPubKeyMap.put("0.0.3", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.4", publicKey);
    nodeAccountIDPubKeyMap.put("0.0.5", publicKey);
    when(currentAddressBook.getNodeAccountIDPubKeyMap()).thenReturn(nodeAccountIDPubKeyMap);
    when(commonDownloaderProperties.getConsensusRatio()).thenReturn(1f);
    byte[] fileHash = TestUtils.generateRandomByteArray(48);
    byte[] fileHashSignature = signHash(fileHash);
    FileStreamSignature fileStreamSignatureNode3 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode3.setNodeAccountId(new EntityId(0L, 0L, 3L, EntityType.ACCOUNT));
    FileStreamSignature fileStreamSignatureNode4 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode4.setNodeAccountId(new EntityId(0L, 0L, 4L, EntityType.ACCOUNT));
    FileStreamSignature fileStreamSignatureNode5 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
    fileStreamSignatureNode5.setNodeAccountId(new EntityId(0L, 0L, 5L, EntityType.ACCOUNT));
    nodeSignatureVerifier.verify(Arrays.asList(fileStreamSignatureNode3, fileStreamSignatureNode4, fileStreamSignatureNode5));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) Test(org.junit.jupiter.api.Test)

Example 13 with FileStreamSignature

use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testInvalidFileSignature.

@Test
void testInvalidFileSignature() throws GeneralSecurityException {
    byte[] fileHash = TestUtils.generateRandomByteArray(48);
    FileStreamSignature fileStreamSignature = buildFileStreamSignature(fileHash, corruptSignature(signHash(fileHash)), null, null);
    List<FileStreamSignature> fileStreamSignatures = Arrays.asList(buildBareBonesFileStreamSignature());
    Exception e = assertThrows(SignatureVerificationException.class, () -> nodeSignatureVerifier.verify(fileStreamSignatures));
    assertTrue(e.getMessage().contains("Signature verification failed for file"));
}
Also used : FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) GeneralSecurityException(java.security.GeneralSecurityException) SignatureVerificationException(com.hedera.mirror.importer.exception.SignatureVerificationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.jupiter.api.Test)

Example 14 with FileStreamSignature

use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method buildFileStreamSignature.

private FileStreamSignature buildFileStreamSignature(byte[] fileHash, byte[] fileHashSignature, byte[] metadataHash, byte[] metadataSignature) {
    FileStreamSignature fileStreamSignature = buildBareBonesFileStreamSignature();
    fileStreamSignature.setFileHash(fileHash);
    fileStreamSignature.setMetadataHash(metadataHash);
    fileStreamSignature.setFileHashSignature(fileHashSignature);
    fileStreamSignature.setMetadataHashSignature(metadataSignature);
    return fileStreamSignature;
}
Also used : FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature)

Example 15 with FileStreamSignature

use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.

the class NodeSignatureVerifierTest method testSignedWithWrongAlgorithm.

@Test
void testSignedWithWrongAlgorithm() throws GeneralSecurityException {
    signer = Signature.getInstance("SHA1withRSA", "SunRsaSign");
    signer.initSign(privateKey);
    byte[] entireFileHash = TestUtils.generateRandomByteArray(48);
    FileStreamSignature fileStreamSignature = buildFileStreamSignature(entireFileHash, signHash(entireFileHash), null, null);
    List<FileStreamSignature> fileStreamSignatures = Arrays.asList(fileStreamSignature);
    Exception e = assertThrows(SignatureVerificationException.class, () -> nodeSignatureVerifier.verify(fileStreamSignatures));
    assertTrue(e.getMessage().contains("Signature verification failed for file"));
}
Also used : FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature) GeneralSecurityException(java.security.GeneralSecurityException) SignatureVerificationException(com.hedera.mirror.importer.exception.SignatureVerificationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.jupiter.api.Test)

Aggregations

FileStreamSignature (com.hedera.mirror.importer.domain.FileStreamSignature)24 Test (org.junit.jupiter.api.Test)14 SignatureVerificationException (com.hedera.mirror.importer.exception.SignatureVerificationException)12 GeneralSecurityException (java.security.GeneralSecurityException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 PublicKey (java.security.PublicKey)7 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 InvalidStreamFileException (com.hedera.mirror.importer.exception.InvalidStreamFileException)4 HashMap (java.util.HashMap)4 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)3 StreamFilename (com.hedera.mirror.importer.domain.StreamFilename)3 Stopwatch (com.google.common.base.Stopwatch)2 Multimap (com.google.common.collect.Multimap)2 StreamType (com.hedera.mirror.common.domain.StreamType)2 AddressBookService (com.hedera.mirror.importer.addressbook.AddressBookService)2 HashMismatchException (com.hedera.mirror.importer.exception.HashMismatchException)2 SignatureFileParsingException (com.hedera.mirror.importer.exception.SignatureFileParsingException)2 ValidatedDataInputStream (com.hedera.mirror.importer.reader.ValidatedDataInputStream)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2