@@ -47,97 +47,110 @@ public MultiThreadedScanJobExecutor(ExecutorService executor) {
47
47
}
48
48
49
49
public SiteReport execute (ScannerConfig config , ScanJob scanJob ) {
50
- List <ProbeType > probeTypes = new LinkedList <>();
51
50
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 ()) {
54
56
if (probe .getDanger () <= config .getDangerLevel ()) {
55
57
numberOfProbes ++;
56
58
}
57
- }
58
- for (TlsProbe probe : scanJob .getPhaseTwoTestList ()) {
59
+ }
60
+ for (TlsProbe probe : scanJob .getPhaseTwoTestList ()) {
59
61
if (probe .getDanger () <= config .getDangerLevel ()) {
60
62
numberOfProbes ++;
61
63
}
64
+ }
65
+ try (ProgressBar pb = new ProgressBar ("" , numberOfProbes )) {
66
+ return scan (config , scanJob , pb );
67
+ }
62
68
}
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 ){
65
74
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 ());
85
81
}
82
+ }
83
+ List <ProbeResult > resultList = new LinkedList <>();
86
84
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 );
99
94
}
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 ){
111
122
pb .step ();
112
123
}
113
124
}
114
125
}
115
126
}
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 );
135
138
}
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 ){
137
150
pb .setExtraMessage ("Finished" );
138
- LOGGER .info ("Finished scan for: " + hostname );
139
- return report ;
140
151
}
152
+ LOGGER .info ("Finished scan for: " + hostname );
153
+ return report ;
141
154
}
142
155
143
156
private void checkProbesDone (List <Future <ProbeResult >> futureResults , ProgressBar pb ){
@@ -151,7 +164,9 @@ private void checkProbesDone(List<Future<ProbeResult>> futureResults, ProgressBa
151
164
tempDone ++;
152
165
}
153
166
if (done < tempDone ) {
154
- pb .step ();
167
+ if (pb != null ){
168
+ pb .step ();
169
+ }
155
170
done = tempDone ;
156
171
if (done == futureResults .size ()) {
157
172
isNotReady = false ;
0 commit comments