Search in sources :

Example 6 with ValidationRun

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);
    }
}
Also used : RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck)

Example 7 with ValidationRun

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;
            }
        });
    });
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) Arrays(java.util.Arrays) CertificateRepositoryObject(net.ripe.rpki.commons.crypto.CertificateRepositoryObject) Transactional(javax.transaction.Transactional) RpkiRepositoryValidationRun(net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun) Hex(net.ripe.rpki.validator3.util.Hex) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) CertificateRepositoryObjectFactory(net.ripe.rpki.commons.crypto.util.CertificateRepositoryObjectFactory) ErrorCodes(net.ripe.rpki.validator3.domain.ErrorCodes) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) Service(org.springframework.stereotype.Service) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Sha256(net.ripe.rpki.validator3.util.Sha256) Either(fj.data.Either) Comparator(java.util.Comparator) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult)

Example 8 with ValidationRun

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);
    }
}
Also used : RpkiRepositoryValidationRun(net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult)

Example 9 with ValidationRun

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);
}
Also used : RsyncRepositoryValidationRun(net.ripe.rpki.validator3.domain.RsyncRepositoryValidationRun) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) ValidationRuns(net.ripe.rpki.validator3.domain.ValidationRuns) CertificateRepositoryObject(net.ripe.rpki.commons.crypto.CertificateRepositoryObject) RpkiRepositoryValidationRun(net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun) RsyncRepositoryValidationRun(net.ripe.rpki.validator3.domain.RsyncRepositoryValidationRun) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayUtils(org.apache.commons.lang3.ArrayUtils) FlushModeType(javax.persistence.FlushModeType) HashMap(java.util.HashMap) Scheduled(org.springframework.scheduling.annotation.Scheduled) CertificateRepositoryObjectFactory(net.ripe.rpki.commons.crypto.util.CertificateRepositoryObjectFactory) ErrorCodes(net.ripe.rpki.validator3.domain.ErrorCodes) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) RpkiRepositories(net.ripe.rpki.validator3.domain.RpkiRepositories) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) Duration(java.time.Duration) Map(java.util.Map) Sha256(net.ripe.rpki.validator3.util.Sha256) URI(java.net.URI) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) Rsync(net.ripe.rpki.commons.rsync.Rsync) Transactional(javax.transaction.Transactional) Files(java.nio.file.Files) RrdpService(net.ripe.rpki.validator3.rrdp.RrdpService) Hex(net.ripe.rpki.validator3.util.Hex) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) Set(java.util.Set) IOException(java.io.IOException) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) EntityManager(javax.persistence.EntityManager) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Instant(java.time.Instant) File(java.io.File) ValidationLocation(net.ripe.rpki.commons.validation.ValidationLocation) FileVisitResult(java.nio.file.FileVisitResult) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) RsyncUtils(net.ripe.rpki.validator3.util.RsyncUtils) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) HashMap(java.util.HashMap) Instant(java.time.Instant) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) URI(java.net.URI) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) HashSet(java.util.HashSet) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 10 with ValidationRun

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;
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) IOException(java.io.IOException) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult) File(java.io.File)

Aggregations

TrustAnchor (net.ripe.rpki.validator3.domain.TrustAnchor)16 RpkiObject (net.ripe.rpki.validator3.domain.RpkiObject)15 RpkiRepository (net.ripe.rpki.validator3.domain.RpkiRepository)15 ValidationCheck (net.ripe.rpki.validator3.domain.ValidationCheck)14 IntegrationTest (net.ripe.rpki.validator3.IntegrationTest)13 Test (org.junit.Test)13 RpkiObjects (net.ripe.rpki.validator3.domain.RpkiObjects)12 RrdpRepositoryValidationRun (net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun)11 TestObjects (net.ripe.rpki.validator3.TestObjects)9 ValidationResult (net.ripe.rpki.commons.validation.ValidationResult)7 Transactional (javax.transaction.Transactional)6 ErrorCodes (net.ripe.rpki.validator3.domain.ErrorCodes)5 TrustAnchorValidationRun (net.ripe.rpki.validator3.domain.TrustAnchorValidationRun)5 Hex (net.ripe.rpki.validator3.util.Hex)5 Sha256 (net.ripe.rpki.validator3.util.Sha256)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 BigInteger (java.math.BigInteger)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 RpkiRepositoryValidationRun (net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun)4