use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.
the class NodeSignatureVerifierTest method testV2FileStreamSignature.
@Test
void testV2FileStreamSignature() throws GeneralSecurityException {
byte[] fileHash = TestUtils.generateRandomByteArray(48);
FileStreamSignature fileStreamSignature = buildFileStreamSignature(fileHash, signHash(fileHash), null, null);
nodeSignatureVerifier.verify(Arrays.asList(fileStreamSignature));
}
use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.
the class NodeSignatureVerifierTest method testNoConsensusRequiredWithVerifiedSignatureFiles.
@Test
void testNoConsensusRequiredWithVerifiedSignatureFiles() 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);
nodeAccountIDPubKeyMap.put("0.0.6", publicKey);
nodeAccountIDPubKeyMap.put("0.0.7", publicKey);
nodeAccountIDPubKeyMap.put("0.0.8", publicKey);
nodeAccountIDPubKeyMap.put("0.0.9", publicKey);
nodeAccountIDPubKeyMap.put("0.0.10", publicKey);
when(currentAddressBook.getNodeAccountIDPubKeyMap()).thenReturn(nodeAccountIDPubKeyMap);
when(commonDownloaderProperties.getConsensusRatio()).thenReturn(0f);
byte[] fileHash = TestUtils.generateRandomByteArray(48);
byte[] fileHashSignature = signHash(fileHash);
FileStreamSignature fileStreamSignatureNode = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
// only 1 node node necessary
nodeSignatureVerifier.verify(List.of(fileStreamSignatureNode));
}
use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.
the class NodeSignatureVerifierTest method testVerifiedWithOneThirdConsensusWithMissingSignatures.
@Test
void testVerifiedWithOneThirdConsensusWithMissingSignatures() 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);
byte[] fileHash = TestUtils.generateRandomByteArray(48);
byte[] fileHashSignature = signHash(fileHash);
FileStreamSignature fileStreamSignatureNode3 = buildFileStreamSignature(fileHash, fileHashSignature, null, null);
// Node 4 and 5 will not verify due to missing signature, but 1/3 verified will confirm consensus reached
FileStreamSignature fileStreamSignatureNode4 = buildFileStreamSignature(fileHash, null, null, null);
fileStreamSignatureNode4.setNodeAccountId(new EntityId(0L, 0L, 4L, EntityType.ACCOUNT));
FileStreamSignature fileStreamSignatureNode5 = buildFileStreamSignature(fileHash, null, 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 SignatureFileReaderV2 method read.
@Override
public FileStreamSignature read(StreamFileData signatureFileData) {
String filename = signatureFileData.getFilename();
try (ValidatedDataInputStream vdis = new ValidatedDataInputStream(signatureFileData.getInputStream(), filename)) {
vdis.readByte(SIGNATURE_TYPE_FILE_HASH, "hash delimiter");
byte[] fileHash = vdis.readNBytes(DigestAlgorithm.SHA384.getSize(), "hash");
vdis.readByte(SIGNATURE_TYPE_SIGNATURE, "signature delimiter");
byte[] signature = vdis.readLengthAndBytes(1, SignatureType.SHA_384_WITH_RSA.getMaxLength(), false, "signature");
if (vdis.available() != 0) {
throw new SignatureFileParsingException("Extra data discovered in signature file " + filename);
}
FileStreamSignature fileStreamSignature = new FileStreamSignature();
fileStreamSignature.setBytes(signatureFileData.getBytes());
fileStreamSignature.setFileHash(fileHash);
fileStreamSignature.setFileHashSignature(signature);
fileStreamSignature.setFilename(filename);
fileStreamSignature.setSignatureType(SignatureType.SHA_384_WITH_RSA);
return fileStreamSignature;
} catch (InvalidStreamFileException | IOException e) {
throw new SignatureFileParsingException(e);
}
}
use of com.hedera.mirror.importer.domain.FileStreamSignature in project hedera-mirror-node by hashgraph.
the class SignatureFileReaderV5 method read.
@Override
public FileStreamSignature read(StreamFileData signatureFileData) {
String filename = signatureFileData.getFilename();
try (ValidatedDataInputStream vdis = new ValidatedDataInputStream(signatureFileData.getInputStream(), filename)) {
vdis.readByte(SIGNATURE_FILE_FORMAT_VERSION, "fileVersion");
// Read the objectStreamSignatureVersion, which is not used
vdis.readInt();
HashObject fileHashObject = new HashObject(vdis, "entireFile", SHA384);
SignatureObject fileHashSignatureObject = new SignatureObject(vdis, "entireFile");
HashObject metadataHashObject = new HashObject(vdis, "metadata", SHA384);
SignatureObject metadataHashSignatureObject = new SignatureObject(vdis, "metadata");
if (vdis.available() != 0) {
throw new SignatureFileParsingException("Extra data discovered in signature file " + filename);
}
FileStreamSignature fileStreamSignature = new FileStreamSignature();
fileStreamSignature.setBytes(signatureFileData.getBytes());
fileStreamSignature.setFileHash(fileHashObject.getHash());
fileStreamSignature.setFileHashSignature(fileHashSignatureObject.getSignature());
fileStreamSignature.setFilename(filename);
fileStreamSignature.setMetadataHash(metadataHashObject.getHash());
fileStreamSignature.setMetadataHashSignature(metadataHashSignatureObject.getSignature());
fileStreamSignature.setSignatureType(fileHashSignatureObject.getSignatureType());
return fileStreamSignature;
} catch (InvalidStreamFileException | IOException e) {
throw new SignatureFileParsingException(e);
}
}
Aggregations