harmadasg commented on code in PR #22513:
URL: https://github.com/apache/kafka/pull/22513#discussion_r4738118870
##########
clients/src/main/java/org/apache/kafka/common/security/ssl/DefaultSslEngineFactory.java:
##########
@@ -212,6 +215,37 @@ private SSLEngine createSslEngine(ConnectionMode
connectionMode, String peerHost
}
return sslEngine;
}
+
+ // package access for testing
+ static String[] filterCipherSuites(List<String> configured, String[]
supported) {
+ // SSLParameters#getCipherSuites may return null. If the provider does
not report its supported
+ // cipher suites we cannot filter, so use the configured list
unchanged to fall back to the old behavior.
+ if (supported == null) {
+ log.warn("Skipping validation of configured cipher suites {}
because the JDK security provider does not report its supported cipher suites",
configured);
+ return configured.toArray(new String[0]);
+ }
+
+ Set<String> supportedCiphers = new HashSet<>(Arrays.asList(supported));
+ List<String> accepted = configured.stream()
+ .filter(supportedCiphers::contains)
+ .collect(Collectors.toList());
+
+ if (accepted.isEmpty()) {
+ throw new InvalidConfigurationException(
+ "None of the cipher suites in " + configured +
+ " are supported by the JDK security provider. " +
+ "Supported cipher suites are: " + supportedCiphers);
+ }
+
+ if (accepted.size() < configured.size()) {
+ List<String> differences = new ArrayList<>(configured);
+ differences.removeAll(accepted);
+ log.warn("Configured cipher suites filtered from {} to {} based on
JDK support. Unsupported cipher suites: {}. Effective cipher suites: {}",
Review Comment:
@chia7712 Thanks for the review! I agree with you, this can be a valid
concern. Actually solving it is a bit tricky as we need a new input on valid
cipher names. The currently installed security providers are no help here as we
can provide a valid cipher name which is implemented by a different, not
installed provider.
https://www.iana.org/assignments/tls-parameters#tls-parameters-4 contains
the authoritative list. I believe there are 3 routes we can take:
- Come up with a regex pattern. Does not really work well as there are 300+
ciphers with vastly different names. Hard to catch typical typos
`(..._GCM_SHA265 instead of ..._GCM_SHA256)`
- Iteration of previous idea but instead of a single regex pattern we can
come up with a grammar rule. In theory it can work but the implementation is
complex and we would still accept grammatically correct but not yet implemented
cipher names, e.g. `(TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA384)`
- Simply use the static IANA cipher list to compare against. This covers
everything but we have to include the list in Kafka which adds some maintenance
cost.
I chose to do the static list solution in the end. Based on my research the
list does not change that often, also new ciphers usually stay in an
experimental phase for a long time. Stale list is low risk, a missing name
that the provider supports is still accepted.
As per the updated config doc the new behavior is
`Configuration fails with an error if a configured name is neither supported
by the provider nor a valid IANA cipher suite name, or if none of the
configured cipher suites are supported.`
Please let me know what you think
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]