-
Notifications
You must be signed in to change notification settings - Fork 1
Scanning profiles #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Scanning profiles #163
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1cad30f
feat: basic scanning profiles
FelixLange1998 80ecb20
feat: settings for profiles
FelixLange1998 d9405d9
chore: inheritance via file paths
FelixLange1998 655874a
refactor: list for each type
FelixLange1998 c45b677
feat: support glob-style for all and negations
FelixLange1998 419087b
feat: list probes command
FelixLange1998 e8ed5c6
refactor: requested review changes
FelixLange1998 2c22676
refactor: requested review changes
FelixLange1998 3b85ed5
refactor: remove names
FelixLange1998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/de/rub/nds/scanner/core/config/ProbeTypeCatalog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis. | ||
| * | ||
| * Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
| * | ||
| * Licensed under Apache License, Version 2.0 | ||
| * http://www.apache.org/licenses/LICENSE-2.0.txt | ||
| */ | ||
| package de.rub.nds.scanner.core.config; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import de.rub.nds.scanner.core.probe.ProbeType; | ||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Renders the constants of one or more {@link ProbeType} enum classes as the same JSON syntax used | ||
| * by a {@link ScanProfile}'s {@code probes} field, so it can be copy-pasted straight into a profile | ||
| * (e.g. behind a {@code -listProbes} CLI flag implemented by a concrete scanner, which knows which | ||
| * {@link ProbeType} classes it registers). | ||
| */ | ||
| public final class ProbeTypeCatalog { | ||
|
|
||
| private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
|
||
| private ProbeTypeCatalog() { | ||
| // Utility class | ||
| } | ||
|
|
||
| /** | ||
| * Renders every constant of the given {@link ProbeType} enum classes as pretty-printed JSON, in | ||
| * the exact shape expected by a scan profile's {@code probes} field — a map from each class's | ||
| * fully qualified name to the list of its constant names, in declaration order. | ||
| * | ||
| * @param probeTypeClasses the {@link ProbeType} enum classes to list, e.g. {@code | ||
| * List.of(TlsProbeType.class, QuicProbeType.class)} | ||
| * @return the pretty-printed JSON, ready to paste as (or into) a profile's {@code probes} field | ||
| */ | ||
| public static String toProfileProbesJson(List<Class<? extends ProbeType>> probeTypeClasses) { | ||
| Map<String, List<String>> probesByType = new LinkedHashMap<>(); | ||
| for (Class<? extends ProbeType> probeTypeClass : probeTypeClasses) { | ||
| List<String> constantNames = new ArrayList<>(); | ||
| for (Object constant : probeTypeClass.getEnumConstants()) { | ||
| constantNames.add(((Enum<?>) constant).name()); | ||
| } | ||
| probesByType.put(probeTypeClass.getName(), constantNames); | ||
| } | ||
| try { | ||
| return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(probesByType); | ||
| } catch (JsonProcessingException e) { | ||
| // Unreachable: probesByType only ever contains plain strings and lists thereof. | ||
| throw new IllegalStateException("Could not render probe type catalog", e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.