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