16
16
import de .rub .nds .tlsattacker .core .constants .NamedGroup ;
17
17
import de .rub .nds .tlsattacker .core .constants .ProtocolMessageType ;
18
18
import de .rub .nds .tlsattacker .core .constants .ProtocolVersion ;
19
+ import de .rub .nds .tlsattacker .core .constants .SignatureAndHashAlgorithm ;
19
20
import de .rub .nds .tlsattacker .core .protocol .message .AlertMessage ;
20
21
import de .rub .nds .tlsattacker .core .state .State ;
21
22
import de .rub .nds .tlsattacker .core .workflow .ParallelExecutor ;
22
23
import de .rub .nds .tlsattacker .core .workflow .WorkflowTraceUtil ;
23
24
import de .rub .nds .tlsattacker .core .workflow .factory .WorkflowTraceType ;
24
25
import de .rub .nds .tlsscanner .serverscanner .config .ScannerConfig ;
25
26
import de .rub .nds .tlsscanner .serverscanner .constants .ProbeType ;
27
+ import de .rub .nds .tlsscanner .serverscanner .rating .TestResult ;
28
+ import de .rub .nds .tlsscanner .serverscanner .report .AnalyzedProperty ;
26
29
import de .rub .nds .tlsscanner .serverscanner .report .SiteReport ;
27
30
import de .rub .nds .tlsscanner .serverscanner .report .result .CiphersuiteProbeResult ;
28
31
import de .rub .nds .tlsscanner .serverscanner .report .result .ProbeResult ;
@@ -39,10 +42,6 @@ public class CiphersuiteProbe extends TlsProbe {
39
42
public CiphersuiteProbe (ScannerConfig config , ParallelExecutor parallelExecutor ) {
40
43
super (parallelExecutor , ProbeType .CIPHERSUITE , config );
41
44
protocolVersions = new LinkedList <>();
42
- protocolVersions .add (ProtocolVersion .SSL3 );
43
- protocolVersions .add (ProtocolVersion .TLS10 );
44
- protocolVersions .add (ProtocolVersion .TLS11 );
45
- protocolVersions .add (ProtocolVersion .TLS12 );
46
45
}
47
46
48
47
@ Override
@@ -51,33 +50,97 @@ public ProbeResult executeTest() {
51
50
List <VersionSuiteListPair > pairLists = new LinkedList <>();
52
51
for (ProtocolVersion version : protocolVersions ) {
53
52
LOGGER .debug ("Testing:" + version .name ());
54
- List <CipherSuite > toTestList = new LinkedList <>();
55
- List <CipherSuite > versionSupportedSuites = new LinkedList <>();
56
- if (version == ProtocolVersion .SSL3 ) {
57
- toTestList .addAll (CipherSuite .SSL3_SUPPORTED_CIPHERSUITES );
58
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
53
+ if (version .isTLS13 ()) {
54
+ pairLists .add (new VersionSuiteListPair (version , getSupportedCiphersuites ()));
59
55
} else {
60
- toTestList .addAll (Arrays .asList (CipherSuite .values ()));
61
- toTestList .remove (CipherSuite .TLS_FALLBACK_SCSV );
62
- toTestList .remove (CipherSuite .TLS_EMPTY_RENEGOTIATION_INFO_SCSV );
63
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
64
- if (versionSupportedSuites .isEmpty ()) {
65
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (version );
56
+ List <CipherSuite > toTestList = new LinkedList <>();
57
+ List <CipherSuite > versionSupportedSuites = new LinkedList <>();
58
+ if (version == ProtocolVersion .SSL3 ) {
59
+ toTestList .addAll (CipherSuite .SSL3_SUPPORTED_CIPHERSUITES );
60
+ versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
61
+ } else {
62
+ toTestList .addAll (Arrays .asList (CipherSuite .values ()));
63
+ toTestList .remove (CipherSuite .TLS_FALLBACK_SCSV );
64
+ toTestList .remove (CipherSuite .TLS_EMPTY_RENEGOTIATION_INFO_SCSV );
65
+ versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
66
+ if (versionSupportedSuites .isEmpty ()) {
67
+ versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (version );
68
+ }
69
+ }
70
+ if (versionSupportedSuites .size () > 0 ) {
71
+ pairLists .add (new VersionSuiteListPair (version , versionSupportedSuites ));
66
72
}
67
73
}
68
- if (versionSupportedSuites .size () > 0 ) {
69
- pairLists .add (new VersionSuiteListPair (version , versionSupportedSuites ));
70
- }
71
-
72
74
}
73
-
74
75
return new CiphersuiteProbeResult (pairLists );
75
76
} catch (Exception E ) {
76
77
LOGGER .error ("Could not scan for " + getProbeName (), E );
77
78
return new CiphersuiteProbeResult (null );
78
79
}
79
80
}
80
81
82
+ private List <CipherSuite > getSupportedCiphersuites () {
83
+ CipherSuite selectedSuite = null ;
84
+ List <CipherSuite > toTestList = new LinkedList <>();
85
+ List <CipherSuite > supportedSuits = new LinkedList <>();
86
+ for (CipherSuite suite : CipherSuite .values ()) {
87
+ if (suite .isTLS13 ()) {
88
+ toTestList .add (suite );
89
+ }
90
+ }
91
+ do {
92
+ selectedSuite = getSelectedCiphersuite (toTestList );
93
+
94
+ if (selectedSuite != null ) {
95
+ if (!toTestList .contains (selectedSuite )) {
96
+ LOGGER .warn ("Server chose a CipherSuite we did not propose!" );
97
+ // TODO write to sitereport
98
+ break ;
99
+ }
100
+ supportedSuits .add (selectedSuite );
101
+ toTestList .remove (selectedSuite );
102
+ }
103
+ } while (selectedSuite != null && !toTestList .isEmpty ());
104
+ return supportedSuits ;
105
+ }
106
+
107
+ private CipherSuite getSelectedCiphersuite (List <CipherSuite > toTestList ) {
108
+ Config tlsConfig = getScannerConfig ().createConfig ();
109
+ tlsConfig .setQuickReceive (true );
110
+ tlsConfig .setDefaultClientSupportedCiphersuites (toTestList );
111
+ tlsConfig .setHighestProtocolVersion (ProtocolVersion .TLS13 );
112
+ tlsConfig .setSupportedVersions (ProtocolVersion .TLS13 );
113
+ tlsConfig .setEnforceSettings (false );
114
+ tlsConfig .setEarlyStop (true );
115
+ tlsConfig .setStopReceivingAfterFatal (true );
116
+ tlsConfig .setStopActionsAfterFatal (true );
117
+ tlsConfig .setWorkflowTraceType (WorkflowTraceType .HELLO );
118
+ tlsConfig .setDefaultClientNamedGroups (NamedGroup .getImplemented ());
119
+ tlsConfig .setAddECPointFormatExtension (false );
120
+ tlsConfig .setAddEllipticCurveExtension (true );
121
+ tlsConfig .setAddSignatureAndHashAlgorithmsExtension (true );
122
+ tlsConfig .setAddSupportedVersionsExtension (true );
123
+ tlsConfig .setAddKeyShareExtension (true );
124
+ tlsConfig .setAddServerNameIndicationExtension (true );
125
+ tlsConfig .setAddCertificateStatusRequestExtension (true );
126
+ tlsConfig .setUseFreshRandom (true );
127
+ tlsConfig .setDefaultClientSupportedSignatureAndHashAlgorithms (SignatureAndHashAlgorithm
128
+ .getTls13SignatureAndHashAlgorithms ());
129
+
130
+ State state = new State (tlsConfig );
131
+ executeState (state );
132
+ if (WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .SERVER_HELLO , state .getWorkflowTrace ())) {
133
+ return state .getTlsContext ().getSelectedCipherSuite ();
134
+ } else if (WorkflowTraceUtil .didReceiveMessage (HandshakeMessageType .HELLO_RETRY_REQUEST ,
135
+ state .getWorkflowTrace ())) {
136
+ return state .getTlsContext ().getSelectedCipherSuite ();
137
+ } else {
138
+ LOGGER .debug ("Did not receive ServerHello Message" );
139
+ LOGGER .debug (state .getWorkflowTrace ().toString ());
140
+ return null ;
141
+ }
142
+ }
143
+
81
144
public List <CipherSuite > getSupportedCipherSuitesWithIntolerance (ProtocolVersion version ) {
82
145
return getSupportedCipherSuitesWithIntolerance (new ArrayList <>(CipherSuite .getImplemented ()), version );
83
146
}
@@ -149,11 +212,30 @@ public List<CipherSuite> getSupportedCipherSuitesWithIntolerance(List<CipherSuit
149
212
150
213
@ Override
151
214
public boolean canBeExecuted (SiteReport report ) {
152
- return true ;
215
+ if (report .isProbeAlreadyExecuted (ProbeType .PROTOCOL_VERSION )) {
216
+ return true ;
217
+ } else {
218
+ return false ;
219
+ }
153
220
}
154
221
155
222
@ Override
156
223
public void adjustConfig (SiteReport report ) {
224
+ if (report .getResult (AnalyzedProperty .SUPPORTS_SSL_3 ) == TestResult .TRUE ) {
225
+ protocolVersions .add (ProtocolVersion .SSL3 );
226
+ }
227
+ if (report .getResult (AnalyzedProperty .SUPPORTS_TLS_1_0 ) == TestResult .TRUE ) {
228
+ protocolVersions .add (ProtocolVersion .TLS10 );
229
+ }
230
+ if (report .getResult (AnalyzedProperty .SUPPORTS_TLS_1_1 ) == TestResult .TRUE ) {
231
+ protocolVersions .add (ProtocolVersion .TLS11 );
232
+ }
233
+ if (report .getResult (AnalyzedProperty .SUPPORTS_TLS_1_2 ) == TestResult .TRUE ) {
234
+ protocolVersions .add (ProtocolVersion .TLS12 );
235
+ }
236
+ if (report .getResult (AnalyzedProperty .SUPPORTS_TLS_1_3 ) == TestResult .TRUE ) {
237
+ protocolVersions .add (ProtocolVersion .TLS13 );
238
+ }
157
239
}
158
240
159
241
@ Override
0 commit comments