use of com.hedera.mirror.importer.exception.SignatureFileParsingException in project hedera-mirror-node by hashgraph.
the class CompositeSignatureFileReaderTest method testInvalidFileVersion.
@Test
void testInvalidFileVersion() {
byte[] invalidVersionNumber = { 12 };
StreamFileData invalidFileData = StreamFileData.from(SIGNATURE_FILENAME, invalidVersionNumber);
SignatureFileParsingException exception = assertThrows(SignatureFileParsingException.class, () -> {
compositeBalanceFileReader.read(invalidFileData);
});
assertTrue(exception.getMessage().contains("Unsupported signature file version: " + invalidVersionNumber[0]));
}
use of com.hedera.mirror.importer.exception.SignatureFileParsingException in project hedera-mirror-node by hashgraph.
the class CompositeSignatureFileReader method read.
@Override
public FileStreamSignature read(StreamFileData signatureFileData) {
try (DataInputStream dataInputStream = new DataInputStream(signatureFileData.getInputStream())) {
byte version = dataInputStream.readByte();
SignatureFileReader fileReader;
if (version == SignatureFileReaderV5.SIGNATURE_FILE_FORMAT_VERSION) {
fileReader = signatureFileReaderV5;
} else if (version <= SignatureFileReaderV2.SIGNATURE_TYPE_FILE_HASH) {
// Begins with a byte of value 4
fileReader = signatureFileReaderV2;
} else {
throw new SignatureFileParsingException("Unsupported signature file version: " + version);
}
return fileReader.read(signatureFileData);
} catch (IOException ex) {
throw new SignatureFileParsingException("Error reading signature file", ex);
}
}
use of com.hedera.mirror.importer.exception.SignatureFileParsingException 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.exception.SignatureFileParsingException 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);
}
}
use of com.hedera.mirror.importer.exception.SignatureFileParsingException in project hedera-mirror-node by hashgraph.
the class CompositeSignatureFileReaderTest method testBlankFile.
@Test
void testBlankFile() {
StreamFileData blankFileData = StreamFileData.from(SIGNATURE_FILENAME, new byte[0]);
SignatureFileParsingException exception = assertThrows(SignatureFileParsingException.class, () -> {
compositeBalanceFileReader.read(blankFileData);
});
assertAll(() -> assertTrue(exception.getMessage().contains("Error reading signature file")), () -> assertTrue(exception.getCause() instanceof IOException));
}
Aggregations