Search in sources :

Example 1 with RpkiRepositoryValidationRun

use of net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun in project rpki-validator-3 by RIPE-NCC.

the class RrdpService method applyDeltaWithdraw.

private void applyDeltaWithdraw(RpkiRepositoryValidationRun validationRun, String uri, DeltaWithdraw deltaWithdraw) {
    final Optional<RpkiObject> maybeObject = rpkiObjectRepository.findBySha256(deltaWithdraw.getHash());
    if (maybeObject.isPresent()) {
        maybeObject.get().removeLocation(uri);
    } else {
        ValidationCheck validationCheck = new ValidationCheck(validationRun, uri, ValidationCheck.Status.ERROR, ErrorCodes.RRDP_WITHDRAW_NONEXISTENT_OBJECT, Hex.format(deltaWithdraw.getHash()));
        validationRun.addCheck(validationCheck);
    }
}
Also used : RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck)

Example 2 with RpkiRepositoryValidationRun

use of net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun 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 3 with RpkiRepositoryValidationRun

use of net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun 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 4 with RpkiRepositoryValidationRun

use of net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun 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 5 with RpkiRepositoryValidationRun

use of net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun in project rpki-validator-3 by RIPE-NCC.

the class RrdpService method doStoreRepository.

private void doStoreRepository(RpkiRepository rpkiRepository, RpkiRepositoryValidationRun validationRun) {
    final Notification notification = rrdpClient.readStream(rpkiRepository.getRrdpNotifyUri(), rrdpParser::notification);
    log.info("The local serial is '{}' and the latest serial is {}", rpkiRepository.getRrdpSerial(), notification.serial);
    if (notification.sessionId.equals(rpkiRepository.getRrdpSessionId())) {
        if (rpkiRepository.getRrdpSerial().compareTo(notification.serial) <= 0) {
            try {
                final List<Delta> deltas = notification.deltas.parallelStream().filter(d -> d.getSerial().compareTo(rpkiRepository.getRrdpSerial()) > 0).sorted(Comparator.comparing(DeltaInfo::getSerial)).map(di -> readDelta(notification, di)).collect(Collectors.toList());
                verifyDeltaSerials(deltas, notification, rpkiRepository);
                deltas.forEach(d -> {
                    storeDelta(d, validationRun);
                    rpkiRepository.setRrdpSerial(rpkiRepository.getRrdpSerial().add(BigInteger.ONE));
                });
            } catch (RrdpException e) {
                log.info("Processing deltas failed {}, falling back to snapshot processing.", e.getMessage());
                ValidationCheck validationCheck = new ValidationCheck(validationRun, rpkiRepository.getRrdpNotifyUri(), ValidationCheck.Status.WARNING, ErrorCodes.RRDP_FETCH_DELTAS, e.getMessage());
                validationRun.addCheck(validationCheck);
                readSnapshot(rpkiRepository, validationRun, notification);
            }
        }
    } else {
        log.info("Repository has session id '{}' but the downloaded version has session id '{}', fetching the snapshot", rpkiRepository.getRrdpSessionId(), notification.sessionId);
        readSnapshot(rpkiRepository, validationRun, notification);
    }
}
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) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck)

Aggregations

RpkiObject (net.ripe.rpki.validator3.domain.RpkiObject)5 ValidationResult (net.ripe.rpki.commons.validation.ValidationResult)4 ValidationCheck (net.ripe.rpki.validator3.domain.ValidationCheck)4 RpkiRepository (net.ripe.rpki.validator3.domain.RpkiRepository)3 RpkiRepositoryValidationRun (net.ripe.rpki.validator3.domain.RpkiRepositoryValidationRun)3 Either (fj.data.Either)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BigInteger (java.math.BigInteger)2 Arrays (java.util.Arrays)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Transactional (javax.transaction.Transactional)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CertificateRepositoryObject (net.ripe.rpki.commons.crypto.CertificateRepositoryObject)2 CertificateRepositoryObjectFactory (net.ripe.rpki.commons.crypto.util.CertificateRepositoryObjectFactory)2 ErrorCodes (net.ripe.rpki.validator3.domain.ErrorCodes)2 RpkiObjects (net.ripe.rpki.validator3.domain.RpkiObjects)2 Hex (net.ripe.rpki.validator3.util.Hex)2