Search in sources :

Example 1 with ProvenanceVerification

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.");
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) TOSCAMetaFile(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile)

Example 2 with ProvenanceVerification

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;
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) File(java.io.File) TOSCAMetaFile(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile)

Example 3 with ProvenanceVerification

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());
        }
    }
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(java.util.Map) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test)

Example 4 with ProvenanceVerification

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());
        }
    }
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(java.util.Map) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test)

Example 5 with ProvenanceVerification

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);
    }
}
Also used : ProvenanceVerification(org.eclipse.winery.accountability.model.ProvenanceVerification) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ProvenanceVerification (org.eclipse.winery.accountability.model.ProvenanceVerification)9 HashMap (java.util.HashMap)5 File (java.io.File)4 Map (java.util.Map)4 ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 Test (org.junit.jupiter.api.Test)3 TOSCAMetaFile (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ExecutionException (java.util.concurrent.ExecutionException)1