use of net.ripe.rpki.validator3.domain.TrustAnchor in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorController method add.
@PostMapping(path = "/upload", consumes = "multipart/form-data")
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale) {
try {
TrustAnchorLocator locator = TrustAnchorLocator.fromMultipartFile(trustAnchorLocator);
AddTrustAnchor command = AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(locator.getCaName()).locations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList())).subjectPublicKeyInfo(locator.getPublicKeyInfo()).rsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null)).build();
long id = trustAnchorService.execute(command);
TrustAnchor trustAnchor = trustAnchorRepository.get(id);
Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
} catch (TrustAnchorExtractorException ex) {
return ResponseEntity.badRequest().body(ApiResponse.error(ApiError.of(HttpStatus.BAD_REQUEST, "Invalid trust anchor locator: " + ex.getMessage())));
}
}
use of net.ripe.rpki.validator3.domain.TrustAnchor in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorService method execute.
public long execute(@Valid AddTrustAnchor command) {
TrustAnchor trustAnchor = new TrustAnchor(false);
trustAnchor.setName(command.getName());
trustAnchor.setLocations(command.getLocations());
trustAnchor.setSubjectPublicKeyInfo(command.getSubjectPublicKeyInfo());
trustAnchor.setRsyncPrefetchUri(command.getRsyncPrefetchUri());
return add(trustAnchor);
}
use of net.ripe.rpki.validator3.domain.TrustAnchor in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorValidationServiceTest method createRipeNccTrustAnchor.
public static TrustAnchor createRipeNccTrustAnchor() {
TrustAnchor ta = new TrustAnchor(false);
ta.setName("RIPE NCC");
ta.setLocations(Arrays.asList("rsync://rpki.ripe.net/ta/ripe-ncc-ta.cer"));
ta.setSubjectPublicKeyInfo("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0URYSGqUz2myBsOzeW1jQ6NsxNvlLMyhWknvnl8NiBCs/T/S2XuNKQNZ+wBZxIgPPV2pFBFeQAvoH/WK83HwA26V2siwm/MY2nKZ+Olw+wlpzlZ1p3Ipj2eNcKrmit8BwBC8xImzuCGaV0jkRB0GZ0hoH6Ml03umLprRsn6v0xOP0+l6Qc1ZHMFVFb385IQ7FQQTcVIxrdeMsoyJq9eMkE6DoclHhF/NlSllXubASQ9KUWqJ0+Ot3QCXr4LXECMfkpkVR2TZT+v5v658bHVs6ZxRD1b6Uk1uQKAyHUbn/tXvP8lrjAibGzVsXDT2L0x4Edx+QdixPgOji3gBMyL2VwIDAQAB");
return ta;
}
use of net.ripe.rpki.validator3.domain.TrustAnchor in project rpki-validator-3 by RIPE-NCC.
the class RrdpServiceTest method should_parse_notification_use_decline_delta_with_different_session_id_and_fallback_to_snapshot.
@Test
public void should_parse_notification_use_decline_delta_with_different_session_id_and_fallback_to_snapshot() {
final byte[] certificate = Objects.aParseableCertificate();
final long serial = 2;
final String sessionId = UUID.randomUUID().toString();
final String wrongSessionId = 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(serial, sessionId, crl);
final Objects.SnapshotInfo snapshot = new Objects.SnapshotInfo("https://host/path/snapshot.xml", Sha256.hash(snapshotXml));
rrdpClient.add(snapshot.uri, snapshotXml);
final Objects.DeltaPublish publishCert = new Objects.DeltaPublish("rsync://host/path/cert.cer", certificate);
final byte[] deltaXml = Objects.deltaXml(serial, wrongSessionId, 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, snapshot, 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
final 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).contains("Session id of the delta"));
assertTrue(validationCheck.getParameters().get(0).contains("is not the same as in the notification file: " + sessionId));
// make sure that it will be the CRL from the snapsh
final List<RpkiObject> objects = rpkiObjects.all().collect(Collectors.toList());
assertEquals(1, objects.size());
RpkiObject rpkiObject = objects.get(0);
assertEquals(RpkiObject.Type.CRL, rpkiObject.getType());
assertEquals(Sets.newHashSet("rsync://host/path/crl1.crl"), rpkiObject.getLocations());
}
use of net.ripe.rpki.validator3.domain.TrustAnchor in project rpki-validator-3 by RIPE-NCC.
the class RrdpServiceTest method should_parse_notification_use_delta_add_and_replace_an_object.
@Test
public void should_parse_notification_use_delta_add_and_replace_an_object() {
final byte[] certificate = Objects.aParseableCertificate();
final String sessionId = UUID.randomUUID().toString();
final byte[] emptySnapshotXml = Objects.snapshotXml(3, 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[] deltaXml1 = Objects.deltaXml(2, sessionId, publishCert);
final Objects.DeltaPublish republishCert = new Objects.DeltaPublish("rsync://host/path/cert.cer", Sha256.hash(publishCert.content), certificate);
final byte[] deltaXml2 = Objects.deltaXml(3, sessionId, republishCert);
final Objects.DeltaInfo deltaInfo1 = new Objects.DeltaInfo("https://host/path/delta1.xml", Sha256.hash(deltaXml1), 2);
final Objects.DeltaInfo deltaInfo2 = new Objects.DeltaInfo("https://host/path/delta2.xml", Sha256.hash(deltaXml2), 3);
rrdpClient.add(deltaInfo1.uri, deltaXml1);
rrdpClient.add(deltaInfo2.uri, deltaXml2);
final String notificationUri = "https://rrdp.ripe.net/notification.xml";
rrdpClient.add(notificationUri, Objects.notificationXml(3, sessionId, emptySnapshot, deltaInfo1, deltaInfo2));
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(0, validationRun.getValidationChecks().size());
final List<RpkiObject> objects = rpkiObjects.all().collect(Collectors.toList());
assertEquals(1, objects.size());
}
Aggregations