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"));
}
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));
}
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"));
}
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;
}
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"));
}
Aggregations