2323import java .io .OutputStreamWriter ;
2424import java .net .*;
2525import java .security .cert .X509Certificate ;
26- import java .util .HashMap ;
27- import java .util .List ;
28- import java .util .Map ;
26+ import java .util .*;
2927import java .util .Map .Entry ;
30- import java .util .Objects ;
3128
3229/**
3330 * The {@code HttpService} class represents a generic HTTP service at a given
@@ -50,13 +47,11 @@ public class HttpService {
5047 private static SSLSocketFactory sslSocketFactory = createSSLFactory ();
5148 private static String HTTPS_SCHEME = "https" ;
5249 private static String HTTP_SCHEME = "http" ;
53- private static String HOSTNAME = "localhost" ;
54- private static String HOSTIP = "127.0.0.1" ;
55- private static String HOSTIPv6 = "::1" ;
50+ private static List <String > VALID_HOSTS = new ArrayList <String >(Arrays .asList ("localhost" , "127.0.0.1" , "::1" ));
5651
5752 private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier () {
5853 public boolean verify (String s , SSLSession sslSession ) {
59- if ( s . equals ( HOSTNAME ) || s . equals ( HOSTIP ) || s . equals ( HOSTIPv6 )) {
54+ if ( VALID_HOSTS . contains ( s )) {
6055 return true ;
6156 } else {
6257 HostnameVerifier hv = HttpsURLConnection .getDefaultHostnameVerifier ();
@@ -239,6 +234,14 @@ public static void setSslSecurityProtocol(SSLSecurityProtocol securityProtocol)
239234 }
240235 }
241236
237+ /**
238+ * Adds list of Cluster Master Hosts to the list of Valid Hosts for Hostname verification.
239+ * @param searchHeadService Splunk SearchHead Service instance
240+ */
241+ public static void addClusterMasterURIsToHosts (Service searchHeadService ){
242+ VALID_HOSTS .addAll (searchHeadService .getClusterMasters ());
243+ }
244+
242245 /**
243246 * Returns the URL prefix of this service, consisting of
244247 * {@code scheme://host[:port]}.
0 commit comments