Search in sources :

Example 1 with TrustAnchorLocator

use of net.ripe.rpki.validator3.util.TrustAnchorLocator 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())));
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RpkiRepository(net.ripe.rpki.validator3.domain.RpkiRepository) StringUtils(org.apache.commons.lang.StringUtils) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Valid(javax.validation.Valid) Paging(net.ripe.rpki.validator3.api.Paging) RpkiRepositories(net.ripe.rpki.validator3.domain.RpkiRepositories) Api(net.ripe.rpki.validator3.api.Api) Locale(java.util.Locale) ValidationRunController(net.ripe.rpki.validator3.api.validationruns.ValidationRunController) TrustAnchorExtractorException(net.ripe.rpki.validator3.util.TrustAnchorExtractorException) URI(java.net.URI) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) PostMapping(org.springframework.web.bind.annotation.PostMapping) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ValidationRun(net.ripe.rpki.validator3.domain.ValidationRun) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ValidationRuns(net.ripe.rpki.validator3.domain.ValidationRuns) Links(org.springframework.hateoas.Links) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Metadata(net.ripe.rpki.validator3.api.Metadata) ArrayList(java.util.ArrayList) Sorting(net.ripe.rpki.validator3.api.Sorting) RequestBody(org.springframework.web.bind.annotation.RequestBody) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) GetMapping(org.springframework.web.bind.annotation.GetMapping) TrustAnchorValidationRun(net.ripe.rpki.validator3.domain.TrustAnchorValidationRun) MessageSource(org.springframework.context.MessageSource) ValidationCheckResource(net.ripe.rpki.validator3.api.validationruns.ValidationCheckResource) Link(org.springframework.hateoas.Link) ApiError(net.ripe.rpki.validator3.api.ApiError) TrustAnchors(net.ripe.rpki.validator3.domain.TrustAnchors) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HttpStatus(org.springframework.http.HttpStatus) ApiCommand(net.ripe.rpki.validator3.api.ApiCommand) ValidationRunResource(net.ripe.rpki.validator3.api.validationruns.ValidationRunResource) SearchTerm(net.ripe.rpki.validator3.api.SearchTerm) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) ApiResponse(net.ripe.rpki.validator3.api.ApiResponse) TrustAnchorExtractorException(net.ripe.rpki.validator3.util.TrustAnchorExtractorException) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) URI(java.net.URI) Link(org.springframework.hateoas.Link) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with TrustAnchorLocator

use of net.ripe.rpki.validator3.util.TrustAnchorLocator in project rpki-validator-3 by RIPE-NCC.

the class PreconfiguredTrustAnchors method managePreconfiguredTrustAnchors.

@PostConstruct
public void managePreconfiguredTrustAnchors() {
    new TransactionTemplate(transactionManager).execute((status) -> {
        log.info("Automatically adding preconfigured trust anchors");
        if (settings.isPreconfiguredTalsLoaded()) {
            log.info("Preconfigured trust anchors are already loaded, skipping");
            return null;
        }
        settings.markPreconfiguredTalsLoaded();
        File[] tals = preconfiguredTrustAnchorDirectory.listFiles(new PatternFilenameFilter(Pattern.compile("^.*\\.tal$")));
        if (ArrayUtils.isEmpty(tals)) {
            log.warn("No preconfigured trust anchors found at {}, skipping", preconfiguredTrustAnchorDirectory);
            return null;
        }
        for (File tal : tals) {
            TrustAnchorLocator locator = TrustAnchorLocator.fromFile(tal);
            if (trustAnchors.findBySubjectPublicKeyInfo(locator.getPublicKeyInfo()).isPresent()) {
                log.info("Preconfigured trust anchor '{}' already installed, skipping", locator.getCaName());
                continue;
            }
            TrustAnchor trustAnchor = new TrustAnchor(true);
            trustAnchor.setName(locator.getCaName());
            trustAnchor.setLocations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList()));
            trustAnchor.setSubjectPublicKeyInfo(locator.getPublicKeyInfo());
            trustAnchor.setRsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null));
            trustAnchorService.add(trustAnchor);
        }
        return null;
    });
}
Also used : PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) File(java.io.File) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) URI(java.net.URI) PostConstruct(javax.annotation.PostConstruct)

Aggregations

URI (java.net.URI)2 TrustAnchor (net.ripe.rpki.validator3.domain.TrustAnchor)2 TrustAnchorLocator (net.ripe.rpki.validator3.util.TrustAnchorLocator)2 PatternFilenameFilter (com.google.common.io.PatternFilenameFilter)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 PostConstruct (javax.annotation.PostConstruct)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Valid (javax.validation.Valid)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Api (net.ripe.rpki.validator3.api.Api)1 ApiCommand (net.ripe.rpki.validator3.api.ApiCommand)1 ApiError (net.ripe.rpki.validator3.api.ApiError)1 ApiResponse (net.ripe.rpki.validator3.api.ApiResponse)1