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."); }
protected Map<String, ProvenanceVerification> validateBlockchainInput(List<ModelProvenanceElement> historyElements, String manifestId, Map<String, File> files, AuthorizationInfo authorizationInfo) throws IOException, NoSuchAlgorithmException { LOGGER.info("Start validating..."); Map<String, ProvenanceVerification> verificationMap = new HashMap<>(); ModelProvenanceElement validHistoryElement = verifyManifest(historyElements, manifestId, files, verificationMap, authorizationInfo); if (Objects.nonNull(validHistoryElement) && verificationMap.get(manifestId) == VERIFIED) { verifyFiles(validHistoryElement, files, verificationMap); } LOGGER.info("Completed validation."); return verificationMap; }
@Override public CompletableFuture<Map<String, ProvenanceVerification>> verify(String processIdentifier, String manifestId, Map<String, File> files) { Objects.requireNonNull(processIdentifier); Objects.requireNonNull(manifestId); Objects.requireNonNull(files); LOGGER.info("Verifying process id: " + processIdentifier); CompletableFuture<AuthorizationInfo> authorizationTree = this.blockchain.getAuthorizationTree(processIdentifier); return this.blockchain .getProvenance(processIdentifier) .thenCombine(authorizationTree, (provenanceElements, authorizationInfo) -> { // TODO: extract into one method and write test cases Map<String, ProvenanceVerification> map = null; try { if (authorizationInfo == null) { LOGGER.info(NO_AUTHORIZATION_DATA); map = new HashMap<>(); map.put(manifestId, NO_AUTHORIZATION_DATA_AVAILABLE); } else { map = this.validateBlockchainInput(provenanceElements, manifestId, files, authorizationInfo); } } catch (NoSuchAlgorithmException e) { LOGGER.error("Could not find the hashing algorithm.", e); } catch (IOException e) { LOGGER.error("Could not transform file to byte array.", e); } catch (SerializationException e) { LOGGER.error("Could not deserialize stored manifest file.", e); } return map; }); }
private List<ModelProvenanceElement> enhanceHistoryElements(List<ModelProvenanceElement> historyElements, AuthorizationInfo authorizationInfo) { historyElements.forEach(element -> { element.setAuthorizedFlag(authorizationInfo); element.setAuthorName( authorizationInfo != null ? authorizationInfo.getRealWorldIdentity( element.getAuthorAddress()).orElseGet(String::new) : "" ); this.fillFilesOfModel(element); }); return historyElements; }
@Override public CompletableFuture<List<FileProvenanceElement>> getHistory(String processIdentifier, String fileId) { CompletableFuture<AuthorizationInfo> authorizationTree = this.blockchain.getAuthorizationTree(processIdentifier); return this.blockchain .getProvenance(processIdentifier) .thenCombine(authorizationTree, (provenanceElements, authorizationInfo) -> { List<FileProvenanceElement> result; if (authorizationInfo != null) { result = getHistoryOfSingleFile(provenanceElements, fileId, authorizationInfo); } else { LOGGER.info(NO_AUTHORIZATION_DATA); FileProvenanceElement historyElement = new FileProvenanceElement("", 0, NO_AUTHORIZATION_DATA); historyElement.setAuthorized(false); historyElement.setFileName(fileId); result = Collections.singletonList(historyElement); } return result; }); }
public static AccountabilityManager getAccountabilityManager(Properties accountabilityConfiguration) throws AccountabilityException { boolean requiresRecreation = false; // if any of the relevant configurations is changed, we need a new instance! if (activeProperties != null) { requiresRecreation = checkIfChanged(accountabilityConfiguration); } if (Objects.isNull(accountabilityManager) || requiresRecreation) { BlockchainFactory.reset(); ImmutableStorageProviderFactory.reset(); // if there is an older accountability manager, we should shut it down if (!Objects.isNull(accountabilityManager)) { accountabilityManager.close(); } try { BlockchainAccess blockchain = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, accountabilityConfiguration); ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, accountabilityConfiguration); accountabilityManager = new AccountabilityManagerImpl(blockchain, storageProvider); copyProperties(accountabilityConfiguration); } catch (BlockchainException e) { String msg = "Could not instantiate accountability layer: " + e.getMessage(); LOGGER.error(msg, e); throw new AccountabilityException(msg, e); } } return accountabilityManager; }