[java-identity-provider] branch main updated: JJETTY-6 Do not use IPv6 when generating certificate

Rod Widdowson rdw at steadingsoftware.com
Sat Nov 2 16:51:37 UTC 2024


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=23e6ae9bfa822d91962f9d70a380a8036b712a47

The following commit(s) were added to refs/heads/main by this push:
     new 23e6ae9bf JJETTY-6 Do not use IPv6 when generating certificate
23e6ae9bf is described below

commit 23e6ae9bfa822d91962f9d70a380a8036b712a47
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Nov 2 16:50:37 2024 +0000

    JJETTY-6 Do not use IPv6 when generating certificate
    
    https://shibboleth.atlassian.net/browse/JJETTY-6
    
    Move "walk the interface" code back to an impl class and deprecate it
---
 .../shibboleth/idp/installer/InstallerSupport.java | 69 --------------------
 .../installer/impl/InstallerPropertiesImpl.java    | 76 +++++++++++++++++++++-
 2 files changed, 75 insertions(+), 70 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index be068d794..62ab09ffb 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -460,75 +460,6 @@ public final class InstallerSupport {
         pathsCopied.addAll(visitor.getCopiedList());
     }
 
-    /**
-     * Is this address named?
-     *
-     * <p>Helper method for {@link #getBestHostName()}.</p>
-     *
-     * @param addr what to look at
-     * @return true unless the name is the canonical name
-     */
-    private static boolean hasHostName(final InetAddress addr) {
-        return !addr.getHostAddress().equals(addr.getCanonicalHostName());
-    }
-
-
-    /**
-     * Find the most apposite network connector, taken from Ant.
-     *
-     * @return the best name we can work out
-     */
-    // CheckStyle: CyclomaticComplexity OFF
-    @Nonnull public static String getBestHostName() {
-        InetAddress bestSoFar = null;
-        try {
-            for (final NetworkInterface netInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
-                for (final InetAddress address : Collections.list(netInterface.getInetAddresses())) {
-                    if (bestSoFar == null) {
-                        // none selected so far, so this one is better.
-                        bestSoFar = address;
-                    } else if (address == null || address.isLoopbackAddress()) {
-                        // definitely not better than the previously selected address.
-                    } else if (address.isLinkLocalAddress()) {
-                        // link local considered better than loopback
-                        if (bestSoFar.isLoopbackAddress()) {
-                            bestSoFar = address;
-                        }
-                    } else if (address.isSiteLocalAddress()) {
-                        // site local considered better than link local (and loopback)
-                        // address with hostname resolved considered better than
-                        // address without hostname
-                        if (bestSoFar.isLoopbackAddress()
-                                || bestSoFar.isLinkLocalAddress()
-                                || (bestSoFar.isSiteLocalAddress() && !hasHostName(bestSoFar))) {
-                            bestSoFar = address;
-                        }
-                    } else {
-                        // current is a "Global address", considered better than
-                        // site local (and better than link local, loopback)
-                        // address with hostname resolved considered better than
-                        // address without hostname
-                        if (bestSoFar.isLoopbackAddress()
-                                || bestSoFar.isLinkLocalAddress()
-                                || bestSoFar.isSiteLocalAddress()
-                                || !hasHostName(bestSoFar)) {
-                            bestSoFar = address;
-                        }
-                    }
-                }
-            }
-        } catch (final SocketException e) {
-            LoggerFactory.getLogger(InstallerSupport.class).error("Could not get host information", e);
-        }
-        if (bestSoFar == null) {
-            return "localhost.localdomain";
-        }
-        final String result = bestSoFar.getCanonicalHostName();
-        assert result!=null;
-        return result;
-    }
-    // CheckStyle: CyclomaticComplexity ON
-
     /** A version of {@link Path#of(String, String...)} that throw a catchable exception.
      * @param pathString the path as a string
      * @return the Path
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
index 631df5ca2..47fd7540c 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
@@ -17,11 +17,15 @@ package net.shibboleth.idp.installer.impl;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -189,6 +193,76 @@ public class InstallerPropertiesImpl  {
     }
 // CheckStyle: CyclomaticComplexity ON
 
+
+    /**
+     * Is this address named?
+     *
+     * <p>Helper method for {@link #getBestHostName()}.</p>
+     * @deprecated to be removed in V6
+     * @param addr what to look at
+     * @return true unless the name is the canonical name
+     */
+    private static boolean hasHostName(final InetAddress addr) {
+        return !addr.getHostAddress().equals(addr.getCanonicalHostName());
+    }
+
+
+    /**
+     * Find the most apposite network connector, taken from Ant.
+     * @deprecated To be removed in V6
+     * @return the best name we can work out
+     */
+    // CheckStyle: CyclomaticComplexity OFF
+    @Nonnull private static String getBestHostName() {
+        InetAddress bestSoFar = null;
+        try {
+            for (final NetworkInterface netInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
+                for (final InetAddress address : Collections.list(netInterface.getInetAddresses())) {
+                    if (bestSoFar == null) {
+                        // none selected so far, so this one is better.
+                        bestSoFar = address;
+                    } else if (address == null || address.isLoopbackAddress()) {
+                        // definitely not better than the previously selected address.
+                    } else if (address.isLinkLocalAddress()) {
+                        // link local considered better than loopback
+                        if (bestSoFar.isLoopbackAddress()) {
+                            bestSoFar = address;
+                        }
+                    } else if (address.isSiteLocalAddress()) {
+                        // site local considered better than link local (and loopback)
+                        // address with hostname resolved considered better than
+                        // address without hostname
+                        if (bestSoFar.isLoopbackAddress()
+                                || bestSoFar.isLinkLocalAddress()
+                                || (bestSoFar.isSiteLocalAddress() && !hasHostName(bestSoFar))) {
+                            bestSoFar = address;
+                        }
+                    } else {
+                        // current is a "Global address", considered better than
+                        // site local (and better than link local, loopback)
+                        // address with hostname resolved considered better than
+                        // address without hostname
+                        if (bestSoFar.isLoopbackAddress()
+                                || bestSoFar.isLinkLocalAddress()
+                                || bestSoFar.isSiteLocalAddress()
+                                || !hasHostName(bestSoFar)) {
+                            bestSoFar = address;
+                        }
+                    }
+                }
+            }
+        } catch (final SocketException e) {
+            LoggerFactory.getLogger(InstallerSupport.class).error("Could not get host information", e);
+        }
+        if (bestSoFar == null) {
+            return "localhost.localdomain";
+        }
+        final String result = bestSoFar.getCanonicalHostName();
+        assert result!=null;
+        return result;
+    }
+    // CheckStyle: CyclomaticComplexity ON
+
     /**
      * Lookup a property; if it isn't defined then ask the user (if we are allowed).
      * 
@@ -316,7 +390,7 @@ public class InstallerPropertiesImpl  {
     @Nonnull public String getHostName() {
         String result = hostname;
         if (result == null) {
-            result = hostname = getValue(InstallerProperties.HOST_NAME, "Host Name:", () -> InstallerSupport.getBestHostName());
+            result = hostname = getValue(InstallerProperties.HOST_NAME, "Host Name:", () -> getBestHostName());
         }
         return result;
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list