|
20 | 20 | import java.rmi.registry.LocateRegistry; |
21 | 21 | import java.rmi.registry.Registry; |
22 | 22 | import java.security.KeyStore.PrivateKeyEntry; |
23 | | -import java.util.ArrayList; |
| 23 | +import java.util.*; |
24 | 24 | import java.util.function.Consumer; |
25 | 25 | import java.util.zip.ZipEntry; |
26 | 26 | import java.util.zip.ZipInputStream; |
@@ -955,7 +955,25 @@ private static void generatePkiCerts() throws Exception { |
955 | 955 | TEST_PKI_SERVER_PASSPHRASE + "): " + serverKeystorePath); |
956 | 956 |
|
957 | 957 | PKIUtils.createKeyEntry("test-sig", TEST_PKI_SERVER_DN, 2, caEntry, serverKeystoreFile, |
958 | | - "PKCS12", null, TEST_PKI_SERVER_PASSPHRASE.toCharArray()); |
| 958 | + "PKCS12", getLocalHostnames(), TEST_PKI_SERVER_PASSPHRASE.toCharArray()); |
| 959 | + } |
| 960 | + |
| 961 | + private static Collection<String> getLocalHostnames() throws SocketException { |
| 962 | + |
| 963 | + // Collect alternate hostnames for inclusion in certificate |
| 964 | + Set<String> altNames = new TreeSet<>(); |
| 965 | + Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); |
| 966 | + while (nets.hasMoreElements()) { |
| 967 | + NetworkInterface netint = nets.nextElement(); |
| 968 | + Enumeration<InetAddress> addrs = netint.getInetAddresses(); |
| 969 | + while (addrs.hasMoreElements()) { |
| 970 | + InetAddress addr = addrs.nextElement(); |
| 971 | + altNames.add(addr.getHostAddress()); |
| 972 | + altNames.add(addr.getHostName()); |
| 973 | + altNames.add(addr.getCanonicalHostName()); |
| 974 | + } |
| 975 | + } |
| 976 | + return altNames; |
959 | 977 | } |
960 | 978 |
|
961 | 979 | /** |
|
0 commit comments