exceptionfactory commented on a change in pull request #4673:
URL: https://github.com/apache/nifi/pull/4673#discussion_r541336803



##########
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:
       This is somewhat complicated since the Java runtime behavior is can be 
controlled using the `jdk.tls.disabledAlgorithms` property in the 
`java.security` configuration.  It is theoretically possible to disable modern 
protocols such as TLSv1.2 and TLSv1.3 using that configuration property, which 
would influence that this method returns.  The primary purpose of this class is 
to provide a _descriptive_ approach to what is running.  The response of this 
method could in fact return TLSv1 or TLSv1.1, but it seems like it should be 
the responsibility of another NiFi class to determine whether to flag that as 
problem.
   
   For that reason, it is theoretically possible for PREFERRED_PROTOCOLS to be 
empty, should TLSv1.2 and TLSv1.3 be disabled.  As a class that should reflect 
how the JVM is currently running, it seems better to maintain this behavior and 
consider other approaches if it is necessary for NiFi to require TLSv1.2 or 
greater for acceptable operation.




----------------------------------------------------------------
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]


Reply via email to