use of org.eclipse.winery.accountability.model.ProvenanceVerification in project winery by eclipse.
the class AccountabilityManagerImpl method verifyFiles.
protected void verifyFiles(ModelProvenanceElement validHistoryElement, Map<String, File> files, Map<String, ProvenanceVerification> verificationMap) throws SerializationException, IOException, NoSuchAlgorithmException {
LOGGER.info("Start validating files...");
for (Map.Entry<String, File> entry : files.entrySet()) {
String fileId = entry.getKey();
LOGGER.info("Validating \"" + fileId + "\"");
String checksum = HashingUtil.getChecksum(entry.getValue(), TOSCAMetaFileAttributes.HASH);
ProvenanceVerification verified = verifyFileInManifest(validHistoryElement, fileId, checksum);
verificationMap.put(entry.getKey(), verified);
LOGGER.info("\"" + entry.getKey() + "\" " + verified);
}
LOGGER.info("Completed files validation.");
}
use of org.eclipse.winery.accountability.model.ProvenanceVerification in project winery by eclipse.
the class AccountabilityManagerImpl method verifyManifest.
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;
}
use of org.eclipse.winery.accountability.model.ProvenanceVerification in project winery by eclipse.
the class CsarImporterValidationTest method testImportAndValidation.
@Test
public void testImportAndValidation() throws Exception {
try (InputStream input = new FileInputStream("src/test/resources/csar/ServiceTemplateWithAllReqCapVariants.csar")) {
CsarImportOptions options = new CsarImportOptions();
options.setOverwrite(true);
options.setAsyncWPDParsing(false);
options.setValidate(true);
ImportMetaInformation importMetaInformation = csarImporter.readCSAR(input, options);
assertEquals(ProvenanceVerification.VERIFIED, importMetaInformation.verificationMap.remove("TOSCA-Metadata/TOSCA.meta"));
for (Map.Entry<String, ProvenanceVerification> entry : importMetaInformation.verificationMap.entrySet()) {
assertEquals(ProvenanceVerification.VERIFIED, entry.getValue());
}
}
}
use of org.eclipse.winery.accountability.model.ProvenanceVerification in project winery by eclipse.
the class CsarImporterValidationTest method testImportAndInvalidValidation.
@Test
public void testImportAndInvalidValidation() throws Exception {
try (InputStream inputStream = new FileInputStream("src/test/resources/csar/ServiceTemplateWithAllReqCapVariants-Invalid.csar")) {
CsarImportOptions options = new CsarImportOptions();
options.setOverwrite(true);
options.setAsyncWPDParsing(false);
options.setValidate(true);
ImportMetaInformation importMetaInformation = csarImporter.readCSAR(inputStream, options);
ProvenanceVerification invalidDefinition = importMetaInformation.verificationMap.remove("Definitions/servicetemplates__ServiceTemplateWithAllReqCapVariants.tosca");
assertEquals(ProvenanceVerification.INVALID, invalidDefinition);
for (Map.Entry<String, ProvenanceVerification> entry : importMetaInformation.verificationMap.entrySet()) {
assertEquals(ProvenanceVerification.VERIFIED, entry.getValue());
}
}
}
use of org.eclipse.winery.accountability.model.ProvenanceVerification in project winery by eclipse.
the class CsarImporterValidationTest method testImportOfCsarWithoutAuthorship.
@Test
public void testImportOfCsarWithoutAuthorship() throws Exception {
try (InputStream inputStream = new FileInputStream("src/test/resources/csar/ProvenanceCsarWithoutAuthorizedAuthors_w1-wip1.csar")) {
CsarImportOptions options = new CsarImportOptions();
options.setOverwrite(true);
options.setAsyncWPDParsing(false);
options.setValidate(true);
ImportMetaInformation importMetaInformation = csarImporter.readCSAR(inputStream, options);
ProvenanceVerification verification = importMetaInformation.verificationMap.get("TOSCA-Metadata/TOSCA.meta");
assertEquals(ProvenanceVerification.NO_AUTHORIZATION_DATA_AVAILABLE, verification);
}
}
Aggregations