use of net.ripe.rpki.validator3.domain.ValidationRun in project rpki-validator-3 by RIPE-NCC.
the class RrdpService method applyDeltaPublish.
private void applyDeltaPublish(RpkiRepositoryValidationRun validationRun, String uri, DeltaPublish deltaPublish) {
if (deltaPublish.getHash().isPresent()) {
final byte[] sha256 = deltaPublish.getHash().get();
final Optional<RpkiObject> existing = rpkiObjectRepository.findBySha256(sha256);
if (existing.isPresent()) {
addRpkiObject(validationRun, uri, deltaPublish, sha256);
} else {
ValidationCheck validationCheck = new ValidationCheck(validationRun, uri, ValidationCheck.Status.ERROR, ErrorCodes.RRDP_REPLACE_NONEXISTENT_OBJECT, Hex.format(sha256));
validationRun.addCheck(validationCheck);
}
} else {
addRpkiObject(validationRun, uri, deltaPublish, null);
}
}
use of net.ripe.rpki.validator3.domain.ValidationRun in project rpki-validator-3 by RIPE-NCC.
the class RrdpService method storeSnapshot.
void storeSnapshot(final Snapshot snapshot, final RpkiRepositoryValidationRun validationRun) {
snapshot.asMap().forEach((objUri, value) -> {
byte[] content = value.content;
rpkiObjectRepository.findBySha256(Sha256.hash(content)).map(existing -> {
existing.addLocation(objUri);
return existing;
}).orElseGet(() -> {
final Either<ValidationResult, RpkiObject> maybeRpkiObject = createRpkiObject(objUri, content);
if (maybeRpkiObject.isLeft()) {
validationRun.addChecks(maybeRpkiObject.left().value());
return null;
} else {
RpkiObject object = maybeRpkiObject.right().value();
rpkiObjectRepository.add(object);
validationRun.addRpkiObject(object);
log.debug("added to database {}", object);
return object;
}
});
});
}
use of net.ripe.rpki.validator3.domain.ValidationRun in project rpki-validator-3 by RIPE-NCC.
the class RpkiRepositoryValidationService method validateRpkiRepository.
public void validateRpkiRepository(long rpkiRepositoryId) {
entityManager.setFlushMode(FlushModeType.COMMIT);
final RpkiRepository rpkiRepository = rpkiRepositories.get(rpkiRepositoryId);
log.info("Starting RPKI repository validation for " + rpkiRepository);
ValidationResult validationResult = ValidationResult.withLocation(rpkiRepository.getRrdpNotifyUri());
final RpkiRepositoryValidationRun validationRun = new RrdpRepositoryValidationRun(rpkiRepository);
validationRunRepository.add(validationRun);
final String uri = rpkiRepository.getRrdpNotifyUri();
if (isRrdpUri(uri)) {
rrdpService.storeRepository(rpkiRepository, validationRun);
if (validationRun.isFailed()) {
rpkiRepository.setFailed();
} else {
rpkiRepository.setDownloaded();
}
} else if (isRsyncUri(uri)) {
validationResult.error("rsync.repository.not.supported");
} else {
log.error("Unsupported type of the URI " + uri);
}
if (validationResult.hasFailures()) {
validationRun.setFailed();
} else {
validationRun.setSucceeded();
}
if (validationRun.isSucceeded() && validationRun.getAddedObjectCount() > 0) {
rpkiRepository.getTrustAnchors().forEach(validationRunRepository::runCertificateTreeValidation);
}
}
use of net.ripe.rpki.validator3.domain.ValidationRun in project rpki-validator-3 by RIPE-NCC.
the class RpkiRepositoryValidationService method validateRsyncRepositories.
@Scheduled(initialDelay = 10_000, fixedDelay = 10_000)
public void validateRsyncRepositories() {
entityManager.setFlushMode(FlushModeType.COMMIT);
Instant cutoffTime = Instant.now().minus(rsyncRepositoryDownloadInterval);
log.info("updating all rsync repositories that have not been downloaded since {}", cutoffTime);
Set<TrustAnchor> affectedTrustAnchors = new HashSet<>();
final RsyncRepositoryValidationRun validationRun = new RsyncRepositoryValidationRun();
validationRunRepository.add(validationRun);
Stream<RpkiRepository> repositories = rpkiRepositories.findRsyncRepositories();
Map<String, RpkiObject> objectsBySha256 = new HashMap<>();
Map<URI, RpkiRepository> fetchedLocations = new HashMap<>();
ValidationResult results = repositories.filter((repository) -> {
boolean needsUpdate = repository.isPending() || repository.getLastDownloadedAt() == null || repository.getLastDownloadedAt().isBefore(cutoffTime);
if (!needsUpdate) {
fetchedLocations.put(URI.create(repository.getRsyncRepositoryUri()), repository);
}
return needsUpdate;
}).map((repository) -> processRsyncRepository(affectedTrustAnchors, validationRun, fetchedLocations, objectsBySha256, repository)).collect(() -> ValidationResult.withLocation("placeholder"), ValidationResult::addAll, ValidationResult::addAll);
validationRun.completeWith(results);
affectedTrustAnchors.forEach(validationRunRepository::runCertificateTreeValidation);
}
use of net.ripe.rpki.validator3.domain.ValidationRun in project rpki-validator-3 by RIPE-NCC.
the class RpkiRepositoryValidationService method processRsyncRepository.
protected ValidationResult processRsyncRepository(Set<TrustAnchor> affectedTrustAnchors, RsyncRepositoryValidationRun validationRun, Map<URI, RpkiRepository> fetchedLocations, Map<String, RpkiObject> objectsBySha256, RpkiRepository repository) {
ValidationResult validationResult = ValidationResult.withLocation(URI.create(repository.getRsyncRepositoryUri()));
validationRun.addRpkiRepository(repository);
try {
File targetDirectory = RsyncUtils.localFileFromRsyncUri(rsyncLocalStorageDirectory, URI.create(repository.getRsyncRepositoryUri()));
RpkiRepository parentRepository = findDownloadedParentRepository(fetchedLocations, repository);
if (parentRepository == null) {
fetchRsyncRepository(repository, targetDirectory, validationResult);
if (validationResult.hasFailureForCurrentLocation()) {
return validationResult;
}
}
if (repository.getType() == RpkiRepository.Type.RSYNC && (parentRepository == null || parentRepository.getType() == RpkiRepository.Type.RSYNC_PREFETCH)) {
storeObjects(targetDirectory, validationRun, validationResult, objectsBySha256, repository);
}
} catch (IOException e) {
repository.setFailed();
validationResult.error(ErrorCodes.RSYNC_REPOSITORY_IO, e.toString(), ExceptionUtils.getStackTrace(e));
}
affectedTrustAnchors.addAll(repository.getTrustAnchors());
repository.setDownloaded();
fetchedLocations.put(URI.create(repository.getRsyncRepositoryUri()), repository);
return validationResult;
}
Aggregations