Search in sources :

Example 21 with RpkiObject

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

the class RrdpServiceTest method should_parse_and_save_snapshot.

@Test
public void should_parse_and_save_snapshot() throws Exception {
    final TrustAnchor trustAnchor = TestObjects.newTrustAnchor();
    entityManager.persist(trustAnchor);
    final RpkiRepository rpkiRepository = new RpkiRepository(trustAnchor, "https://rrdp.ripe.net/notification.xml", RpkiRepository.Type.RRDP);
    entityManager.persist(rpkiRepository);
    final RrdpRepositoryValidationRun validationRun = new RrdpRepositoryValidationRun(rpkiRepository);
    final Snapshot snapshot = new RrdpParser().snapshot(Objects.fileIS("rrdp/snapshot2.xml"));
    subject.storeSnapshot(snapshot, validationRun);
    final List<RpkiObject> objects = rpkiObjects.all().collect(Collectors.toList());
    assertEquals(3, objects.size());
    final String uri1 = "rsync://rpki.ripe.net/repository/DEFAULT/61/fdce4c-2ea5-47eb-94bc-5b50ea88eeab/1/phQ5JfV8llJoaGylcrBcVa7oPfI.roa";
    assertTrue(objects.stream().anyMatch(o -> uri1.equals(o.getLocations().first())));
    final String uri2 = "rsync://rpki.ripe.net/repository/DEFAULT/a0/bf69c4-d64a-4340-9bf1-364854cbc0e8/1/Xt2pFufQkzxVnLyxgKKC8x5dVsw.mft";
    assertTrue(objects.stream().anyMatch(o -> uri2.equals(o.getLocations().first())));
    final String uri3 = "rsync://rpki.ripe.net/repository/DEFAULT/8f/db5787-c2c8-429b-8137-cbf6c1849c44/1/s70Ab2nV-TCWnoHVAM4QdNgMolQ.mft";
    assertTrue(objects.stream().anyMatch(o -> uri3.equals(o.getLocations().first())));
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorCodes(net.ripe.rpki.validator3.domain.ErrorCodes) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) BigInteger(java.math.BigInteger) Sha256(net.ripe.rpki.validator3.util.Sha256) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) Transactional(javax.transaction.Transactional) Hex(net.ripe.rpki.validator3.util.Hex) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) EntityManager(javax.persistence.EntityManager) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest) TestObjects(net.ripe.rpki.validator3.TestObjects) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck) Assert.assertEquals(org.junit.Assert.assertEquals) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) Test(org.junit.Test) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest)

Example 22 with RpkiObject

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

the class RrdpServiceTest method should_parse_notification_use_delta.

@Test
public void should_parse_notification_use_delta() {
    final byte[] certificate = Objects.aParseableCertificate();
    final long serial = 2;
    final String sessionId = UUID.randomUUID().toString();
    final byte[] emptySnapshotXml = Objects.snapshotXml(serial, sessionId);
    final Objects.SnapshotInfo emptySnapshot = new Objects.SnapshotInfo("https://host/path/snapshot.xml", Sha256.hash(emptySnapshotXml));
    rrdpClient.add(emptySnapshot.uri, emptySnapshotXml);
    final Objects.DeltaPublish publishCert = new Objects.DeltaPublish("rsync://host/path/cert.cer", certificate);
    final byte[] deltaXml = Objects.deltaXml(serial, sessionId, publishCert);
    final Objects.DeltaInfo deltaInfo = new Objects.DeltaInfo("https://host/path/delta1.xml", Sha256.hash(deltaXml), serial);
    rrdpClient.add(deltaInfo.uri, deltaXml);
    final String notificationUri = "https://rrdp.ripe.net/notification.xml";
    rrdpClient.add(notificationUri, Objects.notificationXml(serial, sessionId, emptySnapshot, deltaInfo));
    final TrustAnchor trustAnchor = TestObjects.newTrustAnchor();
    entityManager.persist(trustAnchor);
    // make current serial lower to trigger delta download
    final RpkiRepository rpkiRepository = new RpkiRepository(trustAnchor, notificationUri, RpkiRepository.Type.RRDP);
    rpkiRepository.setRrdpSerial(BigInteger.valueOf(serial - 1));
    rpkiRepository.setRrdpSessionId(sessionId);
    entityManager.persist(rpkiRepository);
    // do the first run to get the snapshot
    RrdpRepositoryValidationRun validationRun = new RrdpRepositoryValidationRun(rpkiRepository);
    subject.storeRepository(rpkiRepository, validationRun);
    assertEquals(0, validationRun.getValidationChecks().size());
    final List<RpkiObject> objects = rpkiObjects.all().collect(Collectors.toList());
    assertEquals(1, objects.size());
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) TestObjects(net.ripe.rpki.validator3.TestObjects) Test(org.junit.Test) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest)

Example 23 with RpkiObject

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

the class RrdpServiceTest method should_parse_notification_use_delta_mismatching_delta_hash_fallback_to_snapshot.

