Skip to content

Commit 21cada3

Browse files
committed
delete the progressbar when finished
don't print the progessbar in debug mode added scantime to the top of the report in the console
1 parent a37c486 commit 21cada3

File tree

3 files changed

+166
-130
lines changed

3 files changed

+166
-130
lines changed

src/main/java/de/rub/nds/tlsscanner/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static void main(String[] args) throws IOException {
4242
LOGGER.info("Performing Scan, this may take some time...");
4343
SiteReport report = scanner.scan();
4444
LOGGER.info("Scanned in:" + ((System.currentTimeMillis()-time)/1000) + "s");
45-
ConsoleLogger.CONSOLE.info(report.getFullReport(config.getReportDetail()));
45+
// ANSI escape sequences to erase the progressbar
46+
ConsoleLogger.CONSOLE.info("\033[1A\033[2KScanned in: " + ((System.currentTimeMillis()-time)/1000) + "s\n" + report.getFullReport(config.getReportDetail()));
4647
} catch (ConfigurationException E) {
4748
LOGGER.info("Encountered a ConfigurationException aborting.");
4849
LOGGER.warn(E);

src/main/java/de/rub/nds/tlsscanner/MultiThreadedScanJobExecutor.java

Lines changed: 87 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -47,97 +47,110 @@ public MultiThreadedScanJobExecutor(ExecutorService executor) {
4747
}
4848

4949
public SiteReport execute(ScannerConfig config, ScanJob scanJob) {
50-
List<ProbeType> probeTypes = new LinkedList<>();
5150

52-
int numberOfProbes = 0;
53-
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
51+
if(config.getGeneralDelegate().isDebug()){
52+
return scan(config, scanJob, null);
53+
} else {
54+
int numberOfProbes = 0;
55+
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
5456
if (probe.getDanger() <= config.getDangerLevel()) {
5557
numberOfProbes++;
5658
}
57-
}
58-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
59+
}
60+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
5961
if (probe.getDanger() <= config.getDangerLevel()) {
6062
numberOfProbes++;
6163
}
64+
}
65+
try (ProgressBar pb = new ProgressBar("", numberOfProbes)) {
66+
return scan(config, scanJob, pb);
67+
}
6268
}
63-
64-
try(ProgressBar pb = new ProgressBar("", numberOfProbes)){
69+
}
70+
71+
private SiteReport scan(ScannerConfig config, ScanJob scanJob, ProgressBar pb) {
72+
List<ProbeType> probeTypes = new LinkedList<>();
73+
if(pb != null){
6574
pb.setExtraMessage("Executing Probes");
66-
List<Future<ProbeResult>> futureResults = new LinkedList<>();
67-
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
68-
if (probe.getDanger() <= config.getDangerLevel()) {
69-
futureResults.add(executor.submit(probe));
70-
probeTypes.add(probe.getType());
71-
}
72-
}
73-
List<ProbeResult> resultList = new LinkedList<>();
74-
75-
checkProbesDone(futureResults, pb);
76-
77-
for (Future<ProbeResult> probeResult : futureResults) {
78-
try {
79-
resultList.add(probeResult.get());
80-
} catch (InterruptedException | ExecutionException ex) {
81-
LOGGER.warn("Encoutered Exception while retrieving probeResult");
82-
ex.printStackTrace();
83-
LOGGER.warn(ex);
84-
}
75+
}
76+
List<Future<ProbeResult>> futureResults = new LinkedList<>();
77+
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
78+
if (probe.getDanger() <= config.getDangerLevel()) {
79+
futureResults.add(executor.submit(probe));
80+
probeTypes.add(probe.getType());
8581
}
82+
}
83+
List<ProbeResult> resultList = new LinkedList<>();
8684

