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);
}
}
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);
}
}
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;
}
});
});
}
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);
}
}
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);
}
}
Aggregations