anmolnar commented on code in PR #8413:
URL: https://github.com/apache/hbase/pull/8413#discussion_r3475779698


##########
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java:
##########
@@ -88,6 +89,26 @@ public static String domainNamePointerToHostName(String 
dnPtr) {
     return dnPtr.endsWith(".") ? dnPtr.substring(0, dnPtr.length() - 1) : 
dnPtr;
   }
 
+  /**
+   * Compare two host identifiers for equality. DNS hostnames are compared 
case-insensitively because
+   * DNS labels are case-insensitive. IP address literals are compared exactly.
+   * @param left  first hostname or IP literal
+   * @param right second hostname or IP literal
+   * @return {@code true} if both refer to the same host identifier
+   */
+  public static boolean hostnamesEqual(String left, String right) {
+    if (left == right) {
+      return true;
+    }
+    if (left == null || right == null) {
+      return false;
+    }
+    if (InetAddresses.isInetAddress(left) || 
InetAddresses.isInetAddress(right)) {
+      return left.equals(right);
+    }
+    return left.equalsIgnoreCase(right);
+  }

Review Comment:
   I think this is a valid concern. Besides there's already a bunch of 
IP/hostname verifier tools in 
[HBaseHostnameVerifier](https://github.com/apache/hbase/blob/master/hbase-common/src/main/java/org/apache/hadoop/hbase/io/crypto/tls/HBaseHostnameVerifier.java#L134)
 which we could reuse.



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

Reply via email to