Search in sources :

Example 1 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement in project winery by eclipse.

the class AccountabilityManagerImplTest method verifyManifestArguments.

private static Stream<Arguments> verifyManifestArguments() {
    String validState = "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n";
    ModelProvenanceElement validElement = new ModelProvenanceElement();
    validElement.setFingerprint(validState);
    validElement.setAuthorAddress("0x11111");
    ModelProvenanceElement invalidElement = new ModelProvenanceElement();
    invalidElement.setFingerprint("Empty");
    invalidElement.setAuthorAddress("0x11111");
    ModelProvenanceElement unauthorizedElement = new ModelProvenanceElement();
    unauthorizedElement.setFingerprint("TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 97193968948686d6947d4d760d3fe724b9981980056b8902be92e91fbe9e3eed\n" + "\n" + "Name: myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: a99c9a8e954355e34f11282a6dec25cc5e0b3aec2fd25d33daf2ca06267b477e\n");
    unauthorizedElement.setAuthorAddress("0x11234111");
    AuthorizationElement authorizationElement = new AuthorizationElement();
    authorizationElement.setAuthorizerBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedIdentity("Gharreb");
    authorizationElement.setTransactionHash("0x3215F23");
    List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
    AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
    return Stream.of(Arguments.of(validElement, VERIFIED, authorizationInfo, "Expect a verified manifest"), Arguments.of(invalidElement, INVALID, authorizationInfo, "Expect an invalid manifest"), Arguments.of(null, NO_MANIFEST_FILE_IN_PROVENANCE_LAYER, authorizationInfo, "Expect no manifest in provenance"), Arguments.of(unauthorizedElement, UNAUTHORIZED, authorizationInfo, "Expect a unauthorized manifest"));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)

Example 2 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement in project winery by eclipse.

the class AccountabilityManagerImplTest method getHistoryOfSingleFileArguments.

