thenatog commented on a change in pull request #4673: URL: https://github.com/apache/nifi/pull/4673#discussion_r541302184
########## File path: nifi-commons/nifi-security-utils-api/src/main/java/org/apache/nifi/security/util/TlsPlatform.java ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.security.util; + +import static java.util.Collections.unmodifiableSet; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLParameters; +import java.security.NoSuchAlgorithmException; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * Transport Layer Security Platform provides runtime protocol configuration information + */ +public class TlsPlatform { + private static final Pattern PROTOCOL_VERSION = Pattern.compile("TLSv(\\d+\\.?\\d*)"); + + private static final int FIRST_GROUP = 1; + + private static final List<String> LEGACY_PROTOCOLS = Arrays.asList("TLSv1", "TLSv1.1"); + + private static final SortedMap<Float, String> SORTED_PROTOCOLS = getDefaultSslContextProtocols(); + + private static final Set<String> DEFAULT_PROTOCOLS = unmodifiableSet(new TreeSet<>(SORTED_PROTOCOLS.values()).descendingSet()); + + private static final Set<String> PREFERRED_PROTOCOLS = unmodifiableSet( + DEFAULT_PROTOCOLS.stream() + .filter(protocol -> !LEGACY_PROTOCOLS.contains(protocol)) + .collect(Collectors.toSet()) + ); + + /** + * Get Default Protocols based on Java Security configuration + * + * @return Set of Transport Layer Security Protocol names + */ + public static Set<String> getDefaultProtocols() { + return DEFAULT_PROTOCOLS; + } + + /** + * Get Preferred Protocols based on default protocols with legacy protocols removed + * + * @return Set of Preferred Transport Layer Security Protocol names + */ + public static Set<String> getPreferredProtocols() { + return PREFERRED_PROTOCOLS; + } + + /** + * Get Latest Protocol based on high version number from default protocols in Java Security configuration + * + * @return Latest Transport Layer Security Protocol + */ + public static String getLatestProtocol() { + return SORTED_PROTOCOLS.get(SORTED_PROTOCOLS.lastKey()); Review comment: Because this uses SORTED_PROTOCOLS which is a sorted set of all available protocols, this can allow use of protocols less than TLSv1.2 if TLSv1.2+ are not found to be available at the JVM level. In other words, there is no explicit control of protocol versions from NiFi code. Is it reasonable to allow NiFi to operate for example on TLSv1.0/TLSv1.1 because it's the 'latest' available protocol attained, or should we explicitly deny this situation? Is it possible code could modify the available protocols at the JVM level to create a TLS downgrade attack? Should getLatestProtocol() only use PREFERRED_PROTOCOLS? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