@Test
public void should_parse_notification_use_delta_mismatching_delta_hash_fallback_to_snapshot() {
    final byte[] certificate = Objects.aParseableCertificate();
    final String sessionId = UUID.randomUUID().toString();
    final Objects.Publish crl = new Objects.Publish("rsync://host/path/crl1.crl", Objects.aParseableCrl());
    rrdpClient.add(crl.uri, crl.content);
    final byte[] snapshotXml = Objects.snapshotXml(3, sessionId, crl);
    final Objects.SnapshotInfo emptySnapshot = new Objects.SnapshotInfo("https://host/path/snapshot.xml", Sha256.hash(snapshotXml));
    rrdpClient.add(emptySnapshot.uri, snapshotXml);
    final Objects.DeltaPublish publishCert = new Objects.DeltaPublish("rsync://host/path/cert.cer", certificate);
    final byte[] deltaXml1 = Objects.deltaXml(3, sessionId, publishCert);
    final Objects.DeltaInfo deltaInfo1 = new Objects.DeltaInfo("https://host/path/delta1.xml", Hex.parse("FFFFFFFF"), 3);
    rrdpClient.add(deltaInfo1.uri, deltaXml1);
    final String notificationUri = "https://rrdp.ripe.net/notification.xml";
    rrdpClient.add(notificationUri, Objects.notificationXml(3, sessionId, emptySnapshot, deltaInfo1));
    final TrustAnchor trustAnchor = TestObjects.newTrustAnchor();
    entityManager.persist(trustAnchor);
    // make current serial lower to trigger delta download
    final RpkiRepository rpkiRepository = makeRpkiRepository(sessionId, notificationUri, trustAnchor);
    // do the first run to get the snapshot
    RrdpRepositoryValidationRun validationRun = new RrdpRepositoryValidationRun(rpkiRepository);
    subject.storeRepository(rpkiRepository, validationRun);
    assertEquals(1, validationRun.getValidationChecks().size());
    final ValidationCheck validationCheck = validationRun.getValidationChecks().get(0);
    assertEquals(ErrorCodes.RRDP_FETCH_DELTAS, validationCheck.getKey());
    assertEquals(ValidationCheck.Status.WARNING, validationCheck.getStatus());
    assertEquals(rpkiRepository.getRrdpNotifyUri(), validationCheck.getLocation());
    assertTrue(validationCheck.getParameters().get(0).startsWith("Hash of the delta file"));
    assertTrue(validationCheck.getParameters().get(0).contains("is " + Hex.format(Sha256.hash(deltaXml1)) + ", but notification file says FFFFFFFF"));
    final List<RpkiObject> objects = rpkiObjects.all().collect(Collectors.toList());
    assertEquals(1, objects.size());
    final RpkiObject rpkiObject = objects.get(0);
    assertEquals(RpkiObject.Type.CRL, rpkiObject.getType());
    assertEquals(Sets.newHashSet("rsync://host/path/crl1.crl"), rpkiObject.getLocations());
}
Also used : RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) RrdpRepositoryValidationRun(net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) RpkiObjects(net.ripe.rpki.validator3.domain.RpkiObjects) TestObjects(net.ripe.rpki.validator3.TestObjects) ValidationCheck(net.ripe.rpki.validator3.domain.ValidationCheck) Test(org.junit.Test) IntegrationTest(net.ripe.rpki.validator3.IntegrationTest)

Example 24 with RpkiObject

use of net.ripe.rpki.validator3.domain.RpkiObject 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));
    }
}
Also used : RpkiObject(net.ripe.rpki.validator3.domain.RpkiObject) CertificateRepositoryObject(net.ripe.rpki.commons.crypto.CertificateRepositoryObject) ValidationResult(net.ripe.rpki.commons.validation.ValidationResult)

Example 25 with RpkiObject

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

Aggregations

RpkiObject (net.ripe.rpki.validator3.domain.RpkiObject)20 RpkiRepository (net.ripe.rpki.validator3.domain.RpkiRepository)17 TrustAnchor (net.ripe.rpki.validator3.domain.TrustAnchor)16 IntegrationTest (net.ripe.rpki.validator3.IntegrationTest)14 RpkiObjects (net.ripe.rpki.validator3.domain.RpkiObjects)14 Test (org.junit.Test)14 ValidationCheck (net.ripe.rpki.validator3.domain.ValidationCheck)12 ValidationResult (net.ripe.rpki.commons.validation.ValidationResult)10 RrdpRepositoryValidationRun (net.ripe.rpki.validator3.domain.RrdpRepositoryValidationRun)10 Transactional (javax.transaction.Transactional)9 TestObjects (net.ripe.rpki.validator3.TestObjects)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 List (java.util.List)8 URI (java.net.URI)6 EntityManager (javax.persistence.EntityManager)6 KeyPair (java.security.KeyPair)5 Optional (java.util.Optional)5 X500Principal (javax.security.auth.x500.X500Principal)5 BigInteger (java.math.BigInteger)4 HashMap (java.util.HashMap)4