Skip to content

Commit cc988e0

Browse files
committed
Merge branch 'main' into fix-obl-unsatisfied-obligation-scanner
# Conflicts: # src/test/java/de/rub/nds/scanner/core/execution/ScannerTest.java
2 parents ee39dc4 + 9c438a7 commit cc988e0

File tree

59 files changed

+5289
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5289
-260
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ updates:
1313
interval: "daily"
1414
open-pull-requests-limit: 20
1515
registries: "*"
16+
groups:
17+
internal:
18+
patterns:
19+
- "de.rub.nds*"

pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.rub.nds</groupId>
66
<artifactId>protocol-toolkit-bom</artifactId>
7-
<version>6.0.1</version>
7+
<version>6.2.1</version>
88
</parent>
99

1010
<artifactId>scanner-core</artifactId>
@@ -145,7 +145,7 @@
145145
<spacesPerTab>4</spacesPerTab>
146146
</indent>
147147
<googleJavaFormat>
148-
<version>1.25.2</version>
148+
<version>${plugin.spotless-maven-plugin.google-java-format.version}</version>
149149
<style>AOSP</style>
150150
</googleJavaFormat>
151151
<licenseHeader>
@@ -185,9 +185,7 @@
185185
<configuration>
186186
<source>${maven.compiler.source}</source>
187187
<target>${maven.compiler.target}</target>
188-
<compilerArgs>
189-
<compilerArg>-proc:full</compilerArg>
190-
</compilerArgs>
188+
<proc>full</proc>
191189
</configuration>
192190
</plugin>
193191
<!-- Execute unit tests -->

src/main/java/de/rub/nds/scanner/core/execution/ScannerThreadPoolExecutor.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
*/
99
package de.rub.nds.scanner.core.execution;
1010

11+
import java.util.List;
12+
import java.util.Timer;
13+
import java.util.TimerTask;
1114
import java.util.concurrent.Callable;
1215
import java.util.concurrent.Future;
1316
import java.util.concurrent.RejectedExecutionHandler;
1417
import java.util.concurrent.ScheduledThreadPoolExecutor;
1518
import java.util.concurrent.Semaphore;
1619
import java.util.concurrent.ThreadFactory;
1720
import java.util.concurrent.ThreadPoolExecutor;
18-
import java.util.concurrent.TimeUnit;
1921
import org.apache.logging.log4j.LogManager;
2022
import org.apache.logging.log4j.Logger;
2123

