use of net.ripe.rpki.commons.validation.ValidationResult 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.commons.validation.ValidationResult 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.commons.validation.ValidationResult 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;
}
use of net.ripe.rpki.commons.validation.ValidationResult in project rpki-validator-3 by RIPE-NCC.
the class RrdpService method createRpkiObject.
private Either<ValidationResult, RpkiObject> createRpkiObject(final String uri, final byte[] content) {
ValidationResult validationResult = ValidationResult.withLocation(uri);
CertificateRepositoryObject repositoryObject = CertificateRepositoryObjectFactory.createCertificateRepositoryObject(content, validationResult);
if (validationResult.hasFailures()) {
return Either.left(validationResult);
} else {
return Either.right(new RpkiObject(uri, repositoryObject));
}
}
use of net.ripe.rpki.commons.validation.ValidationResult in project rpki-validator-3 by RIPE-NCC.
the class RrdpService method addRpkiObject.
private void addRpkiObject(RpkiRepositoryValidationRun validationRun, String uri, DeltaPublish deltaPublish, final byte[] existingHash) {
final Either<ValidationResult, RpkiObject> maybeRpkiObject = createRpkiObject(uri, deltaPublish.getContent());
if (maybeRpkiObject.isLeft()) {
validationRun.addChecks(maybeRpkiObject.left().value());
} else {
RpkiObject object = maybeRpkiObject.right().value();
if (existingHash == null || !Arrays.equals(object.getSha256(), existingHash)) {
validationRun.addRpkiObject(object);
rpkiObjectRepository.add(object);
} else {
log.debug("The object added is the same {}", object);
}
log.debug("Added to database {}", object);
}
}
Aggregations