17
17
import de .rub .nds .tlsattacker .core .constants .CipherSuite ;
18
18
import de .rub .nds .tlsattacker .core .constants .HandshakeMessageType ;
19
19
import de .rub .nds .tlsattacker .core .constants .NamedGroup ;
20
+ import de .rub .nds .tlsattacker .core .constants .ProtocolVersion ;
20
21
import de .rub .nds .tlsattacker .core .constants .SignatureAndHashAlgorithm ;
21
22
import de .rub .nds .tlsattacker .core .protocol .message .ClientHelloMessage ;
22
23
import de .rub .nds .tlsattacker .core .protocol .message .HelloVerifyRequestMessage ;
@@ -155,8 +156,10 @@ private TestResult getResult(Config config, WorkflowTrace trace, boolean checkFo
155
156
try {
156
157
State state = new State (config , trace );
157
158
executeState (state );
158
- return checkForTrue == WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .SERVER_HELLO_DONE , trace )
159
- ? TestResults .TRUE : TestResults .FALSE ;
159
+ return checkForTrue == (WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .SERVER_HELLO_DONE , trace )
160
+ || (state .getTlsContext ().getSelectedProtocolVersion () == ProtocolVersion .TLS13
161
+ && (WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .FINISHED , trace )))) ? TestResults .TRUE
162
+ : TestResults .FALSE ;
160
163
} catch (Exception e ) {
161
164
if (e .getCause () instanceof InterruptedException ) {
162
165
LOGGER .error ("Timeout on " + getProbeName ());
@@ -169,7 +172,7 @@ private TestResult getResult(Config config, WorkflowTrace trace, boolean checkFo
169
172
}
170
173
171
174
private TestResult hasExtensionIntolerance () {
172
- Config config = configSelector .getBaseConfig ();
175
+ Config config = configSelector .getAnyWorkingBaseConfig ();
173
176
ClientHelloMessage message = new ClientHelloMessage (config );
174
177
UnknownExtensionMessage extension = new UnknownExtensionMessage ();
175
178
extension .setTypeConfig (new byte [] { (byte ) 3F , (byte ) 3F });
@@ -180,7 +183,7 @@ private TestResult hasExtensionIntolerance() {
180
183
}
181
184
182
185
private TestResult hasBigClientHelloIntolerance () {
183
- Config config = configSelector .getBaseConfig ();
186
+ Config config = configSelector .getAnyWorkingBaseConfig ();
184
187
config .setAddPaddingExtension (true );
185
188
config .setDefaultPaddingExtensionBytes (new byte [14000 ]);
186
189
ClientHelloMessage message = new ClientHelloMessage (config );
@@ -189,7 +192,7 @@ private TestResult hasBigClientHelloIntolerance() {
189
192
}
190
193
191
194
private TestResult hasIgnoresSigHashAlgoOfferingBug () {
192
- Config config = configSelector .getBaseConfig ();
195
+ Config config = configSelector .getAnyWorkingBaseConfig ();
193
196
config .setAddSignatureAndHashAlgorithmsExtension (false );
194
197
List <CipherSuite > suiteList = new LinkedList <>();
195
198
for (CipherSuite suite : CipherSuite .getImplemented ()) {
@@ -208,26 +211,33 @@ private TestResult hasIgnoresSigHashAlgoOfferingBug() {
208
211
}
209
212
210
213
private TestResult hasIgnoresNamedGroupsOfferingBug () {
211
- Config config = configSelector .getBaseConfig ();
212
- List <CipherSuite > suiteList = new LinkedList <>();
213
- for (CipherSuite suite : CipherSuite .getImplemented ()) {
214
- if (suite .isEphemeral () && suite .name ().contains ("EC" )) {
215
- suiteList .add (suite );
214
+ if (configSelector .foundWorkingConfig ()) {
215
+ Config config = configSelector .getBaseConfig ();
216
+ List <CipherSuite > suiteList = new LinkedList <>();
217
+ for (CipherSuite suite : CipherSuite .getImplemented ()) {
218
+ if (suite .isEphemeral () && suite .name ().contains ("EC" )) {
219
+ suiteList .add (suite );
220
+ }
216
221
}
222
+ config .setDefaultClientSupportedCipherSuites (suiteList );
223
+ config .setAddECPointFormatExtension (true );
224
+ config .setAddEllipticCurveExtension (false );
225
+ ClientHelloMessage message = new ClientHelloMessage (config );
226
+ EllipticCurvesExtensionMessage extension = new EllipticCurvesExtensionMessage ();
227
+ extension .setSupportedGroups (Modifiable .explicit (new byte [] { (byte ) 0xED , (byte ) 0xED }));
228
+ message .addExtension (extension );
229
+ WorkflowTrace trace = getWorkflowTrace (config , message );
230
+ return getResult (config , trace , true );
231
+ } else {
232
+ // servers choosing a different group in TLS 1.3 would send an
233
+ // invalid HelloRetryRequest message which has a significantly
234
+ // different meaning than the TLS 1.2 test case
235
+ return TestResults .FALSE ;
217
236
}
218
- config .setDefaultClientSupportedCipherSuites (suiteList );
219
- config .setAddECPointFormatExtension (true );
220
- config .setAddEllipticCurveExtension (false );
221
- ClientHelloMessage message = new ClientHelloMessage (config );
222
- EllipticCurvesExtensionMessage extension = new EllipticCurvesExtensionMessage ();
223
- extension .setSupportedGroups (Modifiable .explicit (new byte [] { (byte ) 0xED , (byte ) 0xED }));
224
- message .addExtension (extension );
225
- WorkflowTrace trace = getWorkflowTrace (config , message );
226
- return getResult (config , trace , true );
227
237
}
228
238
229
239
private void adjustCipherSuiteSelectionBugs () {
230
- Config config = configSelector .getBaseConfig ();
240
+ Config config = configSelector .getAnyWorkingBaseConfig ();
231
241
ClientHelloMessage message = new ClientHelloMessage (config );
232
242
message .setCipherSuites (Modifiable .explicit (new byte [] { (byte ) 0xEE , (byte ) 0xCC }));
233
243
WorkflowTrace trace = getWorkflowTrace (config , message );
@@ -255,7 +265,7 @@ private void adjustCipherSuiteSelectionBugs() {
255
265
}
256
266
257
267
private TestResult hasSignatureAndHashAlgorithmIntolerance () {
258
- Config config = configSelector .getBaseConfig ();
268
+ Config config = configSelector .getAnyWorkingBaseConfig ();
259
269
config .setAddSignatureAndHashAlgorithmsExtension (false );
260
270
List <CipherSuite > suiteList = new LinkedList <>();
261
271
for (CipherSuite suite : CipherSuite .getImplemented ()) {
@@ -274,7 +284,7 @@ private TestResult hasSignatureAndHashAlgorithmIntolerance() {
274
284
}
275
285
276
286
private TestResult hasNamedGroupIntolerance () {
277
- Config config = configSelector .getBaseConfig ();
287
+ Config config = configSelector .getAnyWorkingBaseConfig ();
278
288
List <CipherSuite > suiteList = new LinkedList <>();
279
289
for (CipherSuite suite : CipherSuite .getImplemented ()) {
280
290
if (suite .isEphemeral () && suite .name ().contains ("EC" )) {
@@ -293,25 +303,30 @@ private TestResult hasNamedGroupIntolerance() {
293
303
}
294
304
295
305
private TestResult hasOnlySecondCipherSuiteByteEvaluatedBug () {
296
- Config config = configSelector .getBaseConfig ();
297
- ClientHelloMessage message = new ClientHelloMessage (config );
298
- ByteArrayOutputStream stream = new ByteArrayOutputStream ();
299
- for (CipherSuite suite : CipherSuite .values ()) {
300
- if (suite .getByteValue ()[0 ] == 0x00 ) {
301
- try {
302
- stream .write (new byte [] { (byte ) 0xDF , suite .getByteValue ()[1 ] });
303
- } catch (IOException ex ) {
304
- LOGGER .debug (ex );
306
+ if (configSelector .foundWorkingConfig ()) {
307
+ Config config = configSelector .getBaseConfig ();
308
+ ClientHelloMessage message = new ClientHelloMessage (config );
309
+ ByteArrayOutputStream stream = new ByteArrayOutputStream ();
310
+ for (CipherSuite suite : CipherSuite .values ()) {
311
+ if (suite .getByteValue ()[0 ] == 0x00 ) {
312
+ try {
313
+ stream .write (new byte [] { (byte ) 0xDF , suite .getByteValue ()[1 ] });
314
+ } catch (IOException ex ) {
315
+ LOGGER .debug (ex );
316
+ }
305
317
}
306
318
}
319
+ message .setCipherSuites (Modifiable .explicit (stream .toByteArray ()));
320
+ WorkflowTrace trace = getWorkflowTrace (config , message );
321
+ return getResult (config , trace , true );
322
+ } else {
323
+ // not applicable to TLS 1.3-only servers due to 0x13XX structure
324
+ return TestResults .FALSE ;
307
325
}
308
- message .setCipherSuites (Modifiable .explicit (stream .toByteArray ()));
309
- WorkflowTrace trace = getWorkflowTrace (config , message );
310
- return getResult (config , trace , true );
311
326
}
312
327
313
328
private TestResult hasEmptyLastExtensionIntolerance () {
314
- Config config = configSelector .getBaseConfig ();
329
+ Config config = configSelector .getAnyWorkingBaseConfig ();
315
330
ClientHelloMessage message = new ClientHelloMessage (config );
316
331
ExtendedMasterSecretExtensionMessage extension = new ExtendedMasterSecretExtensionMessage ();
317
332
message .getExtensions ().add (extension );
@@ -320,44 +335,52 @@ private TestResult hasEmptyLastExtensionIntolerance() {
320
335
}
321
336
322
337
private TestResult hasVersionIntolerance () {
323
- Config config = configSelector .getBaseConfig ();
338
+ Config config = configSelector .getAnyWorkingBaseConfig ();
324
339
ClientHelloMessage message = new ClientHelloMessage (config );
325
340
message .setProtocolVersion (Modifiable .explicit (new byte [] { 0x03 , 0x05 }));
326
341
WorkflowTrace trace = getWorkflowTrace (config , message );
327
342
return getResult (config , trace , false );
328
343
}
329
344
330
345
private TestResult hasCompressionIntolerance () {
331
- Config config = configSelector .getBaseConfig ();
332
- ClientHelloMessage message = new ClientHelloMessage (config );
333
- message .setCompressions (new byte [] { (byte ) 0xFF , (byte ) 0x00 });
334
- WorkflowTrace trace = getWorkflowTrace (config , message );
335
- return getResult (config , trace , false );
346
+ if (configSelector .foundWorkingConfig ()) {
347
+ Config config = configSelector .getBaseConfig ();
348
+ ClientHelloMessage message = new ClientHelloMessage (config );
349
+ message .setCompressions (new byte [] { (byte ) 0xFF , (byte ) 0x00 });
350
+ WorkflowTrace trace = getWorkflowTrace (config , message );
351
+ return getResult (config , trace , false );
352
+ } else {
353
+ // At this point, we must have only found a working TLS 1.3 config
354
+ // and RFC 8446 states:
355
+ // If a TLS 1.3 ClientHello is received with any other value in this
356
+ // field, the server MUST abort the handshake with an
357
+ // "illegal_parameter" alert.
358
+ return TestResults .FALSE ;
359
+ }
336
360
}
337
361
338
362
private TestResult hasCipherSuiteLengthIntolerance512 () {
339
- Config config = configSelector .getBaseConfig ();
363
+ Config config = configSelector .getAnyWorkingBaseConfig ();
340
364
List <CipherSuite > toTestList = new LinkedList <>();
341
365
toTestList .addAll (Arrays .asList (CipherSuite .values ()));
342
366
toTestList .remove (CipherSuite .TLS_FALLBACK_SCSV );
343
367
toTestList .remove (CipherSuite .TLS_EMPTY_RENEGOTIATION_INFO_SCSV );
344
368
config .setDefaultClientSupportedCipherSuites (toTestList );
345
- configSelector .repairConfig (config );
346
369
ClientHelloMessage message = new ClientHelloMessage (config );
347
370
WorkflowTrace trace = getWorkflowTrace (config , message );
348
371
return getResult (config , trace , false );
349
372
}
350
373
351
374
private TestResult hasCipherSuiteIntolerance () {
352
- Config config = configSelector .getBaseConfig ();
375
+ Config config = configSelector .getAnyWorkingBaseConfig ();
353
376
ClientHelloMessage message = new ClientHelloMessage (config );
354
377
message .setCipherSuites (Modifiable .insert (new byte [] { (byte ) 0xCF , (byte ) 0xAA }, 1 ));
355
378
WorkflowTrace trace = getWorkflowTrace (config , message );
356
379
return getResult (config , trace , false );
357
380
}
358
381
359
382
private TestResult hasAlpnIntolerance () {
360
- Config config = configSelector .getBaseConfig ();
383
+ Config config = configSelector .getAnyWorkingBaseConfig ();
361
384
config .setAddAlpnExtension (true );
362
385
List <String > alpnProtocols = new LinkedList <>();
363
386
for (AlpnProtocol protocol : AlpnProtocol .values ()) {
@@ -371,7 +394,7 @@ private TestResult hasAlpnIntolerance() {
371
394
}
372
395
373
396
private TestResult hasClientHelloLengthIntolerance () {
374
- Config config = configSelector .getBaseConfig ();
397
+ Config config = configSelector .getAnyWorkingBaseConfig ();
375
398
config .setAddPaddingExtension (true );
376
399
ClientHelloMessage message = new ClientHelloMessage (config );
377
400
int newLength = 512 - 4 - getClientHelloLength (message , config );
@@ -385,7 +408,7 @@ private TestResult hasClientHelloLengthIntolerance() {
385
408
}
386
409
387
410
private TestResult hasGreaseCipherSuiteIntolerance () {
388
- Config config = configSelector .getBaseConfig ();
411
+ Config config = configSelector .getAnyWorkingBaseConfig ();
389
412
Arrays .asList (CipherSuite .values ()).stream ().filter (cipherSuite -> cipherSuite .isGrease ())
390
413
.forEach (greaseCipher -> config .getDefaultClientSupportedCipherSuites ().add (greaseCipher ));
391
414
ClientHelloMessage message = new ClientHelloMessage (config );
@@ -394,7 +417,7 @@ private TestResult hasGreaseCipherSuiteIntolerance() {
394
417
}
395
418
396
419
private TestResult hasGreaseNamedGroupIntolerance () {
397
- Config config = configSelector .getBaseConfig ();
420
+ Config config = configSelector .getAnyWorkingBaseConfig ();
398
421
Arrays .asList (NamedGroup .values ()).stream ().filter (group -> group .isGrease ())
399
422
.forEach (greaseGroup -> config .getDefaultClientNamedGroups ().add (greaseGroup ));
400
423
ClientHelloMessage message = new ClientHelloMessage (config );
@@ -403,7 +426,7 @@ private TestResult hasGreaseNamedGroupIntolerance() {
403
426
}
404
427
405
428
private TestResult hasGreaseSignatureAndHashAlgorithmIntolerance () {
406
- Config config = configSelector .getBaseConfig ();
429
+ Config config = configSelector .getAnyWorkingBaseConfig ();
407
430
Arrays .asList (SignatureAndHashAlgorithm .values ()).stream ().filter (algorithm -> algorithm .isGrease ()).forEach (
408
431
greaseAlgorithm -> config .getDefaultClientSupportedSignatureAndHashAlgorithms ().add (greaseAlgorithm ));
409
432
ClientHelloMessage message = new ClientHelloMessage (config );
0 commit comments