@@ -125,37 +125,64 @@ protected static String[] sanitizeProtocols(String[] protocols,
125125 * Sanitize or filter SSL/TLS cipher suite list based on custom wolfJSSE
126126 * system property limitations.
127127 *
128- * Supported system Security properties which limit cipher suite list are:
129- * - wolfjsse.enabledCipherSuites
128+ * When filterAnon is true, this method filters the default enabled cipher
129+ * suite list, removing anonymous cipher suites to match SunJSSE behavior.
130+ * When filterAnon is false, anonymous cipher suites are preserved, allowing
131+ * applications to explicitly enable them via
132+ * SSLEngine.setEnabledCipherSuites() or SSLSocket.setEnabledCipherSuites().
130133 *
131- * This security property should contain a comma-separated list of
132- * values, for example:
134+ * Filtering applied:
135+ *
136+ * 1. If filterAnon is true, anonymous cipher suites (containing
137+ * "_anon_" in IANA name) are removed, matching SunJSSE behavior.
138+ *
139+ * 2. If the wolfjsse.enabledCipherSuites security property is set,
140+ * the list is further filtered to only include suites in that
141+ * property. This should contain a comma-separated list of values,
142+ * for example:
133143 *
134144 * wolfjsse.enabledCipherSuites=
135145 * "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, \
136146 * TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
137147 *
138- * Only the cipher suites included in this list will be allowed to be used
139- * in JSSE TLS connections. Applications can still set cipher suites,
140- * using for example SSLParameters, but the set cipher suite list will be
141- * filtered by this function to remove any suites not included in the
142- * system property mentioned here if it has been set.
143- *
144148 * @param suites Full list of TLS cipher suites to sanitize/filter,
145- * should be in format similar to: "SUITE1", "SUITE2", etc.
146- *
147- * @return New filtered String array of cipher suites.
149+ * should be in format similar to: "SUITE1", "SUITE2",
150+ * etc.
151+ * @param filterAnon If true, anonymous cipher suites (containing "_anon_"
152+ * in IANA name) will be filtered out. If false, anonymous
153+ * suites are preserved.
154+ *
155+ * @return New filtered String array of cipher suites, or null if input
156+ * is null.
148157 */
149- protected static String [] sanitizeSuites (String [] suites ) {
158+ protected static String [] sanitizeSuites (String [] suites ,
159+ boolean filterAnon ) {
160+
150161 ArrayList <String > filtered = new ArrayList <String >();
151162
163+ if (suites == null ) {
164+ return null ;
165+ }
166+
167+ /* Filter out anonymous cipher suites if requested. SunJSSE also
168+ * excludes them from the default enabled list. Anonymous suites
169+ * contain "_anon_" in IANA format. When filterAnon is false, all
170+ * non-null suites pass through. */
171+ for (int i = 0 ; i < suites .length ; i ++) {
172+ if (suites [i ] != null ) {
173+ if (!filterAnon || !suites [i ].contains ("_anon_" )) {
174+ filtered .add (suites [i ]);
175+ }
176+ }
177+ }
178+
152179 String enabledSuites =
153180 Security .getProperty ("wolfjsse.enabledCipherSuites" );
154181 List <?> enabledList = null ;
155182
156- /* If system property not set, no filtering needed */
183+ /* If system property not set, return filtered list */
157184 if (enabledSuites == null || enabledSuites .isEmpty ()) {
158- return suites ;
185+ return filtered . toArray ( new String [ filtered . size ()]) ;
159186 }
160187
161188 final String tmpSuites = enabledSuites ;
@@ -168,13 +195,15 @@ protected static String[] sanitizeSuites(String[] suites) {
168195 enabledSuites = enabledSuites .replaceAll (", " ,"," );
169196 enabledList = Arrays .asList (enabledSuites .split ("," ));
170197
171- for (int i = 0 ; i < suites .length ; i ++) {
172- if (enabledList .contains (suites [i ])) {
173- filtered .add (suites [i ]);
198+ /* Further filter by wolfjsse.enabledCipherSuites property */
199+ ArrayList <String > propFiltered = new ArrayList <String >();
200+ for (int i = 0 ; i < filtered .size (); i ++) {
201+ if (enabledList .contains (filtered .get (i ))) {
202+ propFiltered .add (filtered .get (i ));
174203 }
175204 }
176205
177- return filtered .toArray (new String [filtered .size ()]);
206+ return propFiltered .toArray (new String [propFiltered .size ()]);
178207 }
179208
180209 /**
0 commit comments