2224
/**
2325
* Extends {@link ThreadPoolExecutor} with its own afterExecute function. A
2426
* ScannerThreadPoolExecutor hold a semaphore which is released each time a Thread finished
25-
* executing.
27+
* executing or is aborted on timeout.
2628
*/
2729
public class ScannerThreadPoolExecutor extends ScheduledThreadPoolExecutor {
2830

@@ -35,6 +37,8 @@ public class ScannerThreadPoolExecutor extends ScheduledThreadPoolExecutor {
3537
/** The time after which tasks are automatically cancelled */
3638
private final long timeout;
3739

40+
private final Timer timer;
41+
3842
/**
3943
* Call super and assign the semaphore
4044
*
@@ -50,6 +54,7 @@ public ScannerThreadPoolExecutor(
5054
this.timeout = timeout;
5155
this.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
5256
this.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
57+
this.timer = new Timer();
5358
}
5459

5560
/**
@@ -84,6 +89,7 @@ public Future<?> submit(Runnable task) {
8489
* @param result the result to return when the task completes
8590
* @return a Future representing pending completion of the task
8691
*/
92+
@Override
8793
public <T> Future<T> submit(Runnable task, T result) {
8894
Future<T> future = super.submit(task, result);
8995
cancelFuture(future);
@@ -98,28 +104,48 @@ public <T> Future<T> submit(Runnable task, T result) {
98104
* @param task the task to submit
99105
* @return a Future representing pending completion of the task
100106
*/
107+
@Override
101108
public <T> Future<T> submit(Callable<T> task) {
102109
Future<T> future = super.submit(task);
103110
cancelFuture(future);
104111
return future;
105112
}
106113

114+
@Override
115+
public void shutdown() {
116+
super.shutdown();
117+
timer.cancel();
118+
}
119+
120+
@Override
121+
public List<Runnable> shutdownNow() {
122+
timer.cancel();
123+
return super.shutdownNow();
124+
}
125+
126+
@Override
127+
public void close() {
128+
super.close();
129+
timer.cancel();
130+
}
131+
107132
private void cancelFuture(Future<?> future) {
108-
this.schedule(
109-
() -> {
110-
if (!future.isDone()) {
111-
future.cancel(true);
112-
if (future.isCancelled()) {
113-
LOGGER.error("Killed task {}", future);
133+
timer.schedule(
134+
new TimerTask() {
135+
@Override
136+
public void run() {
137+
if (!future.isDone()) {
138+
future.cancel(true);
139+
if (future.isCancelled()) {
140+
LOGGER.error("Killed task {}", future);
141+
} else {
142+
LOGGER.error("Could not kill task {}", future);
143+
}
114144
} else {
115-
LOGGER.error("Could not kill task {}", future);
145+
LOGGER.debug("Future already done! {}", future);
116146
}
117-
} else {
118-
LOGGER.debug("Future already done! {}", future);
119147
}
120-
semaphore.release();
121148
},
122-
timeout,
123-
TimeUnit.MILLISECONDS);
149+
timeout);
124150
}
125151
}

src/main/java/de/rub/nds/scanner/core/execution/ThreadedScanJobExecutor.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.LinkedList;
2222
import java.util.List;
23-
import java.util.concurrent.ExecutionException;
24-
import java.util.concurrent.Future;
25-
import java.util.concurrent.Semaphore;
26-
import java.util.concurrent.ThreadPoolExecutor;
23+
import java.util.concurrent.*;
2724
import org.apache.logging.log4j.LogManager;
2825
import org.apache.logging.log4j.Logger;
2926

@@ -57,7 +54,7 @@ public class ThreadedScanJobExecutor<
5754
private final ThreadPoolExecutor executor;
5855

5956
// Used for waiting for Threads in the ThreadPoolExecutor
60-
private final Semaphore semaphore = new Semaphore(0);
57+
private final Semaphore semaphore;
6158

6259
private int probeCount;
6360
private int finishedProbes = 0;
@@ -76,7 +73,8 @@ public ThreadedScanJobExecutor(
7673
int threadCount,
7774
String prefix) {
7875
long probeTimeout = config.getProbeTimeout();
79-
executor =
76+
this.semaphore = new Semaphore(0);
77+
this.executor =
8078
new ScannerThreadPoolExecutor(
8179
threadCount, new NamedThreadFactory(prefix), semaphore, probeTimeout);
8280
this.config = config;
@@ -90,11 +88,14 @@ public ThreadedScanJobExecutor(
9088
* @param config the executor configuration
9189
* @param scanJob the scan job containing probes to execute
9290
* @param executor the thread pool executor to use
91+
* @param semaphore the semaphore released by the executor when a probe finishes
9392
*/
9493
public ThreadedScanJobExecutor(
9594
ExecutorConfig config,
9695
ScanJob<ReportT, ProbeT, AfterProbeT, StateT> scanJob,
97-
ThreadPoolExecutor executor) {
96+
ThreadPoolExecutor executor,
97+
Semaphore semaphore) {
98+
this.semaphore = semaphore;
9899
this.executor = executor;
99100
this.config = config;
100101
this.scanJob = scanJob;

src/main/java/de/rub/nds/scanner/core/probe/AnalyzedProperty.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import jakarta.xml.bind.annotation.XmlAccessType;
1414
import jakarta.xml.bind.annotation.XmlAccessorType;
1515
import jakarta.xml.bind.annotation.XmlRootElement;
16+
import java.io.Serializable;
1617

1718
@XmlRootElement
1819
@XmlAccessorType(XmlAccessType.FIELD)
1920
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
20-
public interface AnalyzedProperty {
21+
public interface AnalyzedProperty extends Serializable {
2122

2223
AnalyzedPropertyCategory getCategory();
2324

src/main/java/de/rub/nds/scanner/core/probe/AnalyzedPropertyCategory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import com.fasterxml.jackson.annotation.JsonTypeInfo;
1212
import jakarta.xml.bind.annotation.XmlAccessType;
1313
import jakarta.xml.bind.annotation.XmlAccessorType;
14+
import java.io.Serializable;
1415

1516
@XmlAccessorType(XmlAccessType.FIELD)
1617
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
17-
public interface AnalyzedPropertyCategory {}
18+
public interface AnalyzedPropertyCategory extends Serializable {}

src/main/java/de/rub/nds/scanner/core/probe/ProbeTypeConverter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package de.rub.nds.scanner.core.probe;
1010

1111
import com.beust.jcommander.IStringConverter;
12+
import java.lang.reflect.InvocationTargetException;
1213
import java.util.Set;
1314
import java.util.stream.Collectors;
1415
import org.reflections.Reflections;
@@ -46,7 +47,10 @@ public ProbeType convert(String value) {
4647
if (convertedType != null) {
4748
return convertedType;
4849
}
49-
} catch (Exception ignored) {
50+
} catch (NoSuchMethodException
51+
| IllegalAccessException
52+
| IllegalArgumentException
53+
| InvocationTargetException ignored) {
5054
// Ignore conversion failures and try next method
5155
}
5256
}

src/main/java/de/rub/nds/scanner/core/report/AnalyzedPropertyTextEncoder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,30 @@
1111
import de.rub.nds.scanner.core.probe.AnalyzedProperty;
1212
import java.util.HashMap;
1313

14+
/**
15+
* An encoder that converts AnalyzedProperty instances to their text representation. Uses a provided
16+
* mapping to translate properties to custom strings.
17+
*/
1418
public class AnalyzedPropertyTextEncoder extends Encoder<AnalyzedProperty> {
1519

1620
private final HashMap<AnalyzedProperty, String> map;
1721

22+
/**
23+
* Creates a new AnalyzedPropertyTextEncoder with the specified property-to-text mapping.
24+
*
25+
* @param map a HashMap mapping AnalyzedProperty instances to their string representations
26+
*/
1827
public AnalyzedPropertyTextEncoder(HashMap<AnalyzedProperty, String> map) {
1928
this.map = map;
2029
}
2130

31+
/**
32+
* Encodes an AnalyzedProperty to its string representation. If a mapping exists, returns the
33+
* mapped value; otherwise returns the property's name.
34+
*
35+
* @param analyzedProperty the property to encode
36+
* @return the string representation of the property
37+
*/
2238
@Override
2339
public String encode(AnalyzedProperty analyzedProperty) {
2440
if (map == null) {

src/main/java/de/rub/nds/scanner/core/report/AnsiColor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14+
/**
15+
* Enum representing ANSI color codes for terminal output. Provides foreground colors, background
16+
* colors, and text formatting options.
17+
*/
1418
public enum AnsiColor {
1519
RESET("\u001B[0m"),
1620
BLACK("\u001B[30m"),
@@ -48,10 +52,21 @@ public enum AnsiColor {
4852
}
4953
}
5054

55+
/**
56+
* Returns the AnsiColor corresponding to the given ANSI code string.
57+
*
58+
* @param code the ANSI code string
59+
* @return the corresponding AnsiColor, or null if no match is found
60+
*/
5161
public static AnsiColor getAnsiColor(String code) {
5262
return MAP.get(code);
5363
}
5464

65+
/**
66+
* Returns the ANSI code string for this color.
67+
*
68+
* @return the ANSI code string
69+
*/
5570
public String getCode() {
5671
return code;
5772
}

src/main/java/de/rub/nds/scanner/core/report/AnsiEscapeSequence.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
*/
99
package de.rub.nds.scanner.core.report;
1010

11+
/**
12+
* Utility class containing ANSI escape sequences for terminal manipulation. Provides constants for
13+
* cursor movement and line manipulation.
14+
*/
1115
public class AnsiEscapeSequence {
1216

17+
/** ANSI escape sequence to move cursor up one line */
1318
public static final String ANSI_ONE_LINE_UP = "\033[1A";
19+
20+
/** ANSI escape sequence to erase the current line */
1421
public static final String ANSI_ERASE_LINE = "\033[2K";
1522
}

0 commit comments

Comments
 (0)