protected ModelProvenanceElement verifyManifest(List<ModelProvenanceElement> historyElements, String manifestId, Map<String, File> files,
Map<String, ProvenanceVerification> verificationMap, AuthorizationInfo authorizationInfo) throws NoSuchAlgorithmException, IOException {
LOGGER.info("Start validating manifest file...");
ModelProvenanceElement validHistoryElement = null;
ProvenanceVerification manifestVerification = INVALID;
if (Objects.nonNull(historyElements) && historyElements.size() > 0) {
File manifestFile = files.remove(manifestId);
String checksum = HashingUtil.getChecksum(manifestFile, TOSCAMetaFileAttributes.HASH);
for (ModelProvenanceElement element : historyElements) {
String retrievedChecksum = HashingUtil.getChecksum(IOUtils.toInputStream(element.getFingerprint(), StandardCharsets.UTF_8), TOSCAMetaFileAttributes.HASH);
if (retrievedChecksum.compareTo(checksum) == 0) {
validHistoryElement = element;
manifestVerification = authorizationInfo.isAuthorized(validHistoryElement.getAuthorAddress())
? VERIFIED
: UNAUTHORIZED;
break;
}
}
} else {
manifestVerification = NO_MANIFEST_FILE_IN_PROVENANCE_LAYER;
}
LOGGER.info("Manifest verification resulted in " + manifestVerification);
verificationMap.put(manifestId, manifestVerification);
return validHistoryElement;
}