private static Stream<Arguments> getHistoryOfSingleFileArguments() {
    String fileId = "folder/myFile.tosca";
    ModelProvenanceElement elementWithFileOccurrence_0 = new ModelProvenanceElement("0x1000000000000000000000000000000000000000", 0, "0x11111", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    ModelProvenanceElement elementWithFileOccurrence_1 = new ModelProvenanceElement("0x2000000000000000000000000000000000000000", 0, "0x3333", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: " + fileId + "\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    ModelProvenanceElement elementWithoutFileOccurrence_0 = new ModelProvenanceElement("0x3000000000000000000000000000000000000000", 0, "0x11111", // region string
    "TOSCA-Meta-Version: 1.0\n" + "CSAR-Version: 1.0\n" + "Created-By: Winery 3.0.0-SNAPSHOT\n" + "Entry-Definitions: Definitions/servicetemplates1__MyTinyToDo_Bare_Docker.tosca\n" + "\n" + "Name: Definitions/myTestFile.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544\n" + "\n" + "Name: Definitions/myTestFile1.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b9e69d43768c487b7a68b95faed3725444" + "\n" + "Name: Definitions/myTestFile2.tosca\n" + "Content-Type: application/vnd.oasis.tosca.definitions\n" + "SHA-256: 9e69d43768c487b7a68b95faed372544");
    AuthorizationElement authorizationElement = new AuthorizationElement();
    authorizationElement.setAuthorizerBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedBlockchainAddress("0x11111");
    authorizationElement.setAuthorizedIdentity("Gharreb");
    authorizationElement.setTransactionHash("0x3215F230003215F230003215F230003215F23000");
    List<AuthorizationElement> authList = Arrays.asList(authorizationElement);
    AuthorizationInfo authorizationInfo = new AuthorizationTree(authList);
    return Stream.of(Arguments.of(null, "someId", null, authorizationInfo, null, "Empty provenance elements list"), Arguments.of(Arrays.asList(elementWithFileOccurrence_0, elementWithoutFileOccurrence_0, elementWithFileOccurrence_1), fileId, Arrays.asList(new FileProvenanceElement(elementWithFileOccurrence_0), new FileProvenanceElement(elementWithFileOccurrence_1)), authorizationInfo, new boolean[] { true, false }, "Find two file occurrences"));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) AuthorizationTree(org.eclipse.winery.accountability.model.authorization.AuthorizationTree) AuthorizationElement(org.eclipse.winery.accountability.model.authorization.AuthorizationElement) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement)

Example 3 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement in project winery by eclipse.

the class AccountabilityManagerImplTest method verifyFileInManifest.

@ParameterizedTest(name = "{index} => ''{6}''")
@MethodSource("verifyFileInManifestArguments")
public void verifyFileInManifest(String fileId, String checksum, String manifestString, String expectedFileId, String expectedChecksum, ProvenanceVerification expectedVerification, String description) {
    ModelProvenanceElement historyElement = new ModelProvenanceElement();
    historyElement.setFingerprint(String.format(manifestString, fileId, checksum));
    assertEquals(expectedVerification, provenance.verifyFileInManifest(historyElement, expectedFileId, expectedChecksum));
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement 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 5 with ModelProvenanceElement

use of org.eclipse.winery.accountability.model.ModelProvenanceElement in project winery by eclipse.

the class ProvenanceSmartContractWrapper method getProvenance.

public CompletableFuture<List<ModelProvenanceElement>> getProvenance(final String identifier) {
    // eventName, indexed parameters, unindexed parameters
    final Event event = new Event("ResourceVersion", Arrays.asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Address>() {
    }, new TypeReference<Bytes>() {
    }));
    EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contract.getContractAddress()).addSingleTopic(EventEncoder.encode(event)).addOptionalTopics(Hash.sha3String(identifier)).addNullTopic();
    final CompletableFuture<List<ModelProvenanceElement>> result = new CompletableFuture<>();
    try {
        final int recordsCount = web3j.ethGetLogs(filter).send().getLogs().size();
        LOGGER.info(recordsCount + " provenance elements detected.");
        if (recordsCount > 0) {
            final List<ModelProvenanceElement> provenanceElements = new ArrayList<>();
            final Disposable subscription = ((Provenance) contract).resourceVersionEventFlowable(filter).subscribe(resourceVersionEventResponse -> {
                try {
                    final ModelProvenanceElement currentElement = generateProvenanceElement(resourceVersionEventResponse);
                    provenanceElements.add(currentElement);
                    if (provenanceElements.size() == recordsCount) {
                        result.complete(provenanceElements);
                    }
                } catch (EthereumException e) {
                    result.completeExceptionally(e);
                }
            });
            // unsubscribe the observable when the CompletableFuture completes (this frees threads)
            result.whenComplete((r, e) -> subscription.dispose());
        } else {
            // empty result
            result.complete(new ArrayList<>());
        }
    } catch (IOException e) {
        final String msg = "Failed detecting the number of provenance elements for the collaboration resource. Reason: " + e.getMessage();
        LOGGER.error(msg);
        result.completeExceptionally(new EthereumException(msg, e));
    }
    return result;
}
Also used : Disposable(io.reactivex.disposables.Disposable) EthFilter(org.web3j.protocol.core.methods.request.EthFilter) ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Utf8String(org.web3j.abi.datatypes.Utf8String) CompletableFuture(java.util.concurrent.CompletableFuture) Event(org.web3j.abi.datatypes.Event) EthereumException(org.eclipse.winery.accountability.exceptions.EthereumException) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(org.web3j.abi.TypeReference)

Aggregations

ModelProvenanceElement (org.eclipse.winery.accountability.model.ModelProvenanceElement)12 File (java.io.File)4 HashMap (java.util.HashMap)4 ProvenanceVerification (org.eclipse.winery.accountability.model.ProvenanceVerification)4 AuthorizationInfo (org.eclipse.winery.accountability.model.authorization.AuthorizationInfo)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 FileProvenanceElement (org.eclipse.winery.accountability.model.FileProvenanceElement)3 AuthorizationElement (org.eclipse.winery.accountability.model.authorization.AuthorizationElement)3 AuthorizationTree (org.eclipse.winery.accountability.model.authorization.AuthorizationTree)3 List (java.util.List)2 EthereumException (org.eclipse.winery.accountability.exceptions.EthereumException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Disposable (io.reactivex.disposables.Disposable)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1