87-
ClientDelegate clientDelegate = (ClientDelegate) config.getDelegate(ClientDelegate.class);
88-
String hostname = clientDelegate.getHost();
89-
SiteReport report = new SiteReport(hostname, probeTypes, config.isNoColor());
90-
report.setServerIsAlive(Boolean.TRUE);
91-
for (ProbeResult result : resultList) {
92-
result.merge(report);
93-
}
94-
//Finished phase one starting phase 2
95-
//Now all basic tests are merged into the site report, so we launch phase 2 so the scanner
96-
//has access to basic server configuration
97-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
98-
probe.adjustConfig(report);
85+
checkProbesDone(futureResults, pb);
86+
87+
for (Future<ProbeResult> probeResult : futureResults) {
88+
try {
89+
resultList.add(probeResult.get());
90+
} catch (InterruptedException | ExecutionException ex) {
91+
LOGGER.warn("Encoutered Exception while retrieving probeResult");
92+
ex.printStackTrace();
93+
LOGGER.warn(ex);
9994
}
100-
futureResults = new LinkedList<>();
101-
resultList = new LinkedList<>();
102-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
103-
if (probe.getDanger() <= config.getDangerLevel()) {
104-
probeTypes.add(probe.getType());
105-
if (probe.shouldBeExecuted(report)) {
106-
futureResults.add(executor.submit(probe));
107-
} else if (!config.isImplementation()) {
108-
ProbeResult result = probe.getNotExecutedResult();
109-
if (result != null) {
110-
resultList.add(result);
95+
}
96+
97+
ClientDelegate clientDelegate = (ClientDelegate) config.getDelegate(ClientDelegate.class);
98+
String hostname = clientDelegate.getHost();
99+
SiteReport report = new SiteReport(hostname, probeTypes, config.isNoColor());
100+
report.setServerIsAlive(Boolean.TRUE);
101+
for (ProbeResult result : resultList) {
102+
result.merge(report);
103+
}
104+
//Finished phase one starting phase 2
105+
//Now all basic tests are merged into the site report, so we launch phase 2 so the scanner
106+
//has access to basic server configuration
107+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
108+
probe.adjustConfig(report);
109+
}
110+
futureResults = new LinkedList<>();
111+
resultList = new LinkedList<>();
112+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
113+
if (probe.getDanger() <= config.getDangerLevel()) {
114+
probeTypes.add(probe.getType());
115+
if (probe.shouldBeExecuted(report)) {
116+
futureResults.add(executor.submit(probe));
117+
} else if (!config.isImplementation()) {
118+
ProbeResult result = probe.getNotExecutedResult();
119+
if (result != null) {
120+
resultList.add(result);
121+
if(pb != null){
111122
pb.step();
112123
}
113124
}
114125
}
115126
}
116-
117-
checkProbesDone(futureResults, pb);
118-
119-
for (Future<ProbeResult> probeResult : futureResults) {
120-
try {
121-
resultList.add(probeResult.get());
122-
} catch (InterruptedException | ExecutionException ex) {
123-
LOGGER.warn("Encoutered Exception while retrieving probeResult");
124-
ex.printStackTrace();
125-
LOGGER.warn(ex);
126-
}
127-
}
128-
// mergeData phase 2
129-
for (ProbeResult result : resultList) {
130-
result.merge(report);
131-
}
132-
//phase 3 - afterprobes
133-
for (AfterProbe afterProbe : scanJob.getAfterProbes()) {
134-
afterProbe.analyze(report);
127+
}
128+
129+
checkProbesDone(futureResults, pb);
130+
131+
for (Future<ProbeResult> probeResult : futureResults) {
132+
try {
133+
resultList.add(probeResult.get());
134+
} catch (InterruptedException | ExecutionException ex) {
135+
LOGGER.warn("Encoutered Exception while retrieving probeResult");
136+
ex.printStackTrace();
137+
LOGGER.warn(ex);
135138
}
136-
executor.shutdown();
139+
}
140+
// mergeData phase 2
141+
for (ProbeResult result : resultList) {
142+
result.merge(report);
143+
}
144+
//phase 3 - afterprobes
145+
for (AfterProbe afterProbe : scanJob.getAfterProbes()) {
146+
afterProbe.analyze(report);
147+
}
148+
executor.shutdown();
149+
if(pb != null){
137150
pb.setExtraMessage("Finished");
138-
LOGGER.info("Finished scan for: " + hostname);
139-
return report;
140151
}
152+
LOGGER.info("Finished scan for: " + hostname);
153+
return report;
141154
}
142155

143156
private void checkProbesDone(List<Future<ProbeResult>> futureResults, ProgressBar pb){
@@ -151,7 +164,9 @@ private void checkProbesDone(List<Future<ProbeResult>> futureResults, ProgressBa
151164
tempDone++;
152165
}
153166
if (done < tempDone) {
154-
pb.step();
167+
if(pb != null){
168+
pb.step();
169+
}
155170
done = tempDone;
156171
if (done == futureResults.size()) {
157172
isNotReady = false;

src/main/java/de/rub/nds/tlsscanner/SingleThreadedScanJobExecutor.java

Lines changed: 77 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,91 +42,111 @@ private String getPaddedProbeName( String probeName){
4242

4343
@Override
4444
public SiteReport execute(ScannerConfig config, ScanJob scanJob) {
45-
List<ProbeType> probeTypes = new LinkedList<>();
46-
List<ProbeResult> resultList = new LinkedList<>();
4745

48-
int numberOfProbes = 0;
49-
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
46+
if(config.getGeneralDelegate().isDebug()){
47+
return scan(config, scanJob, null);
48+
} else {
49+
int numberOfProbes = 0;
50+
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
5051
if (probe.getDanger() <= config.getDangerLevel()) {
5152
numberOfProbes++;
5253
}
53-
}
54-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
54+
}
55+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
5556
if (probe.getDanger() <= config.getDangerLevel()) {
5657
numberOfProbes++;
5758
}
59+
}
60+
try(ProgressBar pb = new ProgressBar("", numberOfProbes)){
61+
return scan(config, scanJob, pb);
62+
}
5863
}
5964

65+
66+
}
67+
68+
private SiteReport scan(ScannerConfig config, ScanJob scanJob, ProgressBar pb){
69+
List<ProbeType> probeTypes = new LinkedList<>();
70+
List<ProbeResult> resultList = new LinkedList<>();
6071

61-
try(ProgressBar pb = new ProgressBar("", numberOfProbes)){
62-
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
63-
if (probe.getDanger() <= config.getDangerLevel()) {
64-
try {
72+
for (TlsProbe probe : scanJob.getPhaseOneTestList()) {
73+
if (probe.getDanger() <= config.getDangerLevel()) {
74+
try {
75+
if(pb != null){
6576
pb.setExtraMessage("Executing " + getPaddedProbeName(probe.getProbeName()));
66-
resultList.add(probe.call());
77+
}
78+
resultList.add(probe.call());
79+
if(pb != null){
6780
pb.step();
68-
} catch (Exception E) {
69-
LOGGER.warn("Could not execute Probe", E);
7081
}
71-
probeTypes.add(probe.getType());
72-
}
73-
}
74-
75-
ClientDelegate clientDelegate = (ClientDelegate) config.getDelegate(ClientDelegate.class);
76-
String hostname = clientDelegate.getHost();
77-
SiteReport report = new SiteReport(hostname, probeTypes, config.isNoColor());
78-
report.setServerIsAlive(Boolean.TRUE);
79-
for (ProbeResult result : resultList) {
80-
try {
81-
result.merge(report);
8282
} catch (Exception E) {
83-
LOGGER.warn("Could not merge SiteReport", E);
83+
LOGGER.warn("Could not execute Probe", E);
8484
}
85+
probeTypes.add(probe.getType());
8586
}
86-
//Finished phase one starting phase 2
87-
//Now all basic tests are merged into the site report, so we launch phase 2 so the scanner
88-
//has access to basic server configuration
89-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
90-
probe.adjustConfig(report);
87+
}
88+
89+
ClientDelegate clientDelegate = (ClientDelegate) config.getDelegate(ClientDelegate.class);
90+
String hostname = clientDelegate.getHost();
91+
SiteReport report = new SiteReport(hostname, probeTypes, config.isNoColor());
92+
report.setServerIsAlive(Boolean.TRUE);
93+
for (ProbeResult result : resultList) {
94+
try {
95+
result.merge(report);
96+
} catch (Exception E) {
97+
LOGGER.warn("Could not merge SiteReport", E);
9198
}
92-
resultList = new LinkedList<>();
93-
resultList = new LinkedList<>();
94-
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
95-
if (probe.getDanger() <= config.getDangerLevel()) {
96-
probeTypes.add(probe.getType());
97-
if (probe.shouldBeExecuted(report)) {
98-
try {
99+
}
100+
//Finished phase one starting phase 2
101+
//Now all basic tests are merged into the site report, so we launch phase 2 so the scanner
102+
//has access to basic server configuration
103+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
104+
probe.adjustConfig(report);
105+
}
106+
resultList = new LinkedList<>();
107+
for (TlsProbe probe : scanJob.getPhaseTwoTestList()) {
108+
if (probe.getDanger() <= config.getDangerLevel()) {
109+
probeTypes.add(probe.getType());
110+
if (probe.shouldBeExecuted(report)) {
111+
try {
112+
if(pb != null){
99113
pb.setExtraMessage("Executing " + getPaddedProbeName(probe.getProbeName()));
100-
resultList.add(probe.call());
114+
}
115+
resultList.add(probe.call());
116+
if(pb != null){
101117
pb.step();
102-
} catch (Exception E) {
103-
LOGGER.warn("Could not execute Probe", E);
104118
}
105-
} else if (!config.isImplementation()) {
106-
ProbeResult result = probe.getNotExecutedResult();
107-
if (result != null) {
108-
resultList.add(result);
119+
} catch (Exception E) {
120+
LOGGER.warn("Could not execute Probe", E);
121+
}
122+
} else if (!config.isImplementation()) {
123+
ProbeResult result = probe.getNotExecutedResult();
124+
if (result != null) {
125+
resultList.add(result);
126+
if(pb != null){
109127
pb.step();
110128
}
111129
}
112130
}
113131
}
114-
// mergeData phase 2
115-
for (ProbeResult result : resultList) {
116-
try {
117-
result.merge(report);
118-
} catch (Exception E) {
119-
LOGGER.warn("Could not merge SiteReport", E);
120-
}
121-
}
122-
//phase 3 - afterprobes
123-
for (AfterProbe afterProbe : scanJob.getAfterProbes()) {
124-
afterProbe.analyze(report);
132+
}
133+
// mergeData phase 2
134+
for (ProbeResult result : resultList) {
135+
try {
136+
result.merge(report);
137+
} catch (Exception E) {
138+
LOGGER.warn("Could not merge SiteReport", E);
125139
}
140+
}
141+
//phase 3 - afterprobes
142+
for (AfterProbe afterProbe : scanJob.getAfterProbes()) {
143+
afterProbe.analyze(report);
144+
}
145+
if (pb != null) {
126146
pb.setExtraMessage(getPaddedProbeName("Finished"));
127-
LOGGER.info("Finished scan for: " + hostname);
128-
return report;
129147
}
148+
LOGGER.info("Finished scan for: " + hostname);
149+
return report;
130150
}
131151

132152
@Override

0 commit comments

Comments
 (0)