26
26
import de .rub .nds .tlsscanner .serverscanner .probe .result .CipherSuiteResult ;
27
27
import de .rub .nds .tlsscanner .serverscanner .report .ServerReport ;
28
28
import de .rub .nds .tlsscanner .serverscanner .selector .ConfigSelector ;
29
- import java .util .ArrayList ;
30
29
import java .util .Arrays ;
31
30
import java .util .LinkedList ;
32
31
import java .util .List ;
32
+ import java .util .stream .Collectors ;
33
33
34
34
public class CipherSuiteProbe extends TlsServerProbe <ConfigSelector , ServerReport , CipherSuiteResult > {
35
35
@@ -46,21 +46,12 @@ public CipherSuiteResult executeTest() {
46
46
for (ProtocolVersion version : protocolVersions ) {
47
47
LOGGER .debug ("Testing:" + version .name ());
48
48
if (version .isTLS13 ()) {
49
- pairLists .add (new VersionSuiteListPair (version , getSupportedCipherSuites ()));
49
+ pairLists .add (new VersionSuiteListPair (version , getSupportedTls13CipherSuites ()));
50
50
} else {
51
- List <CipherSuite > toTestList = new LinkedList <>();
52
- List <CipherSuite > versionSupportedSuites = new LinkedList <>();
53
- if (version == ProtocolVersion .SSL3 ) {
54
- toTestList .addAll (CipherSuite .SSL3_SUPPORTED_CIPHERSUITES );
55
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
56
- } else {
57
- toTestList .addAll (Arrays .asList (CipherSuite .values ()));
58
- toTestList .remove (CipherSuite .TLS_FALLBACK_SCSV );
59
- toTestList .remove (CipherSuite .TLS_EMPTY_RENEGOTIATION_INFO_SCSV );
60
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (toTestList , version );
61
- if (versionSupportedSuites .isEmpty ()) {
62
- versionSupportedSuites = getSupportedCipherSuitesWithIntolerance (version );
63
- }
51
+ List <CipherSuite > toTestList = new LinkedList <>(Arrays .asList (CipherSuite .values ()));
52
+ List <CipherSuite > versionSupportedSuites = getSupportedCipherSuites (toTestList , version );
53
+ if (versionSupportedSuites .isEmpty ()) {
54
+ versionSupportedSuites = getSupportedCipherSuites (CipherSuite .getImplemented (), version );
64
55
}
65
56
if (versionSupportedSuites .size () > 0 ) {
66
57
pairLists .add (new VersionSuiteListPair (version , versionSupportedSuites ));
@@ -70,18 +61,20 @@ public CipherSuiteResult executeTest() {
70
61
return new CipherSuiteResult (pairLists );
71
62
}
72
63
73
- private List <CipherSuite > getSupportedCipherSuites () {
64
+ private List <CipherSuite > getCipherSuitesForVersion (List <CipherSuite > baseList , ProtocolVersion version ) {
65
+ List <CipherSuite > applicableCipherSuites = baseList .stream ()
66
+ .filter (cipherSuite -> cipherSuite .isSupportedInProtocol (version )).collect (Collectors .toList ());
67
+ applicableCipherSuites .remove (CipherSuite .TLS_FALLBACK_SCSV );
68
+ applicableCipherSuites .remove (CipherSuite .TLS_EMPTY_RENEGOTIATION_INFO_SCSV );
69
+ return applicableCipherSuites ;
70
+ }
71
+
72
+ private List <CipherSuite > getSupportedTls13CipherSuites () {
74
73
CipherSuite selectedSuite = null ;
75
- List <CipherSuite > toTestList = new LinkedList <> ();
74
+ List <CipherSuite > toTestList = CipherSuite . getTls13CipherSuites ();
76
75
List <CipherSuite > supportedSuits = new LinkedList <>();
77
- for (CipherSuite suite : CipherSuite .values ()) {
78
- if (suite .isTLS13 ()) {
79
- toTestList .add (suite );
80
- }
81
- }
82
76
do {
83
- selectedSuite = getSelectedCipherSuite (toTestList );
84
-
77
+ selectedSuite = getSelectedTls13CipherSuite (toTestList );
85
78
if (selectedSuite != null ) {
86
79
if (!toTestList .contains (selectedSuite )) {
87
80
LOGGER .warn ("Server chose a CipherSuite we did not propose!" );
@@ -95,7 +88,7 @@ private List<CipherSuite> getSupportedCipherSuites() {
95
88
return supportedSuits ;
96
89
}
97
90
98
- private CipherSuite getSelectedCipherSuite (List <CipherSuite > toTestList ) {
91
+ private CipherSuite getSelectedTls13CipherSuite (List <CipherSuite > toTestList ) {
99
92
Config tlsConfig = configSelector .getTls13BaseConfig ();
100
93
tlsConfig .setWorkflowTraceType (WorkflowTraceType .DYNAMIC_HELLO );
101
94
tlsConfig .setDefaultClientSupportedCipherSuites (toTestList );
@@ -114,13 +107,8 @@ private CipherSuite getSelectedCipherSuite(List<CipherSuite> toTestList) {
114
107
}
115
108
}
116
109
117
- public List <CipherSuite > getSupportedCipherSuitesWithIntolerance (ProtocolVersion version ) {
118
- return getSupportedCipherSuitesWithIntolerance (new ArrayList <>(CipherSuite .getImplemented ()), version );
119
- }
120
-
121
- public List <CipherSuite > getSupportedCipherSuitesWithIntolerance (List <CipherSuite > toTestList ,
122
- ProtocolVersion version ) {
123
- List <CipherSuite > listWeSupport = new LinkedList <>(toTestList );
110
+ public List <CipherSuite > getSupportedCipherSuites (List <CipherSuite > baseList , ProtocolVersion version ) {
111
+ List <CipherSuite > listWeSupport = getCipherSuitesForVersion (baseList , version );
124
112
List <CipherSuite > supported = new LinkedList <>();
125
113
126
114
boolean supportsMore = false ;
0 commit comments